public void CopyAllFilesAndSubdirectories(MockFileSystem mockFileSystem, string sourceDir, string destinationDir, MockFileSystem expectedMockFileSystem) { var copyDir = new CopyDir(mockFileSystem); copyDir.CopyAll(sourceDir, destinationDir); //TO-DO: Replace with proper equality comparer Assert.Equal(mockFileSystem.AllPaths.OrderBy(s => s), expectedMockFileSystem.AllPaths.OrderBy(s => s)); Assert.Equal(mockFileSystem.AllFiles.Select(filePath => mockFileSystem.GetFile(filePath).TextContents).OrderBy(s => s), expectedMockFileSystem.AllFiles.Select(filePath => expectedMockFileSystem.GetFile(filePath).TextContents).OrderBy(s => s)); }
static public void Main(string[] args) { if (args.Length == 1) { RenameFiles.Rename(args[0]); } else if (args.Length == 2) { string sourceDirectory = args[0]; string targetDirectory = args[1]; DirectoryInfo diSource = new DirectoryInfo(sourceDirectory); DirectoryInfo diTarget = new DirectoryInfo(targetDirectory); CopyDir.CopyAll(diSource, diTarget); } else { Console.WriteLine("Illegal arguments."); } }
public App() : base() { string[] args = Environment.GetCommandLineArgs(); List <string> preLogMessages = new List <string>(); Parsed <Options> parsedCommandLineArgs = null; string loggingBasePath = System.AppDomain.CurrentDomain.BaseDirectory; string updateDestinationPath = null; if (args.Length > 1) { var result = Parser.Default.ParseArguments <Options>(args); if (result.GetType() == typeof(Parsed <Options>)) { //Parsing succeeded - have to do update check to keep logs in order... parsedCommandLineArgs = (Parsed <Options>)result; if (parsedCommandLineArgs.Value.UpdateDest != null) { if (Directory.Exists(parsedCommandLineArgs.Value.UpdateDest)) { updateDestinationPath = parsedCommandLineArgs.Value.UpdateDest; loggingBasePath = updateDestinationPath; } else { preLogMessages.Add("Directory doesn't exist for update: " + parsedCommandLineArgs.Value.UpdateDest); } } if (parsedCommandLineArgs.Value.BootMEUITMMode) { Log.Information("We are booting into MEUITM mode."); BootMEUITMMode = true; } if (parsedCommandLineArgs.Value.ME3Path != null && Directory.Exists(parsedCommandLineArgs.Value.ME3Path)) { PreloadedME3Path = parsedCommandLineArgs.Value.ME3Path; //get MassEffectModder.ini string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "MassEffectModder"); string _iniPath = Path.Combine(path, "MassEffectModder.ini"); if (!Directory.Exists(path)) { preLogMessages.Add("Preset ME3 path, ini folder doesn't exist, creating."); Directory.CreateDirectory(path); } if (!File.Exists(_iniPath)) { preLogMessages.Add("Preset ME3 path, ini doesn't exist, creating."); File.Create(_iniPath); } IniFile ini = new IniFile(_iniPath); ini.Write("ME3", parsedCommandLineArgs.Value.ME3Path, "GameDataPath"); preLogMessages.Add("Wrote preset ME3 path to " + parsedCommandLineArgs.Value.ME3Path); } if (parsedCommandLineArgs.Value.BootingNewUpdate) { Log.Information("Booting an update"); preLogMessages.Add("Booting an update."); foreach (string file in Directory.GetFiles(Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "*.pdb", SearchOption.AllDirectories)) { File.Delete(file); } } } } Directory.CreateDirectory(loggingBasePath + "\\logs"); Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.RollingFile(loggingBasePath + "\\logs\\alotinstaller-{Date}.txt", flushToDiskInterval: new TimeSpan(0, 0, 15)) .CreateLogger(); this.Dispatcher.UnhandledException += OnDispatcherUnhandledException; POST_STARTUP = true; Log.Information("====================================================="); Log.Information("Logger Started for ALOT Installer."); preLogMessages.ForEach(x => Log.Information("Prelogger boot message: " + x)); if (args.Length > 0) { string commandlineargs = ""; for (int i = 0; i < args.Length; i++) { commandlineargs += args[i] + " "; } Log.Information("Command line arguments: " + commandlineargs); } Log.Information("Working directory: " + Directory.GetCurrentDirectory()); //Update Mode if (updateDestinationPath != null) { Thread.Sleep(2000); //SLEEP WHILE WE WAIT FOR PARENT PROCESS TO STOP. Log.Information("In update mode. Update destination: " + updateDestinationPath); int i = 0; while (i < 5) { i++; try { Log.Information("Applying update"); CopyDir.CopyAll(new DirectoryInfo(System.AppDomain.CurrentDomain.BaseDirectory), new DirectoryInfo(updateDestinationPath)); break; } catch (Exception e) { Log.Error("Error applying update: " + e.Message); if (i < 5) { Thread.Sleep(1000); Log.Information("Attempt #" + (i + 1)); } else { Log.Fatal("Unable to apply update after 5 attempts. We are giving up."); MessageBox.Show("Update was unable to apply. See the logs directory for more information. If this continues to happen please come to the ALOT discord or download a new copy from GitHub."); Environment.Exit(1); } } } Log.Information("Update files have been applied."); updateDestinationPath += "\\"; //add slash Log.Information("Performing update migrations..."); if (Directory.Exists(updateDestinationPath + "MEM_Packages") && !Directory.Exists(updateDestinationPath + @"Data\MEM_Packages")) { Log.Information("Migrating MEM_Packages folder into subfolder"); Directory.Move(updateDestinationPath + "MEM_Packages", updateDestinationPath + @"Data\MEM_Packages"); } if (Directory.Exists(updateDestinationPath + "music") && !Directory.Exists(updateDestinationPath + @"Data\Music")) { Log.Information("Migrating music folder into subfolder"); Directory.Move(updateDestinationPath + "music", updateDestinationPath + @"Data\Music"); } if (Directory.Exists(updateDestinationPath + "bin")) { Log.Information("Deleting old top level bin folder: " + (updateDestinationPath + "bin")); Utilities.DeleteFilesAndFoldersRecursively(updateDestinationPath + "bin"); } if (Directory.Exists(updateDestinationPath + "lib")) { Log.Information("Deleting old top level lib folder"); Utilities.DeleteFilesAndFoldersRecursively(updateDestinationPath + "lib"); } if (Directory.Exists(updateDestinationPath + "Extracted_Mods")) { Log.Information("Deleting leftover Extracted_Mods folder"); Utilities.DeleteFilesAndFoldersRecursively(updateDestinationPath + "Extracted_Mods"); } if (File.Exists(updateDestinationPath + "manifest.xml")) { Log.Information("Deleting leftover manifest.xml file"); File.Delete(updateDestinationPath + "manifest.xml"); } if (File.Exists(updateDestinationPath + "ALOTInstaller.exe.config")) { Log.Information("Deleting leftover config file"); File.Delete(updateDestinationPath + "ALOTInstaller.exe.config"); } if (File.Exists(updateDestinationPath + "manifest-bundled.xml")) { Log.Information("Deleting leftover manifest-bundled.xml file"); File.Delete(updateDestinationPath + "manifest-bundled.xml"); } if (File.Exists(updateDestinationPath + "DEV_MODE")) { Log.Information("Pulling application out of developer mode"); File.Delete(updateDestinationPath + "DEV_MODE"); } Log.Information("Rebooting into normal mode to complete update: " + updateDestinationPath + System.AppDomain.CurrentDomain.FriendlyName); ProcessStartInfo psi = new ProcessStartInfo(updateDestinationPath + System.AppDomain.CurrentDomain.FriendlyName); psi.WorkingDirectory = updateDestinationPath; psi.Arguments = "--completing-update"; if (BootMEUITMMode) { psi.Arguments += " --meuitm-mode"; //pass through } Process.Start(psi); Environment.Exit(0); System.Windows.Application.Current.Shutdown(); } //Normal Mode ToolTipService.ShowDurationProperty.OverrideMetadata(typeof(UIElement), new FrameworkPropertyMetadata(15000)); ToolTipService.ShowOnDisabledProperty.OverrideMetadata( typeof(Control), new FrameworkPropertyMetadata(true)); if (Directory.Exists(loggingBasePath + "Update")) { Thread.Sleep(1000); Log.Information("Removing Update directory"); Directory.Delete(loggingBasePath + "Update", true); } if (File.Exists(loggingBasePath + "ALOTAddonBuilder.exe")) { Log.Information("Deleting Update Shim ALOTAddonBuilder.exe"); File.Delete(loggingBasePath + "ALOTAddonBuilder.exe"); } if (parsedCommandLineArgs != null && parsedCommandLineArgs.Value != null && parsedCommandLineArgs.Value.BootingNewUpdate) { //turn off debug mode Utilities.WriteRegistryKey(Registry.CurrentUser, AlotAddOnGUI.MainWindow.REGISTRY_KEY, AlotAddOnGUI.MainWindow.SETTINGSTR_DEBUGLOGGING, 0); } Log.Information("Program Version: " + System.Reflection.Assembly.GetEntryAssembly().GetName().Version); try { Log.Information("System information:\n" + Utilities.GetOperatingSystemInfo()); Utilities.GetAntivirusInfo(); } catch (Exception e) { Log.Error("UNABLE TO GET SYSTEM INFORMATION OR ANTIVIRUS INFO. This is indiciative that system may not be stable or that WMI is corrupt."); Log.Error(App.FlattenException(e)); } //string releaseId = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ReleaseId", "").ToString(); }
public static void SelectControls() { //выберите файл или директорию Console.WriteLine("Select directory or file"); string newPath = Console.ReadLine(); bool directoryExists = Directory.Exists(newPath); bool fileExists = File.Exists(newPath); string command = ""; //если папка или файл существуют, пишем показываем список команд if (directoryExists || fileExists) { try { Console.WriteLine("Select command:\n" + "c - to copy file or directory\n" + "d - to delete file or directory\n" + "m - move to directory\n" + "e = to exit file or directory"); command = Console.ReadLine(); } catch { Console.WriteLine("File or directory not found!"); command = Console.ReadLine(); } if (command == "c") { CopyDir.CopyAll(); } if (command == "d") { if (Directory.Exists(newPath)) { Directory.Delete(newPath); } if (File.Exists(newPath)) { File.Delete(newPath); } } if (command == "m") { Directory.SetCurrentDirectory(newPath); rootPath = newPath; Console.WriteLine("The current directory is {0}", rootPath); ShowDirectoryAndFiles(rootPath); } else { Environment.Exit(0); } } }