Example #1
0
        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();
              }
        }
        /// <summary>
        /// Called from View when main window has loaded
        /// </summary>
        public void Loaded()
        {
            // Check for exception loading config file
              if (configLoadException != null) {
            App.LogCrash(configLoadException);
            MessageWindow.Show(owner, "Invalid config file", "An error occurred loading the config file: \n\n" +
              configLoadException.Message + "\n\nDefault values will be used for most settings.",
              MessageWindowIcon.Error, MessageWindowButton.OK);
              }

              // Make sure parity folder exists
              if (!String.IsNullOrEmpty(config.ParityDir)) {
            try {
              Directory.CreateDirectory(config.ParityDir);
            }
            catch (Exception e) {
              LogFile.Log("Could not create parity folder " + config.ParityDir + ": " + e.Message);
              App.LogCrash(e);
              MessageWindow.Show(owner, "Could not access parity folder", "Unable to access the parity location " + config.ParityDir + "\n\n" +
            "You will need to set a valid parity location (under Options) before proceeding.",
            MessageWindowIcon.Error, MessageWindowButton.OK);
            }
              }

              // the ParitySet constructor really, really should not fail.  If it does, there's nothing we can do,
              // so just let the global unhandled exception handler catch it, report it, and close the app.
              paritySet = new ParitySet(config, new disParityUI.Environment());

              try {
            paritySet.ReloadDrives();
              }
              catch (Exception e) {
            App.LogCrash(e);
            MessageWindow.Show(owner, "Can't load backup information", "An error occurred while trying to load the backup: \n\n" +
              e.Message,
              MessageWindowIcon.Error, MessageWindowButton.OK);
              }

              AddDrives();
              paritySet.PropertyChanged += HandleParitySetPropertyChanged;

              UpdateStartupMessage();
              UpdateParityStatus();

              try {
            if (!disParity.License.Accepted) {
              if (!ShowLicenseAgreement()) {
            owner.Close();
            return;
              }
              disParity.License.Accepted = true;
            }

            // check for new version now and again every 24 hours
            disParity.Version.DoUpgradeCheck(HandleNewVersionAvailable);
            pingTimer.Start();

            ScanAll();
              }
              catch (Exception e) {
            App.LogCrash(e);
            LogFile.Log("Exception in MainWindow.Loaded: " + e.Message);
              }
        }
 public OptionsDialogViewModel(ParitySet paritySet)
 {
     this.paritySet = paritySet;
       config = paritySet.Config;
       SetProperties();
 }