diff --git a/drover.dpr b/drover.dpr index cd97a9f..42d80ae 100644 --- a/drover.dpr +++ b/drover.dpr @@ -31,6 +31,10 @@ type function Delete(s: TSocket): bool; end; +const + OPTIONS_FILENAME = 'drover.ini'; + DLL_FILENAME = 'version.dll'; + var RealGetFileVersionInfoA: function(lptstrFilename: LPSTR; dwHandle, dwLen: DWORD; lpData: Pointer): bool; stdcall; RealGetFileVersionInfoW: function(lptstrFilename: LPWSTR; dwHandle, dwLen: DWORD; lpData: Pointer): bool; stdcall; @@ -63,6 +67,7 @@ var dwFlags: DWORD; const lpTo: TSockAddr; iTolen: integer; lpOverlapped: LPWSAOVERLAPPED; lpCompletionRoutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE): integer; stdcall; + currentProcessDir: string; socketManager: TSocketManager; options: TDroverOptions; proxyValue: string; @@ -195,11 +200,42 @@ begin result := RealGetEnvironmentVariableW(lpName, lpBuffer, nSize); end; +procedure CopyFilesToNewVersionFolderIfNeeded(lpApplicationName: LPCWSTR); +var + launchingDir: string; + srcOptionsPath, srcDllPath, dstOptionsPath, dstDllPath: string; +begin + if lpApplicationName = nil then + exit; + + if not SameText(ExtractFileName(lpApplicationName), 'Discord.exe') then + exit; + + if not SameText(ExtractFileName(ParamStr(0)), 'Discord.exe') then + exit; + + launchingDir := IncludeTrailingPathDelimiter(ExtractFilePath(lpApplicationName)); + + srcOptionsPath := currentProcessDir + OPTIONS_FILENAME; + srcDllPath := currentProcessDir + DLL_FILENAME; + dstOptionsPath := launchingDir + OPTIONS_FILENAME; + dstDllPath := launchingDir + DLL_FILENAME; + + if FileExists(launchingDir + 'Discord.exe') and FileExists(srcOptionsPath) and FileExists(srcDllPath) and + not FileExists(dstOptionsPath) and not FileExists(dstDllPath) then + begin + CopyFile(PChar(srcOptionsPath), PChar(dstOptionsPath), true); + CopyFile(PChar(srcDllPath), PChar(dstDllPath), true); + end; +end; + function MyCreateProcessW(lpApplicationName: LPCWSTR; lpCommandLine: LPWSTR; lpProcessAttributes, lpThreadAttributes: PSecurityAttributes; bInheritHandles: bool; dwCreationFlags: DWORD; lpEnvironment: Pointer; lpCurrentDirectory: LPCWSTR; const lpStartupInfo: TStartupInfoW; var lpProcessInformation: TProcessInformation): bool; stdcall; begin + CopyFilesToNewVersionFolderIfNeeded(lpApplicationName); + result := RealCreateProcessW(lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation); end; @@ -211,7 +247,7 @@ begin s := RealGetCommandLineW; if proxyValue <> '' then begin - if Pos('Discord.exe', ParamStr(0)) > 0 then + if SameText(ExtractFileName(ParamStr(0)), 'Discord.exe') then s := s + ' --proxy-server=' + proxyValue; end; result := PChar(s); @@ -251,7 +287,7 @@ var begin SetLength(s, MAX_PATH); GetSystemDirectory(PChar(s), MAX_PATH); - result := IncludeTrailingBackSlash(PChar(s)); + result := IncludeTrailingPathDelimiter(PChar(s)); end; procedure LoadOriginalVersionDll; @@ -312,7 +348,7 @@ var filename: string; begin try - filename := ExtractFilePath(ParamStr(0)) + 'drover.ini'; + filename := currentProcessDir + OPTIONS_FILENAME; f := TIniFile.Create(filename); try @@ -344,6 +380,7 @@ exports MyVerQueryValueW name 'VerQueryValueW'; begin + currentProcessDir := IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0))); socketManager := TSocketManager.Create; options := LoadOptions; diff --git a/drover.dproj b/drover.dproj index 2d385d6..3278b07 100644 --- a/drover.dproj +++ b/drover.dproj @@ -70,7 +70,6 @@ vclwinx;fmx;vclie;DbxCommonDriver;bindengine;IndyIPCommon;VCLRESTComponents;FireDACCommonODBC;FireDACCommonDriver;appanalytics;IndyProtocols;vclx;IndyIPClient;dbxcds;vcledge;bindcompvclwinx;bindcompfmx;inetdb;FireDACSqliteDriver;DbxClientDriver;soapmidas;vclactnband;fmxFireDAC;dbexpress;DBXMySQLDriver;VclSmp;inet;vcltouch;fmxase;dbrtl;fmxdae;FireDACMSAccDriver;CustomIPTransport;vcldsnap;DBXInterBaseDriver;IndySystem;Skia.Package.VCL;vcldb;vclFireDAC;bindcomp;FireDACCommon;IndyCore;RESTBackendComponents;bindcompdbx;rtl;FireDACMySQLDriver;FireDACADSDriver;RESTComponents;DBXSqliteDriver;vcl;IndyIPServer;dsnapxml;dsnapcon;adortl;vclimg;FireDACPgDriver;FireDAC;inetdbxpress;xmlrtl;tethering;bindcompvcl;dsnap;CloudService;fmxobj;bindcompvclsmp;soaprtl;soapserver;FireDACIBDriver;$(DCC_UsePackage) Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;$(DCC_Namespace) Debug - true CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments= 1033 false @@ -99,8 +98,6 @@ true 1033 - (None) - none