Example #1
0
        public static void Main(string[] args)
        {
            m_args = args;
            Project project;

            try
            {
                // used to be static constructors; moved here to provide better diagnostics on failure:
                project = new LibSys.Project();
                new LibSys.StatusBar(); // writes first line in trace file
                new TerraserverCache();

                try
                {
                    string          assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
                    FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assemblyLocation);
                    string          svi = fvi.FileMajorPart + "." + fvi.FileMinorPart + "." + fvi.FileBuildPart + "." + fvi.FilePrivatePart;
                    LibSys.StatusBar.Trace("Assembly location " + assemblyLocation + "    Version " + svi);

                    // Framework 2.0 code:
                    foreach (DriveInfo di in DriveInfo.GetDrives())
                    {
                        string driveLetter = di.Name.Substring(0, 1);

                        LibSys.StatusBar.Trace(String.Format("Drive {0}   type: {1}   state: {2}", di.Name, di.DriveType, di.IsReady ? "ready" : "offline"));
                        if (di.IsReady == true)
                        {
                            LibSys.StatusBar.Trace(String.Format("   Volume label: {0}  File system: {1}", di.VolumeLabel, di.DriveFormat));
                            LibSys.StatusBar.Trace(String.Format(
                                                       "   Available space to current user: {0, 10} MB    Total available space: {1, 10} MB     Total size of drive: {2, 10} MB",
                                                       di.AvailableFreeSpace / 1000000, di.TotalFreeSpace / 1000000, di.TotalSize / 1000000));
                            if (assemblyLocation.ToLower().StartsWith(driveLetter.ToLower()))
                            {
                                LibSys.StatusBar.Trace("   " + Project.PROGRAM_NAME_HUMAN + " installed on this drive");
                            }
                        }
                    }


                    // pre-Framework 2.0 code:

                    /*
                     * string[] str = Directory.GetLogicalDrives();
                     *                  LibSys.StatusBar.Trace("Possible map storage - available drives are:");
                     *                  for(int i=0; i < str.Length ;i++)
                     *                  {
                     *                          string driveLetter = str[i];
                     *                          try
                     *                          {
                     *                                  DirectoryInfo di = new DirectoryInfo(driveLetter);
                     *                                  string strAttr = "disconnected";
                     *                                  if((int)di.Attributes > 0)
                     *                                  {
                     *                                          strAttr = di.Attributes.ToString();
                     *                                  }
                     *                                  if(assemblyLocation.ToLower().StartsWith(driveLetter.ToLower().Substring(0,2)))
                     *                                  {
                     *                                          strAttr += "  (" + Project.PROGRAM_NAME_HUMAN + " installed on this drive)";
                     *                                  }
                     *                                  LibSys.StatusBar.Trace(driveLetter + " - " + strAttr);
                     *                          }
                     *                          catch(Exception exc)
                     *                          {
                     *                                  LibSys.StatusBar.Error(driveLetter + " - " + exc.Message.Replace("\n"," ").Trim());
                     *                          }
                     *                  }
                     */
                }
                catch (Exception exc)
                {
                    LibSys.StatusBar.Error(exc.ToString());
                }

                LibSys.StatusBar.WriteLine("Culture at start: " + Thread.CurrentThread.CurrentCulture + " (" + Thread.CurrentThread.CurrentCulture.DisplayName + ")  UseUserOverride=" + Thread.CurrentThread.CurrentCulture.UseUserOverride);
                Thread.CurrentThread.CurrentCulture   = new CultureInfo("en-US", false);
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US", false);
                LibSys.StatusBar.WriteLine("Set new culture: " + Thread.CurrentThread.CurrentCulture + " (" + Thread.CurrentThread.CurrentCulture.DisplayName + ")  UseUserOverride=" + Thread.CurrentThread.CurrentCulture.UseUserOverride);
                new ThreadPool2();
            }
            catch (Exception e)
            {
                string message = "QuakeMap:Main at start: " + e;
                System.Windows.Forms.MessageBox.Show(null, message, Project.PROGRAM_NAME_HUMAN,
                                                     System.Windows.Forms.MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }

            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);

            try
            {
                Thread.CurrentThread.Name = Project.PROGRAM_NAME_HUMAN + " MainForm";
                LibSys.StatusBar.WriteLine("Framework: " + Environment.Version);
                LibSys.StatusBar.TraceVersions();
                LibSys.StatusBar.WriteLine("Application in: " + Application.StartupPath);
                LibSys.StatusBar.WriteLine("    Executable: " + Application.ExecutablePath);
                // the following fails after obfuscating, packing and installing:
                //LibSys.StatusBar.WriteLine("       Data in: " + Application.CommonAppDataPath);
                //LibSys.StatusBar.WriteLine("     User path: " + Application.LocalUserAppDataPath);
            }
            catch (Exception e)
            {
                LibSys.StatusBar.WriteLine("Interrupted Main at start: " + e);
            }

            if (CommuninicateToOtherInstance()) // safe to proceed?
            {
                LibSys.StatusBar.WriteLine("Safe to proceed " + DateTime.Now);

                WindowsTiler.MainForm mainForm = new WindowsTiler.MainForm(args);

again:
                try
                {
                    if (!Project.goingDown)
                    {
                        Application.Run(mainForm);
                    }
                }
                catch (Exception e)
                {
                    LibSys.StatusBar.WriteLine("Interrupted Main: " + e);
#if DEBUG
                    Project.ErrorBox(null, "Interrupted Main: " + e);
#endif
                    goto again;
                }
            }
            LibSys.StatusBar.WriteLine("Quitting in QuakeMap.Main " + DateTime.Now);

            Project.Closing();

            LibSys.StatusBar.WriteLine("Exit thread '" + Thread.CurrentThread.Name + "' in QuakeMap.Main " + DateTime.Now);
            Application.Exit();
            Application.ExitThread();
            Environment.Exit(0);
        }
