Subversion Repositories spacemission

Rev

Rev 63 | Rev 74 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. unit Global;
  2.  
  3. interface
  4.  
  5. const
  6.   ProgramVersion = '1.2';
  7.   RasterW = 48;
  8.   RasterH = 32;
  9.   MaxPossibleEnemyLives = 999;
  10.   MaxPossibleLevels = 999;
  11.   RegistrySettingsKey = 'SOFTWARE\ViaThinkSoft\SpaceMission\Settings';
  12.   DefaultLevelLength = 1200;
  13.   StartLives = 6;
  14.   conleicht =  650 div 60; // 10
  15.   conmittel = 1000 div 60; // 16
  16.   conschwer = 1350 div 60; // 22
  17.   conmaster = 2000 div 60; // 33
  18.   DEFAULT_ANIMSPEED = 15/1000;
  19.   ADDITIONAL_ENEMIES_PER_LEVEL = 75;
  20.  
  21. type
  22.   // DirectX\Music.dxm
  23.   TSpaceMissionMusicTrack = (
  24.     smmNone,
  25.     smmBoss,   // dxmusic.Midis[0]
  26.     smmGame,   // dxmusic.Midis[1]
  27.     smmScene,  // dxmusic.Midis[2]
  28.     smmTitle   // dxmusic.Midis[3]
  29.   );
  30.  
  31.   // DirectX\Graphics.dxg
  32.   TSpaceMissionGraphicSprite = (
  33.     smgNone,
  34.     smgEnemyDisk,         // ImageList.Items.Item[0]
  35.     smgEnemyAttacker,     // ImageList.Items.Item[1]
  36.     smgEnemyBoss,         // ImageList.Items.Item[2]
  37.     smgBounce,            // ImageList.Items.Item[3]
  38.     smgMachine,           // ImageList.Items.Item[4]
  39.     smgEnemyAttacker2,    // ImageList.Items.Item[5]
  40.     smgEnemyAttacker3,    // ImageList.Items.Item[6]
  41.     smgEnemyMeteor,       // ImageList.Items.Item[7]
  42.     smgBounce2,           // ImageList.Items.Item[8]
  43.     smgEnemyDisk2,        // ImageList.Items.Item[9]
  44.     smgLogo,              // ImageList.Items.Item[10]
  45.     smgExplosion,         // ImageList.Items.Item[11]
  46.     smgBackgroundPlanet1, // ImageList.Items.Item[12]
  47.     smgMatrix,            // ImageList.Items.Item[13]
  48.     smgStar1,             // ImageList.Items.Item[14]
  49.     smgStar2,             // ImageList.Items.Item[15]
  50.     smgStar3,             // ImageList.Items.Item[16]
  51.     smgBackgroundBlue,    // ImageList.Items.Item[17]
  52.     smgBackgroundRed,     // ImageList.Items.Item[18]
  53.     smgBackgroundYellow,  // ImageList.Items.Item[19]
  54.     smgHintergrundRot,    // ImageList.Items.Item[20]
  55.     smgItemMedikit        // ImageList.Items.Item[21]
  56.   );
  57.  
  58.   // DirectX\Sound.dxw
  59.   TSpaceMissionSound = (
  60.     smsNone,
  61.     smsSceneMov,      // WaveList.Items.Item[0]
  62.     smsExplosion,     // WaveList.Items.Item[1]
  63.     smsHit,           // WaveList.Items.Item[2]
  64.     smsShoot,         // WaveList.Items.Item[3]
  65.     smsItemCollected  // WaveList.Items.Item[4]
  66.   );
  67.  
  68. function OwnDirectory: string;
  69.  
  70. const
  71.   FOLDERID_SavedGames: TGuid = '{4C5C32FF-BB9D-43b0-B5B4-2D72E54EAAA4}';
  72.  
  73. // Useful functions
  74. function GetKnownFolderPath(const rfid: TGUID): string;
  75. function KillTask(ExeFileName: string): Integer;
  76. procedure CheckForUpdates(ViaThinkSoftProjectName: string);
  77.  
  78. implementation
  79.  
  80. uses
  81.   Windows, SysUtils, ActiveX, ShlObj, TlHelp32, wininet, Forms, ShellAPI;
  82.  
  83. function GetKnownFolderPath(const rfid: TGUID): string;
  84. var
  85.   OutPath: PWideChar;
  86. begin
  87.   // https://www.delphipraxis.net/135471-unit-zur-verwendung-von-shgetknownfolderpath.html
  88.   if ShGetKnownFolderPath(rfid, 0, 0, OutPath) {>= 0} = S_OK then
  89.   begin
  90.     Result := OutPath;
  91.     // From MSDN
  92.     // ppszPath [out]
  93.     // Type: PWSTR*
  94.     // When this method returns, contains the address of a pointer to a null-terminated Unicode string that specifies the path of the known folder
  95.     // The calling process is responsible for freeing this resource once it is no longer needed by calling CoTaskMemFree.
  96.     // The returned path does not include a trailing backslash. For example, "C:\Users" is returned rather than "C:\Users\".
  97.     CoTaskMemFree(OutPath);
  98.   end
  99.   else
  100.   begin
  101.     Result := '';
  102.   end;
  103. end;
  104.  
  105. // https://stackoverflow.com/questions/43774320/how-to-kill-a-process-by-name
  106. function KillTask(ExeFileName: string): Integer;
  107. const
  108.   PROCESS_TERMINATE = $0001;
  109. var
  110.   ContinueLoop: BOOL;
  111.   FSnapshotHandle: THandle;
  112.   FProcessEntry32: TProcessEntry32;
  113. begin
  114.   Result := 0;
  115.   FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  116.   FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
  117.   ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
  118.  
  119.   while Integer(ContinueLoop) <> 0 do
  120.   begin
  121.     if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
  122.       UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) =
  123.       UpperCase(ExeFileName))) then
  124.       Result := Integer(TerminateProcess(
  125.                         OpenProcess(PROCESS_TERMINATE,
  126.                                     BOOL(0),
  127.                                     FProcessEntry32.th32ProcessID),
  128.                                     0));
  129.      ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
  130.   end;
  131.   CloseHandle(FSnapshotHandle);
  132. end;
  133.  
  134. function OwnDirectory: string;
  135. begin
  136.   result := extractfilepath(paramstr(0));
  137. end;
  138.  
  139. // https://www.delphipraxis.net/post43515.html
  140. function GetHTML(AUrl: string): string;
  141. var
  142.   databuffer : array[0..4095] of char;
  143.   ResStr : string;
  144.   hSession, hfile: hInternet;
  145.   dwindex,dwcodelen,dwread,dwNumber: cardinal;
  146.   dwcode : array[1..20] of char;
  147.   res    : pchar;
  148.   Str    : pchar;
  149. begin
  150.   ResStr:='';
  151.   if (system.pos('http://',lowercase(AUrl))=0) and
  152.      (system.pos('https://',lowercase(AUrl))=0) then
  153.      AUrl:='http://'+AUrl;
  154.  
  155.   // Hinzugefügt
  156.   if Assigned(Application) then Application.ProcessMessages;
  157.  
  158.   hSession:=InternetOpen('InetURL:/1.0',
  159.                          INTERNET_OPEN_TYPE_PRECONFIG,
  160.                          nil,
  161.                          nil,
  162.                          0);
  163.   if assigned(hsession) then
  164.   begin
  165.     // Hinzugefügt
  166.     if Assigned(Application) then application.ProcessMessages;
  167.  
  168.     hfile:=InternetOpenUrl(
  169.            hsession,
  170.            pchar(AUrl),
  171.            nil,
  172.            0,
  173.            INTERNET_FLAG_RELOAD,
  174.            0);
  175.     dwIndex  := 0;
  176.     dwCodeLen := 10;
  177.  
  178.     // Hinzugefügt
  179.     if Assigned(Application) then application.ProcessMessages;
  180.  
  181.     HttpQueryInfo(hfile,
  182.                   HTTP_QUERY_STATUS_CODE,
  183.                   @dwcode,
  184.                   dwcodeLen,
  185.                   dwIndex);
  186.     res := pchar(@dwcode);
  187.     dwNumber := sizeof(databuffer)-1;
  188.     if (res ='200') or (res ='302') then
  189.     begin
  190.       while (InternetReadfile(hfile,
  191.                               @databuffer,
  192.                               dwNumber,
  193.                               DwRead)) do
  194.       begin
  195.  
  196.         // Hinzugefügt
  197.         if Assigned(Application) then application.ProcessMessages;
  198.  
  199.         if dwRead =0 then
  200.           break;
  201.         databuffer[dwread]:=#0;
  202.         Str := pchar(@databuffer);
  203.         resStr := resStr + Str;
  204.       end;
  205.     end
  206.     else
  207.       ResStr := 'Status:'+res;
  208.     if assigned(hfile) then
  209.       InternetCloseHandle(hfile);
  210.   end;
  211.  
  212.   // Hinzugefügt
  213.   if Assigned(Application) then application.ProcessMessages;
  214.  
  215.   InternetCloseHandle(hsession);
  216.   Result := resStr;
  217. end;
  218.  
  219. procedure CheckForUpdates(ViaThinkSoftProjectName: string);
  220. var
  221.   cont: string;
  222. begin
  223.   cont := GetHTML('https://www.viathinksoft.de/update/?id='+ViaThinkSoftProjectName);
  224.   if copy(cont, 0, 7) = 'Status:' then
  225.   begin
  226.     Application.MessageBox('Ein Fehler ist aufgetreten. Wahrscheinlich ist keine Internetverbindung aufgebaut, oder der der ViaThinkSoft-Server vorübergehend offline.', 'Fehler', MB_OK + MB_ICONERROR)
  227.   end
  228.   else
  229.   begin
  230.     if cont <> ProgramVersion then
  231.     begin
  232.       if Application.MessageBox('Eine neue Programmversion ist vorhanden. Möchten Sie diese jetzt herunterladen?', 'Information', MB_YESNO + MB_ICONASTERISK) = ID_YES then
  233.         shellexecute(application.handle, 'open', pchar('https://www.viathinksoft.de/update/?id=@'+ViaThinkSoftProjectName), '', '', sw_normal);
  234.     end
  235.     else
  236.     begin
  237.       Application.MessageBox('Es ist keine neue Programmversion vorhanden.', 'Information', MB_OK + MB_ICONASTERISK);
  238.     end;
  239.   end;
  240. end;
  241.  
  242. end.
  243.