Beispiel #1
0
        public static void Initialize(Action <string> msg)    // called from EDDApplicationContext to initialize config and dbs
        {
            Thread.CurrentThread.Name = "EDD Main Thread";
            msg.Invoke("Checking Config");

            string logpath = EDDOptions.Instance.LogAppDirectory();

            BaseUtils.LogClean.DeleteOldLogFiles(logpath, "*.hlog", 2, 256);        // Remove hlogs faster
            BaseUtils.LogClean.DeleteOldLogFiles(logpath, "*.log", 10, 256);

            if (!Debugger.IsAttached || EDDOptions.Instance.TraceLog != null)
            {
                TraceLog.RedirectTrace(logpath, EDDOptions.Instance.TraceLog);
            }

            if (!Debugger.IsAttached || EDDOptions.Instance.LogExceptions)
            {
                ExceptionCatcher.RedirectExceptions(Properties.Resources.URLProjectFeedback);
            }

            if (EDDOptions.Instance.LogExceptions)
            {
                FirstChanceExceptionCatcher.RegisterFirstChanceExceptionHandler();
            }

            msg.Invoke("Checking Databases");

            Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Initializing database");

            UserDatabase.Instance.Start("UserDB");
            SystemsDatabase.Instance.Start("SystemDB");
            UserDatabase.Instance.Initialize();
            SystemsDatabase.Instance.Initialize();

            Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Database initialization complete");

            HttpCom.LogPath = logpath;

            Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Init config finished");

            Trace.WriteLine($"*** Elite Dangerous Discovery Initializing - {EDDOptions.Instance.VersionDisplayString}, Platform: {Environment.OSVersion.Platform.ToString()}");

            GlobalBookMarkList.LoadBookmarks();
            GlobalCaptainsLogList.LoadLog();

            msg.Invoke("Loading Icons");
            Icons.IconSet.ResetIcons();     // start with a clean slate loaded up from default icons

            msg.Invoke("Loading Configuration");
            EDDConfig.Instance.Update(false);
            EDDProfiles.Instance.LoadProfiles(EDDOptions.Instance.Profile);

            string path = EDDOptions.Instance.IconsPath ?? System.IO.Path.Combine(EDDOptions.Instance.IconsAppDirectory(), "*.zip");

            Icons.IconSet.LoadIconPack(path, EDDOptions.Instance.AppDataDirectory, EDDOptions.ExeDirectory());
        }
        public bool WebServerControl(bool start)        // false if an error occurs
        {
            if (WebServer.Running)
            {
                WebServer.Stop();
            }

            if (start)
            {
                WebServer.Port = EDDConfig.Instance.WebServerPort;

                string servefrom;
                bool   valid;

                if (EDDOptions.Instance.WebServerFolder != null)
                {
                    servefrom = EDDOptions.Instance.WebServerFolder;
                    valid     = Directory.Exists(servefrom);
                }
                else
                {
                    servefrom = Path.Combine(EDDOptions.ExeDirectory(), "eddwebsite.zip");
                    valid     = File.Exists(servefrom);
                }

                if (valid)
                {
                    System.Diagnostics.Debug.WriteLine("Serve from " + servefrom + " on port " + EDDConfig.Instance.WebServerPort);

                    if (WebServer.Start(servefrom))   // may fail due to some security reasons
                    {
                        Controller.LogLine("Web server enabled".T(EDTx.EDDiscoveryForm_WSE));
                    }
                    else
                    {
                        Controller.LogLineHighlight("Web server failed to start".T(EDTx.EDDiscoveryForm_WSF));
                        return(false);
                    }
                }
                else
                {
                    Controller.LogLineHighlight("Web server disabled due to incorrect folder or missing zip file".T(EDTx.EDDiscoveryForm_WSERR));
                }
            }
            else
            {
                Controller.LogLine("*** Web server is disabled ***".T(EDTx.EDDiscoveryForm_WSD));
            }

            return(true);
        }
