Example #1
0
        private static void Main(string[] args)
        {
            try
            {
                if ((args.Length == 1) && (args[0] == "start"))		// Used to start application during install
                {
                    ProcessStartInfo psi = new ProcessStartInfo
                    {
                        FileName = Application.ExecutablePath,
                        UseShellExecute = false,
                        WorkingDirectory = Path.GetDirectoryName (Application.ExecutablePath)
                    };
                    Process.Start (psi);
                    return;
                }

                const string projectName = "scm-notifier";
                const string directoryName = projectName;
                const string iniFileName = projectName + ".ini";
                string appPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                string configPath = Path.Combine(appPath, directoryName);
                string iniPath = Path.Combine(appPath, directoryName + @"\" + iniFileName);

                if (!File.Exists(iniPath)) {
                    if (!File.Exists(configPath))
                        Directory.CreateDirectory(configPath);

                    // migrate from old config file
                    string oldPath = Path.Combine(appPath, "SCM_Notifier.ini");
                    if (File.Exists(oldPath)) {
                        File.Copy(oldPath, iniPath);
                        File.Delete(oldPath);
                    }
                }

                Config.Init(iniPath);

                if (!Config.IsSettingsOK())
                    if (new SettingsForm().ShowDialog() != DialogResult.OK)
                        return;

                MainForm form = new MainForm();

                Thread.CurrentThread.Name = "Main";
                Application.ThreadException += OnThreadException;
                Application.Run (form);

                lock (form)
                {
                    if (statusThread != null)
                        statusThread.Abort();
                }
            }
            catch (Exception e)
            {
                FatalError (e);
            }
        }
Example #2
0
        private static void Main(string[] args)
        {
            try
            {
                if ((args.Length == 1) && (args[0] == "start"))		// Used to start application during install
                {
                    ProcessStartInfo psi = new ProcessStartInfo
                    {
                        FileName = Application.ExecutablePath,
                        UseShellExecute = false,
                        WorkingDirectory = Path.GetDirectoryName (Application.ExecutablePath)
                    };
                    Process.Start (psi);
                    return;
                }

                const string projectName = "scm-notifier";
                const string directoryName = projectName;
                const string iniFileName = projectName + ".ini";
                if (File.Exists (iniFileName))
                    Config.Init (iniFileName);
                else
                {
                    // MW: Ensure INI file is created in subdirectory of AppData folder
                    if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), directoryName)))
                        Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), directoryName));

                    Config.Init(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), directoryName + @"\" + iniFileName));
                }

                if (!Config.IsSettingsOK())
                    if (new SettingsForm().ShowDialog() != DialogResult.OK)
                        return;

                MainForm form = new MainForm();

                Thread.CurrentThread.Name = "Main";
                Application.ThreadException += OnThreadException;
                Application.Run (form);

                lock (form)
                {
                    if (statusThread != null)
                        statusThread.Abort();
                }
            }
            catch (Exception e)
            {
                FatalError (e);
            }
        }