Example #1
0
		public static void Main()
		{
			// Enable visual styles
			//Application.EnableVisualStyles();
			//Application.DoEvents();		// This must be here to work around a .NET bug
			Application.SetCompatibleTextRenderingDefault(true);
			
			// Set current thread name
			Thread.CurrentThread.Name = "Main Application";
			
			// Application is running
			appmutex = new Mutex(false, "gluon");
			apprunning = true;
			
			// Get a reference to this assembly
			thisasm = Assembly.GetExecutingAssembly();
			Version thisversion = thisasm.GetName().Version;
			
			// Find paths
			Uri localpath = new Uri(Path.GetDirectoryName(thisasm.GetName().CodeBase));
			apppath = Uri.UnescapeDataString(localpath.AbsolutePath);
			temppath = Path.GetTempPath();
			settingspath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Gluon");
			logfile = Path.Combine(settingspath, "Log.txt");
			
			// Make program settings directory if missing
			if(!Directory.Exists(settingspath)) Directory.CreateDirectory(settingspath);
			
			// Remove the previous log file and start logging
			//if(File.Exists(logfile)) File.Delete(logfile);
			General.WriteLogLine("===============================================================================================");
			General.WriteLogLine("Gluon " + thisversion.Major + "." + thisversion.Minor + "." + thisversion.Build + "." + thisversion.Revision + " startup.");
			
			#if HIGH_PRIORITY_PROCESS
				Process thisproc = Process.GetCurrentProcess();
				thisproc.PriorityClass = ProcessPriorityClass.AboveNormal;
			#endif
			Thread thisthread = Thread.CurrentThread;
			thisthread.Priority = ThreadPriority.Highest;

			// Load settings
			settings = new SettingsManager();
			
			#if DEBUG
				if(!settings.LiveEnvironment)
					accessenabled = true;
			#endif

			// Make me a clock
			clock = new Clock();
			
			// Make the power managment
			power = new PowerManager();
			
			// Load sounds
			sounds = new SoundsManager();
			sounds.LoadSounds();

			// If audio is not set to primary device, we must make it so and restart Gluon
			if(!sounds.CheckAudioOutputPrimary())
			{
				sounds.SetAudioOutputPrimary();
				
				// Restart Gluon
				ProcessStartInfo proc = new ProcessStartInfo();
				proc.ErrorDialog = false;
				proc.FileName = Path.Combine(General.AppPath, "Gluon.exe");
				proc.LoadUserProfile = true;
				//proc.UserName = "******";
				proc.UseShellExecute = false;
				proc.WorkingDirectory = General.AppPath;
				Process.Start(proc);
				return;
			}
			
			// Load color palette
			colors = new ColorPalette();
			
			// Load interface images
			images = new InterfaceImageProvider();
			
			// Build images for all color schemes
			colors.SetupDarkScheme();
			images.BuildImages();
			colors.SetupNormalScheme();
			images.BuildImages();

			// Managers
			remote = new RemoteManager();
			display = new DisplayManager();
			pcap = new PCapManager();
			obex = new ObexManager();
			agenda = new AgendaManager();
			notes = new NotesManager();
			groceries = new GroceriesManager();
			db = new DatabaseManager();

			// Load main window
			mainwindow = new MainForm();
			mainwindow.ShowTaggedPanel("loading");
			
			// See LoadingDisplaypanel::Load() for connect/setup stuff
			
			#if CATCH_EXCEPTIONS
					
				// Add exception handlers
				AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
				Application.ThreadException += Application_ThreadException;
			
			#endif
			
			bool failed;
			
			do
			{
				failed = false;
				
				#if CATCH_EXCEPTIONS
				
				try
				{
				
				#endif
					
					// Show main window
					Application.Run(mainwindow);
					
				#if CATCH_EXCEPTIONS
				
				}
				catch(Exception e)
				{
					Application.ExitThread();
					failed = true;
					mainwindow = new MainForm();
					General.ErrorMessage = e.GetType().Name + ": " + e.Message + "\r\n" + e.StackTrace;
					General.WriteLogLine(General.ErrorMessage);
					mainwindow.ShowTaggedPanel("error");
				}
				
				#endif
			}
			while(failed);

			// Clean stuff up
			sounds.SetAudioOutputPrimary();
			display.Dispose();
			obex.Dispose();
			pcap.Dispose();
			db.Dispose();
			remote.Dispose();
		}
