private static void Update(string updateeFilePath, string packageContentDirPath, bool restartUpdatee) { // Wait until updatee is writable to ensure all running instances have exited WriteLog("Waiting for all running updatee instances to exit..."); while (!FileEx.CheckWriteAccess(updateeFilePath)) { Thread.Sleep(100); } // Copy over the package contents WriteLog("Copying package contents from storage to updatee's directory..."); var updateeDirPath = Path.GetDirectoryName(updateeFilePath); DirectoryEx.Copy(packageContentDirPath, updateeDirPath); // Launch the updatee again if requested if (restartUpdatee) { WriteLog("Restarting updatee..."); using (var restartedUpdateeProcess = Process.Start(updateeFilePath)) WriteLog($"Restarted as pid:{restartedUpdateeProcess?.Id}."); } // Delete package content directory WriteLog("Deleting package contents from storage..."); Directory.Delete(packageContentDirPath, true); }
private static void Update(int updateeProcessId, string updateeFilePath, string packageContentDirPath, bool restartUpdatee) { // Get updatee directory path from file path var updateeDirPath = Path.GetDirectoryName(updateeFilePath); // Wait until updatee dies WriteLog("Waiting for updatee to exit..."); ProcessEx.WaitForExit(updateeProcessId); // Copy over the extracted package WriteLog("Copying package contents..."); DirectoryEx.Copy(packageContentDirPath, updateeDirPath); // Launch the updatee again if requested if (restartUpdatee) { WriteLog("Restarting updatee..."); Process.Start(updateeFilePath); } // Delete package directory WriteLog("Deleting package contents..."); Directory.Delete(packageContentDirPath, true); }
public void WithInstructions() { var instructions = InstructionBuilder .Create() .WithCalamariInstruction("test-calamari-instruction") .WithNodeInstruction() .AsString(); using (var temporaryDirectory = TemporaryDirectory.Create()) { var generatedApplicationPath = CodeGenerator.GenerateConsoleApplication("node", temporaryDirectory.DirectoryPath); var toolRoot = Path.Combine(temporaryDirectory.DirectoryPath, "app"); var destinationPath = CalamariEnvironment.IsRunningOnWindows ? toolRoot : Path.Combine(toolRoot, "bin"); DirectoryEx.Copy(generatedApplicationPath, destinationPath); var variables = new VariableDictionary { { SpecialVariables.Execution.Manifest, instructions }, { nameof(NodeInstructions.BootstrapperPathVariable), "BootstrapperPathVariable_Value" }, { nameof(NodeInstructions.NodePathVariable), toolRoot }, { nameof(NodeInstructions.TargetEntryPoint), "TargetEntryPoint_Value" }, { nameof(NodeInstructions.TargetPathVariable), "TargetPathVariable_Value" }, }; var result = ExecuteCommand(variables, "Calamari.Tests"); result.AssertSuccess(); result.AssertOutput(string.Join(Environment.NewLine, "Hello from TestCommand", "Hello from my custom node!", Path.Combine("BootstrapperPathVariable_Value", "bootstrapper.js"), Path.Combine("TargetPathVariable_Value", "TargetEntryPoint"))); } }
private void RunCore() { var updateeDirPath = Path.GetDirectoryName(_updateeFilePath); // Wait until updatee is writable to ensure all running instances have exited WriteLog("Waiting for all running updatee instances to exit..."); while (!FileEx.CheckWriteAccess(_updateeFilePath)) { Thread.Sleep(100); } // Copy over the package contents WriteLog("Copying package contents from storage to updatee's directory..."); DirectoryEx.Copy(_packageContentDirPath, updateeDirPath); // Restart updatee if requested if (_restartUpdatee) { var startInfo = new ProcessStartInfo { WorkingDirectory = updateeDirPath, Arguments = _routedArgs, UseShellExecute = true // avoid sharing console window with updatee }; // If updatee is an .exe file - start it directly if (string.Equals(Path.GetExtension(_updateeFilePath), ".exe", StringComparison.OrdinalIgnoreCase)) { startInfo.FileName = _updateeFilePath; } // If not - figure out what to do with it else { // If there's an .exe file with same name - start it instead // Security vulnerability? if (File.Exists(Path.ChangeExtension(_updateeFilePath, ".exe"))) { startInfo.FileName = Path.ChangeExtension(_updateeFilePath, ".exe"); } // Otherwise - start the updatee using dotnet SDK else { startInfo.FileName = "dotnet"; startInfo.Arguments = $"{_updateeFilePath} {_routedArgs}"; } } WriteLog($"Restarting updatee [{startInfo.FileName} {startInfo.Arguments}]..."); using var restartedUpdateeProcess = Process.Start(startInfo); WriteLog($"Restarted as pid:{restartedUpdateeProcess?.Id}."); } // Delete package content directory WriteLog("Deleting package contents from storage..."); Directory.Delete(_packageContentDirPath, true); }
public void CreateCommand([Option(0, "利用するテンプレート名")] string templateName, [Option(1, "作成するコンテスト名")] string contestName) { var templateConfig = new TemplateConfig(); if (!templateConfig.IsInstalled(templateName)) { Console.Error.WriteLine($"WA! {templateName} がテンプレート名に存在しません。"); Console.Error.WriteLine($" テンプレート一覧を確認してください。"); Console.WriteLine($"テンプレート名 : テンプレートへのパス"); foreach (var template in templateConfig.ListTemplate()) { Console.WriteLine($"{template.name} : {template.path}"); } return; } var invalidFileNameString = new string(Path.GetInvalidFileNameChars()); if (invalidFileNameString.Any(invalidChar => contestName.Contains(invalidChar))) { Console.Error.WriteLine($"WA! 以下の文字は、コンテスト名に含むことができません。"); Console.Error.WriteLine($" {String.Join(" ", invalidFileNameString)}"); return; } if (Directory.Exists(contestName) || File.Exists(contestName)) { Console.Error.WriteLine($"WA! {contestName} はすでに存在しています。別のコンテスト名を使用してください。"); return; } if (!templateConfig.IsInstalled(templateName)) { var template = templateConfig.Get(templateName); Console.Error.WriteLine($"CE! テンプレート名 {template.name} のパス {template.path} に、テンプレートが存在しません。"); Console.Error.WriteLine($" install コマンドと -update オプションで、修正したテンプレートへのパスを上書き登録してください。"); return; } Console.WriteLine("WJ... コンテスト名のディレクトリを作成します。"); Directory.CreateDirectory(contestName); foreach (var problemName in new List <string> { "A", "B", "C", "D", "E", "F" }) { Console.WriteLine($"WJ... {problemName} ディレクトリを作成します。"); var template = templateConfig.Get(templateName); var problemPath = Path.Combine(contestName, problemName); DirectoryEx.Copy(template.path, problemPath); } Console.WriteLine("AC! コンテスト用の各問題の作成が完了しました。"); }
private static void CopyBaseFile(string destDir) { var maxVerPath = GetMaxVersionPath(); if (string.IsNullOrEmpty(maxVerPath)) { //NetUtil.DownFile(baseDownloadUrl, _baseFn, baseLength); //Zip.UnZipFile(_baseFn, destDir, null); Log.Info("缺少基础版本.....无法升级到最新版"); //MsgBox.ShowErrTip("无法升级到最新版....请手动安装!!"); } else { DirectoryEx.Copy(maxVerPath, destDir); } }
/// <summary> /// Builds the executable and packages the game. /// </summary> public static void Build() { PlatformType activePlatform = ActivePlatform; PlatformInfo platformInfo = ActivePlatformInfo; string srcRoot = GetBuildFolder(BuildFolder.SourceRoot, activePlatform); string destRoot = GetBuildFolder(BuildFolder.DestinationRoot, activePlatform); // Prepare clean destination folder if (Directory.Exists(destRoot)) { Directory.Delete(destRoot, true); } Directory.CreateDirectory(destRoot); // Compile game assembly string bansheeAssemblyFolder; if (platformInfo.Debug) { bansheeAssemblyFolder = GetBuildFolder(BuildFolder.BansheeDebugAssemblies, activePlatform); } else { bansheeAssemblyFolder = GetBuildFolder(BuildFolder.BansheeReleaseAssemblies, activePlatform); } string srcBansheeAssemblyFolder = Path.Combine(srcRoot, bansheeAssemblyFolder); string destBansheeAssemblyFolder = Path.Combine(destRoot, bansheeAssemblyFolder); Directory.CreateDirectory(destBansheeAssemblyFolder); CompilerInstance ci = ScriptCompiler.CompileAsync(ScriptAssemblyType.Game, ActivePlatform, platformInfo.Debug, destBansheeAssemblyFolder); // Copy engine assembly { string srcFile = Path.Combine(srcBansheeAssemblyFolder, EditorApplication.EngineAssemblyName); string destFile = Path.Combine(destBansheeAssemblyFolder, EditorApplication.EngineAssemblyName); File.Copy(srcFile, destFile); } // Copy builtin data string dataFolder = GetBuildFolder(BuildFolder.Data, activePlatform); string srcData = Path.Combine(srcRoot, dataFolder); string destData = Path.Combine(destRoot, dataFolder); DirectoryEx.Copy(srcData, destData); // Copy native binaries string binaryFolder = GetBuildFolder(BuildFolder.NativeBinaries, activePlatform); string srcBin = Path.Combine(srcRoot, binaryFolder); string destBin = destRoot; string[] nativeBinaries = GetNativeBinaries(activePlatform); foreach (var entry in nativeBinaries) { string srcFile = Path.Combine(srcBin, entry); string destFile = Path.Combine(destBin, entry); File.Copy(srcFile, destFile); } // Copy .NET framework assemblies string frameworkAssemblyFolder = GetBuildFolder(BuildFolder.FrameworkAssemblies, activePlatform); string srcFrameworkAssemblyFolder = Path.Combine(srcRoot, frameworkAssemblyFolder); string destFrameworkAssemblyFolder = Path.Combine(destRoot, frameworkAssemblyFolder); Directory.CreateDirectory(destFrameworkAssemblyFolder); string[] frameworkAssemblies = GetFrameworkAssemblies(activePlatform); foreach (var entry in frameworkAssemblies) { string srcFile = Path.Combine(srcFrameworkAssemblyFolder, entry + ".dll"); string destFile = Path.Combine(destFrameworkAssemblyFolder, entry + ".dll"); File.Copy(srcFile, destFile); } // Copy Mono string monoFolder = GetBuildFolder(BuildFolder.Mono, activePlatform); string srcMonoFolder = Path.Combine(srcRoot, monoFolder); string destMonoFolder = Path.Combine(destRoot, monoFolder); DirectoryEx.Copy(srcMonoFolder, destMonoFolder); string srcExecFile = GetMainExecutable(activePlatform); string destExecFile = Path.Combine(destBin, Path.GetFileName(srcExecFile)); File.Copy(srcExecFile, destExecFile); InjectIcons(destExecFile, platformInfo); PackageResources(destRoot, platformInfo); CreateStartupSettings(destRoot, platformInfo); // Wait until compile finishes while (!ci.IsDone) { Thread.Sleep(200); } ci.Dispose(); }
private static void Update(string updateeFilePath, string packageContentDirPath, bool restartUpdatee) { var updateeDirPath = Path.GetDirectoryName(updateeFilePath); // Wait until updatee is writable to ensure all running instances have exited WriteLog("Waiting for all running updatee instances to exit..."); while (!FileEx.CheckWriteAccess(updateeFilePath)) { Thread.Sleep(100); } // Copy over the package contents WriteLog("Copying package contents from storage to updatee's directory..."); DirectoryEx.Copy(packageContentDirPath, updateeDirPath); // Restart updatee if requested if (restartUpdatee) { WriteLog("Restarting updatee..."); var startInfo = new ProcessStartInfo { WorkingDirectory = updateeDirPath }; // If updatee is an .exe file - start it directly if (string.Equals(Path.GetExtension(updateeFilePath), ".exe", StringComparison.OrdinalIgnoreCase)) { startInfo.FileName = updateeFilePath; } // If not - figure out what to do with it else { //Start with dotnet if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { var process = new Process { StartInfo = new ProcessStartInfo { FileName = "dotnet", Arguments = Path.GetFileName(updateeFilePath), WorkingDirectory = Path.GetDirectoryName(updateeFilePath), UseShellExecute = false, RedirectStandardOutput = false, RedirectStandardError = false, CreateNoWindow = true } }; WriteLog("Windows detected. Restarting with: " + process.StartInfo.FileName + " " + process.StartInfo.Arguments + " in WorkingDirectory: " + process.StartInfo.WorkingDirectory); process.Start(); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { var process = new Process { StartInfo = new ProcessStartInfo { FileName = "/bin/bash", Arguments = "-c \" " + "dotnet " + updateeFilePath + " \"", UseShellExecute = false, } }; WriteLog("Linux detected. Restarting with: " + process.StartInfo.FileName + " " + process.StartInfo.Arguments); process.Start(); } } } // Delete package content directory WriteLog("Deleting package contents from storage..."); Directory.Delete(packageContentDirPath, true); }
/// <summary> /// Enables/disables the directory redirection. /// </summary> /// <param name="option"> /// The option that determines whether the redirect will be enabled or disabled. /// </param> /// <param name="dirMap"> /// The diretory map. /// <para> /// The key is used for the source directory, and the value is used for the /// destination directory. /// </para> /// </param> public static void DirRedirection(PortalizerActions option, Dictionary <string, string> dirMap) { if (dirMap?.Any() != true) { return; } var hash = nameof(DirRedirection).Encrypt(); var hPath = PathEx.Combine(Attributes.TempDir, hash); switch (option) { case PortalizerActions.Disable: FileEx.TryDelete(hPath); break; default: if (File.Exists(hPath)) { DirRedirection(PortalizerActions.Disable, dirMap); } FileEx.Create(hPath); break; } foreach (var data in dirMap) { if (string.IsNullOrWhiteSpace(data.Key) || string.IsNullOrWhiteSpace(data.Value)) { continue; } var srcPath = PathEx.Combine(data.Key); var destPath = PathEx.Combine(data.Value); DirectoryEx.SetAttributes(srcPath, FileAttributes.Normal); var backupPath = $"{srcPath}-{{{EnvironmentEx.MachineId}}}.backup"; switch (option) { case PortalizerActions.Disable: DirectoryEx.SetAttributes(backupPath, FileAttributes.Normal); if (DirectoryEx.DestroySymbolicLink(srcPath, true)) { continue; } try { if (Directory.Exists(srcPath)) { DirectoryEx.SetAttributes(srcPath, FileAttributes.Normal); DirectoryEx.Copy(srcPath, destPath, true, true); Directory.Delete(srcPath, true); } if (Directory.Exists(backupPath)) { DirectoryEx.Copy(backupPath, srcPath, true, true); Directory.Delete(backupPath); } } catch (Exception ex) { Log.Write(ex); } break; default: if (DirectoryEx.CreateSymbolicLink(srcPath, destPath, true)) { DirectoryEx.SetAttributes(backupPath, FileAttributes.Normal); continue; } try { if (Directory.Exists(srcPath)) { if (!Directory.Exists(backupPath)) { DirectoryEx.Move(srcPath, backupPath); DirectoryEx.SetAttributes(backupPath, FileAttributes.Hidden); } if (Directory.Exists(srcPath)) { Directory.Delete(srcPath, true); } } if (Directory.Exists(destPath)) { DirectoryEx.SetAttributes(destPath, FileAttributes.Normal); DirectoryEx.Copy(destPath, srcPath); } if (!Directory.Exists(srcPath)) { Directory.CreateDirectory(srcPath); } } catch (Exception ex) { Log.Write(ex); } break; } } }
/// <summary> /// Copy direcotries recursively /// </summary> /// <param name="sourceDirInfo"></param> /// <param name="targetDirPath"></param> public static void Copy(this DirectoryInfo sourceDirInfo, string targetDirPath) { DirectoryEx.Copy(sourceDirInfo.FullName, targetDirPath); return; }