Exemplo n.º 1
0
 private void HandleInitialized(object sender, EventArgs args)
 {
     if (SingleInstance.AlreadyRunning())
     {
         MessageWindow.ShowError(null, "Already running", "Another instance of disParity is already running");
         Close();
     }
 }
Exemplo n.º 2
0
 protected override void OnStartup(StartupEventArgs e)
 {
     base.OnStartup(e);
     {
         DispatcherUnhandledException += App_DispatcherUnhandledException;
     }
     if (SingleInstance.AlreadyRunning())
     {
         Current.Shutdown(); // Just shutdown the current application,if any instance found.
     }
     AppMan.App.Initialize();
 }
Exemplo n.º 3
0
        public static int Main(params string[] args)
        {
            ServiceBaseX sbx = null;

            ServiceBaseX.dtStartProcess = DateTime.Now;

            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.UnhandledException += new UnhandledExceptionEventHandler(ProcessHandler);

            try
            {
                //check if process restarts
                bool bRestart = false;

                //check on two arguments
                if (args.Length == 2)
                {
                    args[1].ToLower().EndsWith("restart");
                }

                if (SingleInstance.AlreadyRunning("Global\\" + System.Diagnostics.Process.GetCurrentProcess().ProcessName) && bRestart == false)
                {
                    return(1);
                }

                sbx = new ServiceTCP();

                if (sbx != null)
                {
                    if (args.Length > 0 && args[0].ToLower().StartsWith("console"))
                    {
                        sbx.RunConsole(args);
                    }
                    else
                    {
                        System.ServiceProcess.ServiceBase.Run(sbx);
                    }
                }
            }
            catch (Exception ex)
            {
                if (ServiceBaseX._logger != null)
                {
                    ServiceBaseX._logger.Log(Category.Error, MethodBase.GetCurrentMethod().DeclaringType.Name + "_" + MethodBase.GetCurrentMethod().Name + ": " + ex.Message);
                }
            }
            return(0);
        }
Exemplo n.º 4
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();
            }
        }