public MainWindowViewModel(Window owner) { this.owner = owner; // Set up application data and log folders string appDataPath = Utils.AppDataFolder; if (!Directory.Exists(appDataPath)) Directory.CreateDirectory(appDataPath); string logPath = Path.Combine(appDataPath, "logs"); if (!Directory.Exists(logPath)) Directory.CreateDirectory(logPath); LogFile.Open(Path.Combine(logPath, "disParity.log"), false); LogFile.Log("Application launched (version {0})", disParity.Version.VersionString); updateTimer = new System.Timers.Timer(1000); updateTimer.AutoReset = true; updateTimer.Elapsed += HandleUpdateTimer; updateParityStatusTimer = new System.Timers.Timer(1000); updateParityStatusTimer.AutoReset = true; updateParityStatusTimer.Elapsed += UpdateParityStatus; pingTimer = new System.Timers.Timer(TimeSpan.FromHours(24).TotalMilliseconds); pingTimer.AutoReset = true; pingTimer.Elapsed += HandlePingTimer; operationManager = new OperationManager(this); operationManager.OperationFinished += HandleOperationFinished; // Try to load the config.xml now, we need it to set the main window position. // If it fails, use default values for everything and display a dialog in Loaded() try { config = new Config(Path.Combine(Utils.AppDataFolder, "Config.xml")); if (config.Exists) { config.Load(); config.Validate(); } } catch (Exception e) { configLoadException = e; config.MakeBackup(); config.Reset(); } Left = config.MainWindowX; Top = config.MainWindowY; Height = config.MainWindowHeight; Width = config.MainWindowWidth; }
static void Main(string[] args) { string recoverDir = ""; Command cmd = Command.None; bool verbose = false; if (args.Length > 0) { if (args[0].ToLower() == "update") cmd = Command.Update; else if (args[0].ToLower() == "verify") { cmd = Command.Verify; } else if ((args.Length == 3) && args[0].ToLower() == "recover") { cmd = Command.Recover; if (!ReadDriveNum(args)) return; recoverDir = args[2]; } else if ((args.Length == 2) && args[0].ToLower() == "test") { cmd = Command.Test; if (!ReadDriveNum(args)) return; } else if (args[0].ToLower() == "list") { cmd = Command.List; if (args.Length == 2) { if (!ReadDriveNum(args)) return; } } else if (args[0].ToLower() == "stats") cmd = Command.Stats; else if (args[0].ToLower() == "hashcheck") { cmd = Command.HashCheck; if (args.Length == 2) { if (!ReadDriveNum(args)) return; } } else if (args[0].ToLower() == "monitor") { verbose = true; cmd = Command.Monitor; } else if (args[0].ToLower() == "undelete") { cmd = Command.Undelete; if (!ReadDriveNum(args)) return; } } if (args.Length > 1 && (cmd == Command.Update || cmd == Command.Verify)) { if (args[1].ToLower() == "-v") verbose = true; else { PrintUsage(); return; } } if (cmd == Command.None) { PrintUsage(); return; } if (SingleInstance.AlreadyRunning()) { Console.WriteLine("Another instance of disParity is currently running."); return; } disParity.Version.DoUpgradeCheck(HandleNewVersionAvailable); string appDataPath = Utils.AppDataFolder; if (!Directory.Exists(appDataPath)) Directory.CreateDirectory(appDataPath); string logPath = Path.Combine(appDataPath, "logs"); if (!Directory.Exists(logPath)) Directory.CreateDirectory(logPath); string logFileName = Path.Combine(logPath, "disParity " + DateTime.Now.ToString("yy-MM-dd HH.mm.ss")); LogFile.Open(logFileName, verbose); LogFile.Write("Beginning \"{0}\" command at {1} on {2}\r\n", args[0].ToLower(), DateTime.Now.ToShortTimeString(), DateTime.Today.ToLongDateString()); string ConfigPath = Path.Combine(appDataPath, "Config.xml"); try { config = new Config(ConfigPath); config.Load(); } catch (Exception e) { LogFile.Write("Could not load Config file: " + e.Message); return; } try { ParitySet set = new ParitySet(config, null); // <--- FIX ME, need to pass actual environment here set.ReloadDrives(); switch (cmd) { case Command.Update: set.Update(true); break; case Command.Recover: int successes; int failures; set.Recover(set.Drives[driveNum], recoverDir, out successes, out failures); break; case Command.HashCheck: if (driveNum != -1) set.HashCheck(set.Drives[driveNum]); //else // set.HashCheck(); break; } } catch (Exception e) { LogFile.Log("Fatal error encountered during {0}: {1}", args[0].ToLower(), e.Message); LogFile.Log("Stack trace: {0}", e.StackTrace); } finally { if (!String.IsNullOrEmpty(shutdownMsg)) LogFile.Write(shutdownMsg); LogFile.Close(); } }