Inno Setup(File Copy失效Debug)

Inno Setup 版本:6.2.2
为什么我的FileCopy用不了
已知BUG:
1.CODE函数无法在安装程序安装完成后执行
2.FileCopy无效
安装包描述:
需要在安装结束后检测文件夹是否存在
文件夹1:C:\ProgramData\TruckersMP
如果文件夹1存在则把三个字体文件复制到
目标1:C:\ProgramData\TruckersMP\data\Shared_mod\font
如果文件夹1不存在则把三个字体文件复制到
目标2:C:\Users\Admin\AppData\Roaming\TruckersMP\installation\data\shared_mod\fonts
源文件1:C:\TruckersMP\Temp\OpenSans.ttf
源文件2:C:\TruckersMP\Temp\OpenSans-Semibold.ttf
源文件3:C:\TruckersMP\Temp\RobotoMono.ttf
问题描述:
C盘TruckersMP正常识别还是没有复制过去

img

img


C盘TruckersMP无法识别,也没有复制到Roaming里面的TruckersMP里面

img

img


帮忙解决一下谢谢!
源代码:

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "TruckersMP汉化"
#define MyAppVersion "1.0.0"
#define MyAppPublisher "SmallHy"
#define MyAppURL "None"
#define MyAppExeName "MyProg.exe"

[Setup]
; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{3C0D160D-241C-445D-A7FD-5447461E272C}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
CreateAppDir=no
LicenseFile=D:\Software\Inno Setup 6\Input\TruckersMP-汉化\License\License.txt
UninstallFilesDir="C:\TruckersMP\Uninst\TruckersMP_Chinese"
; Uncomment the following line to run in non administrative install mode (install for current user only.)
;PrivilegesRequired=lowest
OutputDir=D:\Software\Inno Setup 6\Output
OutputBaseFilename=TruckersMP汉化包
SetupIconFile=D:\Software\Inno Setup 6\Input\Logo\Tmp.ico
Compression=lzma
SolidCompression=yes
WizardStyle=modern
RestartIfNeededByRun=no

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "chinesesimplified"; MessagesFile: "compiler:Languages\ChineseSimplified.isl"

[Files]
Source: "D:\Software\Inno Setup 6\Input\TruckersMP-汉化\Chinese\shared_mod\*"; DestDir: "C:\TruckersMP\Temp"; Flags: ignoreversion recursesubdirs createallsubdirs
; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Code]
function InitializeSetup: Boolean;
var
  InstallDir: string; 
  ProgramDataTruckersMP: string; 
  ProgramDataTruckersMPFont: string;
  RoamingTruckersMP: string; 
  RoamingTruckersMPFont: string; 
begin
  InstallDir := ExpandConstant('C:\TruckersMP\Temp\fonts'); 
  ProgramDataTruckersMP := ExpandConstant('{commonappdata}\TruckersMP'); 
  ProgramDataTruckersMPFont := ProgramDataTruckersMP + '\data\shared_mod\fonts'; 
  RoamingTruckersMP := ExpandConstant('{userappdata}\Roaming\TruckersMP');
  RoamingTruckersMPFont := RoamingTruckersMP + '\installation\data\shared_mod\fonts'; 
  
  if DirExists(ProgramDataTruckersMP) then 
  begin 
// 文件夹存在,将文件复制到 ProgramData\TruckersMP\data\shared_mod\fonts 
  FileCopy(InstallDir + '\OpenSans.ttf', ProgramDataTruckersMPFont + '\OpenSans.ttf', False); 
  FileCopy(InstallDir + '\OpenSans-Semibold.ttf', ProgramDataTruckersMPFont + '\OpenSans-Semibold.ttf', False); 
  FileCopy(InstallDir + '\RobotoMono.ttf', ProgramDataTruckersMPFont + '\RobotoMono.ttf', False); 
  end 
  else 
  begin 
// 文件夹不存在,将文件复制到 {userappdata}\Roaming\TruckersMP\installation\data\shared_mod\fonts  
    FileCopy(InstallDir + '\OpenSans.ttf', RoamingTruckersMPFont + '\OpenSans.ttf', False); 
    FileCopy(InstallDir + '\OpenSans-Semibold.ttf', RoamingTruckersMPFont + '\OpenSans-Semibold.ttf', False); 
    FileCopy(InstallDir + '\RobotoMono.ttf', RoamingTruckersMPFont + '\RobotoMono.ttf', False); 
  end; 
  Result := True; 
end;

可以的话顺便帮我加一段功能_谢谢
新功能描述:
1.
检测软件eurotrucks2.exe是否在运行
如果是则弹出提示框提示是否关闭
是则关闭,否则终止安装
2.
如果两个文件夹同时存在
则把三个字体文件分别复制到两个目标文件夹里面
---------谢谢!----------

【以下回答由 GPT 生成】

根据您描述的问题,以下是一种可能的解决方案:

首先,要在安装完成后执行代码,您可以使用Inno Setup中的CurStepChanged事件,并在安装结束后检查文件夹是否存在。

其次,您可以使用FileCopy函数将三个字体文件复制到目标文件夹,确保文件复制成功。

以下是修改后的您的脚本:

[Files]
Source: "C:\TruckersMP\Temp\OpenSans.ttf"; DestDir: "{code:GetDestinationDir}"; Flags: external; AfterInstall: CopyFontFiles
Source: "C:\TruckersMP\Temp\OpenSans-Semibold.ttf"; DestDir: "{code:GetDestinationDir}"; Flags: external; AfterInstall: CopyFontFiles
Source: "C:\TruckersMP\Temp\RobotoMono.ttf"; DestDir: "{code:GetDestinationDir}"; Flags: external; AfterInstall: CopyFontFiles

[Code]
var
  DestinationDir: string;

function GetDestinationDir(Param: string): string;
begin
  // 检查文件夹是否存在
  if DirExists('C:\ProgramData\TruckersMP') then
    Result := 'C:\ProgramData\TruckersMP\data\Shared_mod\font'
  else
    Result := 'C:\Users\Admin\AppData\Roaming\TruckersMP\installation\data\shared_mod\fonts';

  DestinationDir := Result;
end;

procedure CopyFontFiles;
begin
  // 使用FileCopy函数将文件复制到目标文件夹
  FileCopy(ExpandConstant('{src}'), DestinationDir + '\' + ExtractFileName(ExpandConstant('{src}')), False);
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  // 在安装结束后检查文件夹是否存在
  if CurStep = ssPostInstall then
  begin
    if DirExists('C:\ProgramData\TruckersMP') then
      MsgBox('文件夹存在', mbInformation, MB_OK)
    else
      MsgBox('文件夹不存在', mbInformation, MB_OK);
  end;
end;

上述代码将检查目标文件夹的情况,并根据结果复制文件到正确的目标文件夹。

请注意,如果目标文件夹不存在,您可能需要在安装程序中创建它。

希望这可以解决您的问题!


如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^