Example #2
0
        public static void Main()
        {
            // Enable visual styles
            //Application.EnableVisualStyles();
            //Application.DoEvents();		// This must be here to work around a .NET bug
            Application.SetCompatibleTextRenderingDefault(true);

            // Set current thread name
            Thread.CurrentThread.Name = "Main Application";

            // Application is running
            appmutex   = new Mutex(false, "gluon");
            apprunning = true;

            // Get a reference to this assembly
            thisasm = Assembly.GetExecutingAssembly();
            Version thisversion = thisasm.GetName().Version;

            // Find paths
            Uri localpath = new Uri(Path.GetDirectoryName(thisasm.GetName().CodeBase));

            apppath      = Uri.UnescapeDataString(localpath.AbsolutePath);
            temppath     = Path.GetTempPath();
            settingspath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Gluon");
            logfile      = Path.Combine(settingspath, "Log.txt");

            // Make program settings directory if missing
            if (!Directory.Exists(settingspath))
            {
                Directory.CreateDirectory(settingspath);
            }

            // Remove the previous log file and start logging
            //if(File.Exists(logfile)) File.Delete(logfile);
            General.WriteLogLine("===============================================================================================");
            General.WriteLogLine("Gluon " + thisversion.Major + "." + thisversion.Minor + "." + thisversion.Build + "." + thisversion.Revision + " startup.");

                        #if HIGH_PRIORITY_PROCESS
            Process thisproc = Process.GetCurrentProcess();
            thisproc.PriorityClass = ProcessPriorityClass.AboveNormal;
                        #endif
            Thread thisthread = Thread.CurrentThread;
            thisthread.Priority = ThreadPriority.Highest;

            // Load settings
            settings = new SettingsManager();

                        #if DEBUG
            if (!settings.LiveEnvironment)
            {
                accessenabled = true;
            }
                        #endif

            // Make me a clock
            clock = new Clock();

            // Make the power managment
            power = new PowerManager();

            // Load sounds
            sounds = new SoundsManager();
            sounds.LoadSounds();

            // If audio is not set to primary device, we must make it so and restart Gluon
            if (!sounds.CheckAudioOutputPrimary())
            {
                sounds.SetAudioOutputPrimary();

                // Restart Gluon
                ProcessStartInfo proc = new ProcessStartInfo();
                proc.ErrorDialog     = false;
                proc.FileName        = Path.Combine(General.AppPath, "Gluon.exe");
                proc.LoadUserProfile = true;
                //proc.UserName = "******";
                proc.UseShellExecute  = false;
                proc.WorkingDirectory = General.AppPath;
                Process.Start(proc);
                return;
            }

            // Load color palette
            colors = new ColorPalette();

            // Load interface images
            images = new InterfaceImageProvider();

            // Build images for all color schemes
            colors.SetupDarkScheme();
            images.BuildImages();
            colors.SetupNormalScheme();
            images.BuildImages();

            // Managers
            remote    = new RemoteManager();
            display   = new DisplayManager();
            pcap      = new PCapManager();
            obex      = new ObexManager();
            agenda    = new AgendaManager();
            notes     = new NotesManager();
            groceries = new GroceriesManager();
            db        = new DatabaseManager();

            // Load main window
            mainwindow = new MainForm();
            mainwindow.ShowTaggedPanel("loading");

            // See LoadingDisplaypanel::Load() for connect/setup stuff

                        #if CATCH_EXCEPTIONS
            // Add exception handlers
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            Application.ThreadException += Application_ThreadException;
                        #endif

            bool failed;

            do
            {
                failed = false;

                                #if CATCH_EXCEPTIONS
                try
                {
                                #endif

                // Show main window
                Application.Run(mainwindow);

                                #if CATCH_EXCEPTIONS
            }
            catch (Exception e)
            {
                Application.ExitThread();
                failed               = true;
                mainwindow           = new MainForm();
                General.ErrorMessage = e.GetType().Name + ": " + e.Message + "\r\n" + e.StackTrace;
                General.WriteLogLine(General.ErrorMessage);
                mainwindow.ShowTaggedPanel("error");
            }
                                #endif
            }while(failed);

            // Clean stuff up
            sounds.SetAudioOutputPrimary();
            display.Dispose();
            obex.Dispose();
            pcap.Dispose();
            db.Dispose();
            remote.Dispose();
        }