Subversion Repositories spacemission

Rev

Rev 61 | Rev 72 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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