예제 #1
0
        public static OptionsControl Load(out bool ProgramIsNew)
        {
            try
            {
                if (File.Exists(Paths.GetOptionsFilePath()))
                {
                    object deserializedOptionsObj;
                    var    formatter = new BinaryFormatter();
                    using (var fileStream = new FileStream(Paths.GetOptionsFilePath(), FileMode.Open, FileAccess.Read,
                                                           FileShare.ReadWrite))
                    {
                        deserializedOptionsObj = formatter.Deserialize(fileStream);
                    }

                    var oc = (OptionsControl)deserializedOptionsObj;
                    oc.FillNullToDefaults();
                    ProgramIsNew = false;
                    return(oc);
                }
            }
            catch (Exception)
            {
            }

            var oco = new OptionsControl();

            oco.ReCreateCryptoKey();
#if DEBUG
            ProgramIsNew = false;
#else
            ProgramIsNew = true;
#endif
            return(oco);
        }
예제 #2
0
        public static void Main(string[] args)
        {
#if DEBUG
            System.Diagnostics.PresentationTraceSources.DataBindingSource.Switch.Level =
                System.Diagnostics.SourceLevels.Critical;
#endif

            using (new Mutex(true, "SPCodeGlobalMutex", out var mutexReserved))
            {
                if (mutexReserved)
                {
#if !DEBUG
                    try
                    {
#endif

                    var splashScreen = new SplashScreen("Resources/Icon256x.png");
                    splashScreen.Show(false, true);
                    Environment.CurrentDirectory =
                        Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ??
                        throw new NullReferenceException();
#if !DEBUG
                    ProfileOptimization.SetProfileRoot(Environment.CurrentDirectory);
                    ProfileOptimization.StartProfile("Startup.Profile");
#endif
                    _IsLocalInstallation = Paths.IsLocalInstallation();
                    UpdateStatus         = new UpdateInfo();
                    OptionsObject        = OptionsControlIOObject.Load(out var ProgramIsNew);

                    if (OptionsObject.Program_DiscordPresence)
                    {
                        // Init Discord RPC
                        discordClient.Initialize();

                        // Set default presence
                        discordClient.SetPresence(new RichPresence
                        {
                            State      = "Idle",
                            Timestamps = discordTime,
                            Assets     = new Assets
                            {
                                LargeImageKey = "immagine"
                            }
                        });
                    }


                    Translations = new TranslationProvider();
                    Translations.LoadLanguage(OptionsObject.Language, true);
                    foreach (var arg in args)
                    {
                        if (arg.ToLowerInvariant() == "-rcck") //ReCreateCryptoKey
                        {
                            OptionsObject.ReCreateCryptoKey();
                            MakeRCCKAlert();
                        }
                    }

                    Configs = ConfigLoader.Load();
                    for (var i = 0; i < Configs.Length; ++i)
                    {
                        if (Configs[i].Name == OptionsObject.Program_SelectedConfig)
                        {
                            SelectedConfig = i;
                            break;
                        }
                    }

                    if (!OptionsObject.Program_UseHardwareAcceleration)
                    {
                        RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
                    }
#if !DEBUG
                    if (ProgramIsNew)
                    {
                        if (Translations.AvailableLanguageIDs.Length > 0)
                        {
                            splashScreen.Close(new TimeSpan(0, 0, 1));
                            var languageWindow =
                                new LanguageChooserWindow(Translations.AvailableLanguageIDs,
                                                          Translations.AvailableLanguages);
                            languageWindow.ShowDialog();
                            var potentialSelectedLanguageID = languageWindow.SelectedID;
                            if (!string.IsNullOrWhiteSpace(potentialSelectedLanguageID))
                            {
                                OptionsObject.Language = potentialSelectedLanguageID;
                                Translations.LoadLanguage(potentialSelectedLanguageID);
                            }

                            splashScreen.Show(false, true);
                        }
                    }
#endif
                    MainWindow = new MainWindow(splashScreen);
                    var pipeServer = new PipeInteropServer(MainWindow);
                    pipeServer.Start();
#if !DEBUG
                }
                catch (Exception e)
                {
                    File.WriteAllText($@"{Paths.GetCrashLogDirectory()}\CRASH_{Environment.TickCount}.txt",
                                      BuildExceptionString(e, "SPCODE LOADING"));
                    MessageBox.Show(
                        "An error occured." + Environment.NewLine +
                        $"A crash report was written in {Paths.GetCrashLogDirectory()}",
                        "Error",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                    Environment.Exit(Environment.ExitCode);
                }
#endif
                    var app = new Application();
#if !DEBUG
                    try
                    {
                        if (OptionsObject.Program_CheckForUpdates)
                        {
                            Task.Run(UpdateCheck.Check);
                        }
#endif
                    app.Startup += App_Startup;
                    app.Run(MainWindow);
                    OptionsControlIOObject.Save();
#if !DEBUG
                }
                catch (Exception e)
                {
                    File.WriteAllText($@"{Paths.GetCrashLogDirectory()}\CRASH_{Environment.TickCount}.txt",
                                      BuildExceptionString(e, "SPCODE MAIN"));
                    MessageBox.Show(
                        "An error occured." + Environment.NewLine +
                        $"A crash report was written in {Paths.GetCrashLogDirectory()}",
                        "Error",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                    Environment.Exit(Environment.ExitCode);
                }
#endif
                }
                else
                {
                    try
                    {
                        var sBuilder   = new StringBuilder();
                        var addedFiles = false;
                        for (var i = 0; i < args.Length; ++i)
                        {
                            if (!string.IsNullOrWhiteSpace(args[i]))
                            {
                                var fInfo = new FileInfo(args[i]);
                                if (fInfo.Exists)
                                {
                                    var ext = fInfo.Extension.ToLowerInvariant().Trim('.', ' ');
                                    if (ext == "sp" || ext == "inc" || ext == "txt" || ext == "smx")
                                    {
                                        addedFiles = true;
                                        sBuilder.Append(fInfo.FullName);
                                        if (i + 1 != args.Length)
                                        {
                                            sBuilder.Append("|");
                                        }
                                    }
                                }
                            }
                        }

                        if (addedFiles)
                        {
                            PipeInteropClient.ConnectToMasterPipeAndSendData(sBuilder.ToString());
                        }
                    }
                    catch (Exception)
                    {
                        // ignored
                    } //dont f**k the user up with irrelevant data
                }
            }
        }