Example #2
0
        public static void Main(string[] args)
        {
            m_args = args;
            Project project;

            try
            {
                // used to be static constructors; moved here to provide better diagnostics on failure:
                project = new LibSys.Project();
                new LibSys.StatusBar();	// writes first line in trace file
                new TerraserverCache();

                try
                {

                    string assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;
                    FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assemblyLocation);
                    string svi = fvi.FileMajorPart + "." + fvi.FileMinorPart + "." + fvi.FileBuildPart + "." + fvi.FilePrivatePart;
                    LibSys.StatusBar.Trace("Assembly location " + assemblyLocation + "    Version " + svi);

                    // Framework 2.0 code:
                    foreach (DriveInfo di in DriveInfo.GetDrives())
                    {
                        string driveLetter = di.Name.Substring(0, 1);

                        LibSys.StatusBar.Trace(String.Format("Drive {0}   type: {1}   state: {2}", di.Name, di.DriveType, di.IsReady ? "ready" : "offline"));
                        if (di.IsReady == true)
                        {
                            LibSys.StatusBar.Trace(String.Format("   Volume label: {0}  File system: {1}", di.VolumeLabel, di.DriveFormat));
                            LibSys.StatusBar.Trace(String.Format(
                                "   Available space to current user: {0, 10} MB    Total available space: {1, 10} MB     Total size of drive: {2, 10} MB",
                                di.AvailableFreeSpace / 1000000, di.TotalFreeSpace / 1000000, di.TotalSize / 1000000));
                            if (assemblyLocation.ToLower().StartsWith(driveLetter.ToLower()))
                            {
                                LibSys.StatusBar.Trace("   " + Project.PROGRAM_NAME_HUMAN + " installed on this drive");
                            }
                        }
                    }

                    // pre-Framework 2.0 code:
                    /*
                    string[] str = Directory.GetLogicalDrives();
                    LibSys.StatusBar.Trace("Possible map storage - available drives are:");
                    for(int i=0; i < str.Length ;i++)
                    {
                        string driveLetter = str[i];
                        try
                        {
                            DirectoryInfo di = new DirectoryInfo(driveLetter);
                            string strAttr = "disconnected";
                            if((int)di.Attributes > 0)
                            {
                                strAttr = di.Attributes.ToString();
                            }
                            if(assemblyLocation.ToLower().StartsWith(driveLetter.ToLower().Substring(0,2)))
                            {
                                strAttr += "  (" + Project.PROGRAM_NAME_HUMAN + " installed on this drive)";
                            }
                            LibSys.StatusBar.Trace(driveLetter + " - " + strAttr);
                        }
                        catch(Exception exc)
                        {
                            LibSys.StatusBar.Error(driveLetter + " - " + exc.Message.Replace("\n"," ").Trim());
                        }
                    }
                    */
                }
                catch (Exception exc)
                {
                    LibSys.StatusBar.Error(exc.ToString());
                }

                LibSys.StatusBar.WriteLine("Culture at start: " + Thread.CurrentThread.CurrentCulture + " (" + Thread.CurrentThread.CurrentCulture.DisplayName + ")  UseUserOverride=" + Thread.CurrentThread.CurrentCulture.UseUserOverride);
                Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", false);
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US", false);
                LibSys.StatusBar.WriteLine("Set new culture: " + Thread.CurrentThread.CurrentCulture + " (" + Thread.CurrentThread.CurrentCulture.DisplayName + ")  UseUserOverride=" + Thread.CurrentThread.CurrentCulture.UseUserOverride);
                new ThreadPool2();
            }
            catch (Exception e)
            {
                string message = "QuakeMap:Main at start: " + e;
                System.Windows.Forms.MessageBox.Show(null, message, Project.PROGRAM_NAME_HUMAN,
                                                        System.Windows.Forms.MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }

            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);

            try
            {
                Thread.CurrentThread.Name = Project.PROGRAM_NAME_HUMAN + " MainForm";
                LibSys.StatusBar.WriteLine("Framework: " + Environment.Version);
                LibSys.StatusBar.TraceVersions();
                LibSys.StatusBar.WriteLine("Application in: " + Application.StartupPath);
                LibSys.StatusBar.WriteLine("    Executable: " + Application.ExecutablePath);
                // the following fails after obfuscating, packing and installing:
                //LibSys.StatusBar.WriteLine("       Data in: " + Application.CommonAppDataPath);
                //LibSys.StatusBar.WriteLine("     User path: " + Application.LocalUserAppDataPath);
            }
            catch (Exception e)
            {
                LibSys.StatusBar.WriteLine("Interrupted Main at start: " + e);
            }

            if (CommuninicateToOtherInstance())	// safe to proceed?
            {
                LibSys.StatusBar.WriteLine("Safe to proceed " + DateTime.Now);

                WindowsTiler.MainForm mainForm = new WindowsTiler.MainForm(args);

            again:
                try
                {
                    if (!Project.goingDown)
                    {
                        Application.Run(mainForm);
                    }
                }
                catch (Exception e)
                {
                    LibSys.StatusBar.WriteLine("Interrupted Main: " + e);
            #if DEBUG
                    Project.ErrorBox(null, "Interrupted Main: " + e);
            #endif
                    goto again;
                }
            }
            LibSys.StatusBar.WriteLine("Quitting in QuakeMap.Main " + DateTime.Now);

            Project.Closing();

            LibSys.StatusBar.WriteLine("Exit thread '" + Thread.CurrentThread.Name + "' in QuakeMap.Main " + DateTime.Now);
            Application.Exit();
            Application.ExitThread();
            Environment.Exit(0);
        }