public void CopyFile(string filename) { if (SourcePath.Equals("") || DestPath.Equals("")) { return; } if (SourcePath.Equals(DestPath)) { var result = MessageBox.Show("Такой файл уже существует, вы " + "хотите его заменить?", "Замена файла", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result != MessageBoxResult.OK) { return; } } File.Copy(SourcePath + filename, DestPath + filename, true); if (UpdateListListener != null) { UpdateListListener.UpdateList(SourcePath, filename); } }
public override void GetFilesToDeployOrStage(ProjectParams Params, DeploymentContext SC) { // the first app is the "main" one, the rest are marked as debug files for exclusion from chunking/distribution StagedFileType WorkingFileType = StagedFileType.NonUFS; List <string> Exes = GetExecutableNames(SC); foreach (var Exe in Exes) { string AppBundlePath = ""; if (Exe.StartsWith(CombinePaths(SC.RuntimeProjectRootDir, "Binaries", SC.PlatformDir))) { AppBundlePath = CombinePaths(SC.ShortProjectName, "Binaries", SC.PlatformDir, Path.GetFileNameWithoutExtension(Exe) + ".app"); StageAppBundle(SC, WorkingFileType, CombinePaths(SC.ProjectRoot, "Binaries", SC.PlatformDir, Path.GetFileNameWithoutExtension(Exe) + ".app"), AppBundlePath); } else if (Exe.StartsWith(CombinePaths(SC.RuntimeRootDir, "Engine/Binaries", SC.PlatformDir))) { AppBundlePath = CombinePaths("Engine/Binaries", SC.PlatformDir, Path.GetFileNameWithoutExtension(Exe) + ".app"); string AbsoluteBundlePath = CombinePaths(SC.LocalRoot, AppBundlePath); // ensure the ue4game binary exists, if applicable if (!SC.IsCodeBasedProject && !Directory.Exists(AbsoluteBundlePath) && !SC.bIsCombiningMultiplePlatforms) { LogError("Failed to find app bundle " + AbsoluteBundlePath); throw new AutomationException(ExitCode.Error_MissingExecutable, "Could not find app bundle {0}. You may need to build the UE4 project with your target configuration and platform.", AbsoluteBundlePath); } StageAppBundle(SC, WorkingFileType, CombinePaths(SC.LocalRoot, "Engine/Binaries", SC.PlatformDir, Path.GetFileNameWithoutExtension(Exe) + ".app"), AppBundlePath); } if (!string.IsNullOrEmpty(AppBundlePath)) { SC.StageFiles(WorkingFileType, CombinePaths(SC.ProjectRoot, "Build/Mac"), "Application.icns", false, null, CombinePaths(AppBundlePath, "Contents/Resources"), true); if (Params.bUsesSteam) { SC.StageFiles(StagedFileType.NonUFS, CombinePaths(SC.LocalRoot, "Engine/Source/ThirdParty/Steamworks/Steamv132/sdk/redistributable_bin/osx32"), "libsteam_api.dylib", false, null, CombinePaths(AppBundlePath, "Contents/MacOS"), true); } } // the first app is the "main" one, the rest are marked as debug files for exclusion from chunking/distribution WorkingFileType = StagedFileType.DebugNonUFS; } if (SC.bStageCrashReporter) { string CrashReportClientPath = CombinePaths("Engine/Binaries", SC.PlatformDir, "CrashReportClient.app"); StageAppBundle(SC, StagedFileType.NonUFS, CombinePaths(SC.LocalRoot, "Engine/Binaries", SC.PlatformDir, "CrashReportClient.app"), CrashReportClientPath); } // Copy the splash screen, Mac specific SC.StageFiles(StagedFileType.NonUFS, CombinePaths(SC.ProjectRoot, "Content/Splash"), "Splash.bmp", false, null, null, true); // CEF3 files if (Params.bUsesCEF3) { SC.StageFiles(StagedFileType.NonUFS, CombinePaths(SC.LocalRoot, "Engine/Binaries/ThirdParty/CEF3/Mac/"), "*", true, null, null, true); string UnrealCEFSubProcessPath = CombinePaths("Engine/Binaries", SC.PlatformDir, "UnrealCEFSubProcess.app"); StageAppBundle(SC, StagedFileType.NonUFS, CombinePaths(SC.LocalRoot, "Engine/Binaries", SC.PlatformDir, "UnrealCEFSubProcess.app"), UnrealCEFSubProcessPath); } // Stage the bootstrap executable if (!Params.NoBootstrapExe) { foreach (StageTarget Target in SC.StageTargets) { BuildProduct Executable = Target.Receipt.BuildProducts.FirstOrDefault(x => x.Type == BuildProductType.Executable); if (Executable != null) { // only create bootstraps for executables if (SC.NonUFSStagingFiles.ContainsKey(Executable.Path) && Executable.Path.Replace("\\", "/").Contains("/" + TargetPlatformType.ToString() + "/")) { string BootstrapArguments = ""; if (!SC.IsCodeBasedProject && !ShouldStageCommandLine(Params, SC)) { BootstrapArguments = String.Format("../../../{0}/{0}.uproject", SC.ShortProjectName); } string BootstrapExeName; if (SC.StageTargetConfigurations.Count > 1) { BootstrapExeName = Path.GetFileName(Executable.Path) + ".app"; } else if (Params.IsCodeBasedProject) { BootstrapExeName = Target.Receipt.TargetName + ".app"; } else { BootstrapExeName = SC.ShortProjectName + ".app"; } string AppPath = Executable.Path.Substring(0, Executable.Path.LastIndexOf(".app/") + 4); object Dest = SC.NonUFSStagingFiles[Executable.Path]; foreach (var DestPath in SC.NonUFSStagingFiles[Executable.Path]) { string AppRelativePath = DestPath.Substring(0, DestPath.LastIndexOf(".app/") + 4); StageBootstrapExecutable(SC, BootstrapExeName, AppPath, AppRelativePath, BootstrapArguments); } } } } } // Copy the ShaderCache files, if they exist SC.StageFiles(StagedFileType.UFS, CombinePaths(SC.ProjectRoot, "Content"), "ShaderCache.ushadercache", false, null, null, true); SC.StageFiles(StagedFileType.UFS, CombinePaths(SC.ProjectRoot, "Content"), "ShaderCodeCache.ushadercode", false, null, null, true); }
public override void GetFilesToDeployOrStage(ProjectParams Params, DeploymentContext SC) { // Stage all the build products foreach (StageTarget Target in SC.StageTargets) { SC.StageBuildProductsFromReceipt(Target.Receipt, Target.RequireFilesExist, Params.bTreatNonShippingBinariesAsDebugFiles); } if (SC.bStageCrashReporter) { string CrashReportClientPath = CombinePaths("Engine/Binaries", SC.PlatformDir, "CrashReportClient.app"); StageAppBundle(SC, StagedFileType.NonUFS, CombinePaths(SC.LocalRoot, "Engine/Binaries", SC.PlatformDir, "CrashReportClient.app"), CrashReportClientPath); } // Find the app bundle path List <string> Exes = GetExecutableNames(SC); foreach (var Exe in Exes) { string AppBundlePath = ""; if (Exe.StartsWith(CombinePaths(SC.RuntimeProjectRootDir, "Binaries", SC.PlatformDir))) { AppBundlePath = CombinePaths(SC.ShortProjectName, "Binaries", SC.PlatformDir, Path.GetFileNameWithoutExtension(Exe) + ".app"); } else if (Exe.StartsWith(CombinePaths(SC.RuntimeRootDir, "Engine/Binaries", SC.PlatformDir))) { AppBundlePath = CombinePaths("Engine/Binaries", SC.PlatformDir, Path.GetFileNameWithoutExtension(Exe) + ".app"); } // Copy the custom icon and Steam dylib, if needed if (!string.IsNullOrEmpty(AppBundlePath)) { SC.StageFiles(StagedFileType.NonUFS, CombinePaths(SC.ProjectRoot, "Build/Mac"), "Application.icns", false, null, CombinePaths(AppBundlePath, "Contents/Resources"), true); } } // Copy the splash screen, Mac specific SC.StageFiles(StagedFileType.NonUFS, CombinePaths(SC.ProjectRoot, "Content/Splash"), "Splash.bmp", false, null, null, true); // Stage the bootstrap executable if (!Params.NoBootstrapExe) { foreach (StageTarget Target in SC.StageTargets) { BuildProduct Executable = Target.Receipt.BuildProducts.FirstOrDefault(x => x.Type == BuildProductType.Executable); if (Executable != null) { // only create bootstraps for executables if (SC.NonUFSStagingFiles.ContainsKey(Executable.Path) && Executable.Path.Replace("\\", "/").Contains("/" + TargetPlatformType.ToString() + "/")) { string BootstrapArguments = ""; if (!ShouldStageCommandLine(Params, SC)) { if (!SC.IsCodeBasedProject) { BootstrapArguments = String.Format("../../../{0}/{0}.uproject", SC.ShortProjectName); } else { BootstrapArguments = SC.ShortProjectName; } } string BootstrapExeName; if (SC.StageTargetConfigurations.Count > 1) { BootstrapExeName = Path.GetFileName(Executable.Path) + ".app"; } else if (Params.IsCodeBasedProject) { BootstrapExeName = Target.Receipt.TargetName + ".app"; } else { BootstrapExeName = SC.ShortProjectName + ".app"; } string AppPath = Executable.Path.Substring(0, Executable.Path.LastIndexOf(".app/") + 4); object Dest = SC.NonUFSStagingFiles[Executable.Path]; foreach (var DestPath in SC.NonUFSStagingFiles[Executable.Path]) { string AppRelativePath = DestPath.Substring(0, DestPath.LastIndexOf(".app/") + 4); StageBootstrapExecutable(SC, BootstrapExeName, AppPath, AppRelativePath, BootstrapArguments); } } } } } // Copy the ShaderCache files, if they exist SC.StageFiles(StagedFileType.UFS, CombinePaths(SC.ProjectRoot, "Content"), "DrawCache.ushadercache", false, null, null, true); SC.StageFiles(StagedFileType.UFS, CombinePaths(SC.ProjectRoot, "Content"), "ByteCodeCache.ushadercode", false, null, null, true); }
public bool StartInstall() { InstallStarted = false; if (Transfer.IsBusy || !File.Exists(DestPath)) { return(false); } const string nonHash = "None"; var fileHash = default(string); foreach (var(_, item2, _, item4) in SrcData) { if (!item4) { continue; } if (fileHash == default || fileHash == nonHash) { switch (item2.Length) { case Crypto.Md5.HashLength: fileHash = DestPath.EncryptFile(); break; case Crypto.Sha1.HashLength: fileHash = DestPath.EncryptFile(ChecksumAlgorithm.Sha1); break; case Crypto.Sha256.HashLength: fileHash = DestPath.EncryptFile(ChecksumAlgorithm.Sha256); break; case Crypto.Sha384.HashLength: fileHash = DestPath.EncryptFile(ChecksumAlgorithm.Sha384); break; case Crypto.Sha512.HashLength: fileHash = DestPath.EncryptFile(ChecksumAlgorithm.Sha512); break; default: fileHash = nonHash; break; } } if (fileHash != nonHash && !fileHash.EqualsEx(item2)) { switch (MessageBoxEx.Show(string.Format(CultureInfo.InvariantCulture, Language.GetText(nameof(en_US.ChecksumErrorMsg)), Path.GetFileName(DestPath)), Resources.GlobalTitle, MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button3)) { case DialogResult.Ignore: break; case DialogResult.Retry: AutoRetry = true; continue; default: continue; } } if (Directory.Exists(AppData.InstallDir)) { if (!BreakFileLocks(AppData.InstallDir, false)) { MessageBoxEx.Show(string.Format(CultureInfo.InvariantCulture, Language.GetText(nameof(en_US.InstallSkippedMsg)), AppData.Name), Resources.GlobalTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); continue; } } if (DestPath.EndsWithEx(".7z", ".rar", ".zip")) { if (!File.Exists(CorePaths.FileArchiver)) { throw new PathNotFoundException(CorePaths.FileArchiver); } using (var process = Compaction.SevenZipHelper.Unzip(DestPath, AppData.InstallDir)) if (process?.HasExited == false) { process.WaitForExit(); } } else { var appsDir = CorePaths.AppsDir; using (var process = ProcessEx.Start(DestPath, appsDir, $"/DESTINATION=\"{appsDir}\\\"", Elevation.IsAdministrator, false)) if (process?.HasExited == false) { process.WaitForInputIdle(0x1000); try { var buttons = Settings.NsisButtons; if (buttons == null) { throw new NotSupportedException(); } var okButton = buttons.Take(2).ToArray(); var langId = WinApi.NativeHelper.GetUserDefaultUILanguage(); var wndState = langId == 1031 || langId == 1033 || langId == 2057 ? WinApi.ShowWindowFlags.ShowMinNoActive : WinApi.ShowWindowFlags.ShowNa; var stopwatch = Stopwatch.StartNew(); var minimized = new List <IntPtr>(); var counter = new CounterInvestor <int>(); while (stopwatch.Elapsed.TotalMinutes < 5d) { if (process.HasExited) { break; } string title; using (var proc = Process.GetProcessById(process.Id)) title = proc.MainWindowTitle; if (string.IsNullOrEmpty(title)) { continue; } var parent = WinApi.NativeHelper.FindWindow(null, title); if (parent == IntPtr.Zero) { continue; } if (!minimized.Contains(parent) && WinApi.NativeHelper.ShowWindowAsync(parent, wndState)) { minimized.Add(parent); } foreach (var button in buttons) { var child = WinApi.NativeHelper.FindWindowEx(parent, IntPtr.Zero, "Button", button); if (child == IntPtr.Zero) { continue; } if (counter.Increase(button.GetHashCode()) > 10) { if (button.EqualsEx(okButton)) { goto Manually; } continue; } WinApi.NativeHelper.SendMessage(child, 0xf5u, IntPtr.Zero, IntPtr.Zero); } } } catch (Exception ex) when(ex.IsCaught()) { Log.Write(ex); } Manually: if (!process.HasExited) { try { using (var proc = Process.GetProcessById(process.Id)) { var hWnd = WinApi.NativeHelper.FindWindow(null, proc.MainWindowTitle); WinApi.NativeHelper.ShowWindowAsync(hWnd, WinApi.ShowWindowFlags.ShowNormal); WinApi.NativeHelper.SetForegroundWindow(hWnd); WinApi.NativeHelper.SetWindowPos(hWnd, new IntPtr(-1), 0, 0, 0, 0, WinApi.SetWindowPosFlags.NoMove | WinApi.SetWindowPosFlags.NoSize); } } catch (Exception ex) when(ex.IsCaught()) { Log.Write(ex); } process.WaitForExit(); } } // fix for messy app installer var retries = 0; retry: try { var appDirs = new[] { Path.Combine(appsDir, "App"), Path.Combine(appsDir, "Data"), Path.Combine(appsDir, "Other") }; if (appDirs.Any(Directory.Exists)) { if (!Directory.Exists(AppData.InstallDir)) { Directory.CreateDirectory(AppData.InstallDir); } else { BreakFileLocks(AppData.InstallDir); foreach (var dir in new[] { "App", "Other" }.Select(name => Path.Combine(AppData.InstallDir, name)).Where(Directory.Exists)) { Directory.Delete(dir, true); } foreach (var file in Directory.EnumerateFiles(AppData.InstallDir, "*.*", SearchOption.TopDirectoryOnly)) { File.Delete(file); } } foreach (var dir in appDirs) { if (!Directory.Exists(dir)) { continue; } var dirName = Path.GetFileName(dir); if (string.IsNullOrEmpty(dirName)) { continue; } BreakFileLocks(dir); if (dirName.EqualsEx("Data")) { Directory.Delete(dir, true); continue; } var innerDir = Path.Combine(AppData.InstallDir, dirName); Directory.Move(innerDir, dir); } foreach (var file in Directory.EnumerateFiles(appsDir, "*.*", SearchOption.TopDirectoryOnly)) { if (FileEx.IsHidden(file) || file.EndsWithEx(".7z", ".rar", ".zip", ".paf.exe")) { continue; } var fileName = Path.GetFileName(file); if (string.IsNullOrEmpty(fileName)) { continue; } BreakFileLocks(file); var innerFile = Path.Combine(AppData.InstallDir, fileName); File.Move(innerFile, file); } } } catch (Exception ex) when(ex.IsCaught()) { Log.Write(ex); if (retries >= 15) { return(false); } retries++; Thread.Sleep(1000); goto retry; } } FileEx.TryDelete(DestPath); InstallStarted = true; return(true); } return(false); }