Beispiel #3
0
        public static void Initialize(Action <string> msg)    // called from EDDApplicationContext to initialize config and dbs
        {
            msg.Invoke("Checking Config");

            EDDOptions.Instance.Init();

            string logpath = EDDOptions.Instance.LogAppDirectory();

            BaseUtils.LogClean.DeleteOldLogFiles(logpath, "*.hlog", 2, 256);        // Remove hlogs faster
            BaseUtils.LogClean.DeleteOldLogFiles(logpath, "*.log", 10, 256);

            if (!Debugger.IsAttached || EDDOptions.Instance.TraceLog != null)
            {
                TraceLog.RedirectTrace(logpath, EDDOptions.Instance.TraceLog);
            }

            if (!Debugger.IsAttached || EDDOptions.Instance.LogExceptions)
            {
                ExceptionCatcher.RedirectExceptions(Properties.Resources.URLProjectFeedback);
            }

            if (EDDOptions.Instance.LogExceptions)
            {
                FirstChanceExceptionCatcher.RegisterFirstChanceExceptionHandler();
            }

            HttpCom.LogPath = logpath;

            SQLiteConnectionUser.EarlyReadRegister();

            Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Init config finished");

            Trace.WriteLine($"*** Elite Dangerous Discovery Initializing - {EDDOptions.Instance.VersionDisplayString}, Platform: {Environment.OSVersion.Platform.ToString()}");

            msg.Invoke("Scanning Memory Banks");
            InitializeDatabases();

            GlobalBookMarkList.LoadBookmarks();

            msg.Invoke("Locating Crew Members");
            EDDConfig.Instance.Update(false);
            EDDProfiles.Instance.LoadProfiles();

            msg.Invoke("Decoding Symbols");
            Icons.IconSet.ResetIcons();     // start with a clean slate loaded up from default icons

            string path = EDDOptions.Instance.IconsPath ?? (EDDOptions.Instance.IconsAppDirectory() + "\\*.zip");

            Icons.IconSet.LoadIconPack(path, EDDOptions.Instance.AppDataDirectory, EDDOptions.ExeDirectory());
        }
        // Return whichever form should initially be displayed; normally SplashForm, but maybe SafeModeForm
        private static Form StartupForm()
        {                                                   // Really just a workaround for the clumsy terniary operator if constructing new but different things.
            bool insafemode = EDDOptions.Instance.SafeMode; // force reading of options, pick up safe mode option

            // check some basic things can be reached before we start

            string dberror = "Check status of the drive/share" + Environment.NewLine +
                             "Check options.txt and dboptions.txt for correctness in " + EDDOptions.Instance.AppDataDirectory + Environment.NewLine +
                             "Or use safemode reset DB to remove dboptions.txt " + Environment.NewLine +
                             "and go back to using the standard c: location";
            string apperror = "Check status of the drive/share" + Environment.NewLine +
                              "Also check options.txt is correct in your " + EDDOptions.ExeDirectory() + " folder";
            string sysdbdir  = Path.GetDirectoryName(EDDOptions.Instance.SystemDatabasePath);
            string userdbdir = Path.GetDirectoryName(EDDOptions.Instance.UserDatabasePath);

            if (!Directory.Exists(EDDOptions.Instance.AppDataDirectory))
            {
                System.Windows.Forms.MessageBox.Show("Error: App Data Directory is inaccessible at " + EDDOptions.Instance.AppDataDirectory + Environment.NewLine + Environment.NewLine + apperror,
                                                     "Application Folder inaccessible", System.Windows.Forms.MessageBoxButtons.OK);
                Environment.Exit(1);
            }
            else if (!BaseUtils.FileHelpers.VerifyWriteToDirectory(EDDOptions.Instance.AppDataDirectory))
            {
                System.Windows.Forms.MessageBox.Show("Error: App Data Directory is not writable at " + EDDOptions.Instance.AppDataDirectory + Environment.NewLine + Environment.NewLine + apperror,
                                                     "Application Folder not writable", System.Windows.Forms.MessageBoxButtons.OK);
                Environment.Exit(1);
            }
            else if (!Directory.Exists(sysdbdir))
            {
                System.Windows.Forms.MessageBox.Show("Error: Systems database is inaccessible at " + EDDOptions.Instance.SystemDatabasePath + Environment.NewLine + Environment.NewLine + dberror,
                                                     "Systems DB inaccessible", System.Windows.Forms.MessageBoxButtons.OK);
                insafemode = true;
            }
            else if (!BaseUtils.FileHelpers.VerifyWriteToDirectory(sysdbdir))
            {
                System.Windows.Forms.MessageBox.Show("Error: Systems database folder is not writable at " + sysdbdir + Environment.NewLine + Environment.NewLine + dberror,
                                                     "Systems DB not writeable", System.Windows.Forms.MessageBoxButtons.OK);
                insafemode = true;
            }
            else if (!Directory.Exists(userdbdir))
            {
                System.Windows.Forms.MessageBox.Show("Error: User database is inaccessible at " + EDDOptions.Instance.UserDatabasePath + Environment.NewLine + Environment.NewLine + dberror,
                                                     "User DB inaccessible", System.Windows.Forms.MessageBoxButtons.OK);
                insafemode = true;
            }
            else if (!BaseUtils.FileHelpers.VerifyWriteToDirectory(userdbdir))
            {
                System.Windows.Forms.MessageBox.Show("Error: User database folder is not writable at " + sysdbdir + Environment.NewLine + Environment.NewLine + dberror,
                                                     "User DB not writeable", System.Windows.Forms.MessageBoxButtons.OK);
                insafemode = true;
            }

            if (Control.ModifierKeys.HasFlag(Keys.Shift) || insafemode)
            {
                return(new SafeModeForm());
            }
            else
            {
                return(new SplashForm());
            }
        }
