Subversion Repositories aysalia

Rev

Rev 30 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 30 Rev 31
Line 1... Line 1...
1
program AyDos;
1
program AyDos;
2
 
2
 
3
// Aysalia DOS Launcher
3
// Aysalia DOS Launcher
4
// Revision 2018-12-07
4
// Revision 2018-12-08
5
// (C) 2018 Daniel Marschall, ViaThinkSoft
5
// (C) 2018 Daniel Marschall, ViaThinkSoft
6
 
6
 
7
// This launcher does launch DOSBox with the correct *.conf file,
7
// This launcher does launch DOSBox with the correct *.conf file,
8
// centers the window and changes the window title and icon at runtime.
8
// centers the window and changes the window title and icon at runtime.
9
 
9
 
Line 153... Line 153...
153
    end;
153
    end;
154
  end;
154
  end;
155
end;
155
end;
156
 
156
 
157
function ShellExecuteWait(hWnd: HWND; Operation, FileName, Parameters,
157
function ShellExecuteWait(hWnd: HWND; Operation, FileName, Parameters,
158
  Directory: PChar; ShowCmd: Integer): DWord;
158
  Directory: PChar; ShowCmd: Integer; lpEnumFunc: TFNWndEnumProc=nil): DWord;
159
var
159
var
160
  Info: TShellExecuteInfo;
160
  Info: TShellExecuteInfo;
161
  pInfo: PShellExecuteInfo;
161
  pInfo: PShellExecuteInfo;
162
begin
162
begin
163
  pInfo := @Info;
163
  pInfo := @Info;
Line 175... Line 175...
175
  end;
175
  end;
176
  ShellExecuteEx(pInfo);
176
  ShellExecuteEx(pInfo);
177
 
177
 
178
  repeat
178
  repeat
179
    result := WaitForSingleObject(Info.hProcess, 10);
179
    result := WaitForSingleObject(Info.hProcess, 10);
180
    EnumWindows(@EnumWindowsProc, 0);
180
    if Assigned(lpEnumFunc) then EnumWindows(lpEnumFunc, 0);
181
  until (result <> WAIT_TIMEOUT);
181
  until (result <> WAIT_TIMEOUT);
182
end;
182
end;
183
 
183
 
184
function CanRunDosBox: boolean;
184
function CanRunDosBox: boolean;
185
var
185
var
Line 225... Line 225...
225
var
225
var
226
  sFile: string;
226
  sFile: string;
227
begin
227
begin
228
  if CanRunDosBox then
228
  if CanRunDosBox then
229
  begin
229
  begin
-
 
230
    hPsApiDll := LoadLibrary('psapi.dll');
-
 
231
    try
-
 
232
      hIcon := LoadIcon(hInstance, 'MainIcon');
-
 
233
      bCeneredOnce := false;
-
 
234
 
230
    ShellExecuteWait(0, 'open', DOSBOX_EXE, '-noconsole -conf DOSBox.conf',
235
      ShellExecuteWait(0, 'open', DOSBOX_EXE, '-noconsole -conf DOSBox.conf',
231
      PChar(ExtractFilePath(ParamStr(0))), SW_NORMAL);
236
        PChar(ExtractFilePath(ParamStr(0))), SW_NORMAL, @EnumWindowsProc);
232
 
237
 
233
    sFile := IncludeTrailingBackslash(ExtractFilePath(ParamStr(0))) + 'stdout.txt';
238
      sFile := IncludeTrailingBackslash(ExtractFilePath(ParamStr(0))) + 'stdout.txt';
234
    if FileExists(sFile) then DeleteFile(PChar(sFile));
239
      if FileExists(sFile) then DeleteFile(PChar(sFile));
235
 
240
 
236
    sFile := IncludeTrailingBackslash(ExtractFilePath(ParamStr(0))) + 'stderr.txt';
241
      sFile := IncludeTrailingBackslash(ExtractFilePath(ParamStr(0))) + 'stderr.txt';
237
    if FileExists(sFile) then DeleteFile(PChar(sFile));
242
      if FileExists(sFile) then DeleteFile(PChar(sFile));
-
 
243
    finally
-
 
244
      FreeLibrary(hPsApiDll);
-
 
245
      hPsApiDll := 0;
-
 
246
    end;
238
  end
247
  end
239
  else
248
  else
240
  begin
249
  begin
241
    // SEE_MASK_CLASSNAME cannot be used with pure MZ files (it does only work for NE/PE files!)
250
    // SEE_MASK_CLASSNAME cannot be used with pure MZ files (it does only work for NE/PE files!)
242
    // So we need to do the dirty rename-hack...
251
    // So we need to do the dirty rename-hack...
243
    RenameFile(AYDOS_MNU, AYDOS_COM);
252
    if FileExists(AYDOS_MNU) and not FileExists(AYDOS_COM) then RenameFile(AYDOS_MNU, AYDOS_COM);
244
    try
253
    try
245
      ShellExecuteWait(0, 'open', PChar(AYDOS_COM), '', PChar(ExtractFilePath(ParamStr(0))), SW_NORMAL);
254
      ShellExecuteWait(0, 'open', PChar(AYDOS_COM), '',
-
 
255
        PChar(ExtractFilePath(ParamStr(0))), SW_NORMAL, nil);
246
    finally
256
    finally
247
      RenameFile(AYDOS_COM, AYDOS_MNU);
257
      if FileExists(AYDOS_COM) and not FileExists(AYDOS_MNU) then RenameFile(AYDOS_COM, AYDOS_MNU);
248
    end;
258
    end;
249
  end;
259
  end;
250
 
260
 
251
  result := 0;
261
  result := 0;
252
end;
262
end;
253
 
263
 
254
begin
264
begin
255
  hPsApiDll := LoadLibrary('psapi.dll');
-
 
256
  try
-
 
257
    hIcon := LoadIcon(hInstance, 'MainIcon');
-
 
258
    ExitCode := Main;
265
  ExitCode := Main;
259
  finally
-
 
260
    FreeLibrary(hPsApiDll);
-
 
261
    hPsApiDll := 0;
-
 
262
  end;
-
 
263
end.
266
end.