Skip to content

Commit

Permalink
Add auto-copy of required files to new Discord folder after update
Browse files Browse the repository at this point in the history
  • Loading branch information
hdrover committed Oct 25, 2024
1 parent a36b852 commit fc0864d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
43 changes: 40 additions & 3 deletions drover.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -312,7 +348,7 @@ var
filename: string;
begin
try
filename := ExtractFilePath(ParamStr(0)) + 'drover.ini';
filename := currentProcessDir + OPTIONS_FILENAME;

f := TIniFile.Create(filename);
try
Expand Down Expand Up @@ -344,6 +380,7 @@ exports
MyVerQueryValueW name 'VerQueryValueW';

begin
currentProcessDir := IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0)));
socketManager := TSocketManager.Create;

options := LoadOptions;
Expand Down
3 changes: 0 additions & 3 deletions drover.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
<DCC_UsePackage>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)</DCC_UsePackage>
<DCC_Namespace>Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;$(DCC_Namespace)</DCC_Namespace>
<BT_BuildType>Debug</BT_BuildType>
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<VerInfo_Locale>1033</VerInfo_Locale>
<DCC_SYMBOL_PLATFORM>false</DCC_SYMBOL_PLATFORM>
Expand Down Expand Up @@ -99,8 +98,6 @@
<PropertyGroup Condition="'$(Cfg_2_Win64)'!=''">
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
<VerInfo_Locale>1033</VerInfo_Locale>
<Manifest_File>(None)</Manifest_File>
<AppDPIAwarenessMode>none</AppDPIAwarenessMode>
</PropertyGroup>
<ItemGroup>
<DelphiCompile Include="$(MainSource)">
Expand Down

0 comments on commit fc0864d

Please sign in to comment.