Beispiel #5
0
        public static void Initialize(Action <string> msg)    // called from EDDApplicationContext to initialize config and dbs
        {
            Thread.CurrentThread.Name = "EDD Main Thread";
            msg.Invoke("Checking Config");

            string logpath = EDDOptions.Instance.LogAppDirectory();

            BaseUtils.LogClean.DeleteOldLogFiles(logpath, "*.hlog", 2, 256);        // Remove hlogs faster
            BaseUtils.LogClean.DeleteOldLogFiles(logpath, "*.log", 10, 256);

            if (!Debugger.IsAttached || EDDOptions.Instance.TraceLog != null)
            {
                TraceLog.RedirectTrace(logpath, EDDOptions.Instance.TraceLog);
            }

            if (!Debugger.IsAttached || EDDOptions.Instance.LogExceptions)
            {
                ExceptionCatcher.RedirectExceptions(Properties.Resources.URLProjectFeedback);
            }

            if (EDDOptions.Instance.LogExceptions)
            {
                FirstChanceExceptionCatcher.RegisterFirstChanceExceptionHandler();
            }

            if (EDDOptions.Instance.BackgroundPriority)
            {
                Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.Idle;
            }
            else if (EDDOptions.Instance.LowPriority)
            {
                Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.BelowNormal;
            }

            if (EDDOptions.Instance.ForceTLS12)
            {
                System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls11;
            }

            msg.Invoke("Checking Databases");

            Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Initializing database");

            UserDatabase.Instance.Start("UserDB");
            SystemsDatabase.Instance.Start("SystemDB");
            UserDatabase.Instance.Initialize();
            SystemsDatabase.Instance.Initialize();

            Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Database initialization complete");

            HttpCom.LogPath = logpath;

            Trace.WriteLine(BaseUtils.AppTicks.TickCountLap() + " Init config finished");

            Trace.WriteLine($"*** Elite Dangerous Discovery Initializing - {EDDOptions.Instance.VersionDisplayString}, Platform: {Environment.OSVersion.Platform.ToString()}");

            GlobalBookMarkList.LoadBookmarks();
            GlobalCaptainsLogList.LoadLog();

            msg.Invoke("Loading Icons");
            EDDiscovery.Icons.ForceInclusion.Include();      // Force the assembly into the project by a empty call
            BaseUtils.Icons.IconSet.CreateSingleton();
            System.Reflection.Assembly iconasm = BaseUtils.ResourceHelpers.GetAssemblyByName("EDDiscovery.Icons");
            BaseUtils.Icons.IconSet.Instance.LoadIconsFromAssembly(iconasm);
            BaseUtils.Icons.IconSet.Instance.AddAlias("settings", "Controls.Main.Tools.Settings");             // from use by action system..
            BaseUtils.Icons.IconSet.Instance.AddAlias("missioncompleted", "Journal.MissionCompleted");
            BaseUtils.Icons.IconSet.Instance.AddAlias("speaker", "Legacy.speaker");
            BaseUtils.Icons.IconSet.Instance.AddAlias("Default", "Legacy.star");        // MUST be present

            msg.Invoke("Loading Configuration");
            EDDConfig.Instance.Update(false);
            EDDProfiles.Instance.LoadProfiles(EDDOptions.Instance.Profile);

            string path = EDDOptions.Instance.IconsPath ?? System.IO.Path.Combine(EDDOptions.Instance.IconsAppDirectory(), "*.zip");

            BaseUtils.Icons.IconSet.Instance.LoadIconPack(path, EDDOptions.Instance.AppDataDirectory, EDDOptions.ExeDirectory());
        }