Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            m_WorkingDirectory = Environment.CurrentDirectory;

            bool runSelfUpdateTest = false;

            string            exeUpdateFileName = null;
            CommandLineReader reader            = new CommandLineReader(args);

            while (reader.Read())
            {
                if (String.Equals(reader.CurrentArgument, "-delete", StringComparison.InvariantCultureIgnoreCase))
                {
                    reader.TryReadNextAsString(out exeUpdateFileName);
                }
                else if (String.Equals(reader.CurrentArgument, "-selfupdatetest", StringComparison.InvariantCultureIgnoreCase))
                {
                    runSelfUpdateTest = true;
                }
            }

            if (runSelfUpdateTest)
            {
                RunSelfUpdateTest();
                return;
            }

            try
            {
                // Delete Self-Update Exe
                if (String.IsNullOrEmpty(exeUpdateFileName) == false &&
                    File.Exists(exeUpdateFileName))
                // && String.Equals(Path.GetFullPath(Path.GetTempPath()), Path.GetFullPath(Path.GetDirectoryName(exeUpdateFileName)), StringComparison.InvariantCultureIgnoreCase))
                {
                    int counter = 0;
                    while (true)
                    {
                        counter++;
                        if (counter > 30)
                        {
                            break;
                        }

                        try
                        {
                            File.Delete(exeUpdateFileName);
                            break;
                        }
                        catch { }
                        Thread.Sleep(100);
                    }
                }
            }
            catch (Exception e)
            {
                // Just logging, no messages here
                LogException(e);
            }

            try
            {
                InitializeConfiguration();
            }
            catch (Exception e)
            {
                MessageBox.Show("Error on reading configuration.\nDetails: " + e.Message, Title + " - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            string CurrentDir = Directory.GetCurrentDirectory();

            // Go down a dir when looking for the files

            string[] Dirs = CurrentDir.Split('\\');

            // If we are in bin do this
            if (Dirs[Dirs.Length - 1] == "bin")
            {
                Directory.SetCurrentDirectory(Directory.GetParent(CurrentDir).FullName);
            }

            Application.Run(new FormMain());

            Directory.SetCurrentDirectory(CurrentDir);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            m_WorkingDirectory = Environment.CurrentDirectory;

            bool runSelfUpdateTest = false;

            string exeUpdateFileName = null;
            CommandLineReader reader = new CommandLineReader(args);
            while (reader.Read())
            {
                if (String.Equals(reader.CurrentArgument, "-delete", StringComparison.InvariantCultureIgnoreCase))
                {
                    reader.TryReadNextAsString(out exeUpdateFileName);
                }
                else if (String.Equals(reader.CurrentArgument, "-selfupdatetest", StringComparison.InvariantCultureIgnoreCase))
                {
                    runSelfUpdateTest = true;
                }
            }

            if (runSelfUpdateTest)
            {
                RunSelfUpdateTest();
                return;
            }

            try
            {
                // Delete Self-Update Exe
                if (String.IsNullOrEmpty(exeUpdateFileName) == false &&
                    File.Exists(exeUpdateFileName))
                    // && String.Equals(Path.GetFullPath(Path.GetTempPath()), Path.GetFullPath(Path.GetDirectoryName(exeUpdateFileName)), StringComparison.InvariantCultureIgnoreCase))
                {
                    int counter = 0;
                    while (true)
                    {
                        counter++;
                        if (counter > 30) break;

                        try
                        {
                            File.Delete(exeUpdateFileName);
                            break;
                        }
                        catch { }
                        Thread.Sleep(100);
                    }
                }
            }
            catch (Exception e)
            {
                // Just logging, no messages here
                LogException(e);
            }

            try
            {
                InitializeConfiguration();
            }
            catch (Exception e)
            {
                MessageBox.Show("Error on reading configuration.\nDetails: " + e.Message, Title + " - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            string CurrentDir = Directory.GetCurrentDirectory();
            // Go down a dir when looking for the files

            string[] Dirs = CurrentDir.Split('\\');

            // If we are in bin do this
            if (Dirs[Dirs.Length - 1] == "bin")
            {
                Directory.SetCurrentDirectory(Directory.GetParent(CurrentDir).FullName);
            }

            Application.Run(new FormMain());

            Directory.SetCurrentDirectory(CurrentDir);
        }