Exemple #1
0
        public static void Main(string[] args)
        {
            bool InSafe = false;
            bool mutexReserved;
            using (Mutex appMutex = new Mutex(true, "SpeditGlobalMutex", out mutexReserved))
            {
                if (mutexReserved)
                {
#if !DEBUG
                    try
                    {
#endif
                        SplashScreen splashScreen = new SplashScreen("Resources/Icon256x.png");
                        splashScreen.Show(false, true);
                        UpdateStatus = new UpdateInfo();
                        Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                        OptionsObject = OptionsControlIOObject.Load();
                        for (int i = 0; i < args.Length; ++i)
                        {
                            if (args[i].ToLowerInvariant() == "-rcck") //ReCreateCryptoKey
                            {
                                var opt = OptionsObject;
                                OptionsObject.ReCreateCryptoKey();
                                MessageBox.Show("All FTP passwords are now encrypted wrong!" + Environment.NewLine + "You have to replace them!",
                                    "Created new crypto key", MessageBoxButton.OK, MessageBoxImage.Information);
                            }
                            else if (args[i].ToLowerInvariant() == "-safe")
                            {
                                InSafe = true;
                            }
                        }
                        Configs = ConfigLoader.Load();
                        for (int i = 0; i < Configs.Length; ++i)
                        {
                            if (Configs[i].Name == OptionsObject.Program_SelectedConfig)
                            {
                                Program.SelectedConfig = i;
                                break;
                            }
                        }
                        if (!OptionsObject.Program_UseHardwareAcceleration)
                        {
                            RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly;
                        }
                        MainWindow = new MainWindow(splashScreen);
                        PipeInteropServer pipeServer = new PipeInteropServer(MainWindow);
                        pipeServer.Start();
#if !DEBUG
                    }
                    catch (Exception e)
                    {
                        File.WriteAllText("CRASH_" + Environment.TickCount.ToString() + ".txt", BuildExceptionString(e, "SPEDIT LOADING"));
                        MessageBox.Show("An error occured while loading." + Environment.NewLine + "A crash report was written in the editor-directory.",
                            "Error while Loading",
                            MessageBoxButton.OK,
                            MessageBoxImage.Error);
                        Environment.Exit(Environment.ExitCode);
                    }
#endif
                        Application app = new Application();
                        if (InSafe)
                        {
                            try
                            {
#if !DEBUG
                                if (OptionsObject.Program_CheckForUpdates)
                                {
                                    UpdateCheck.Check(true);
                                }
#endif
                                app.Run(MainWindow);
                                OptionsControlIOObject.Save();
                            }
                            catch (Exception e)
                            {
                                File.WriteAllText("CRASH_" + Environment.TickCount.ToString() + ".txt", BuildExceptionString(e, "SPEDIT MAIN"));
                                MessageBox.Show("An error occured." + Environment.NewLine + "A crash report was written in the editor-directory.",
                                    "Error",
                                    MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                                Environment.Exit(Environment.ExitCode);
                            }
                        }
                        else
                        {
#if !DEBUG
                            if (OptionsObject.Program_CheckForUpdates)
                            {
                                UpdateCheck.Check(true);
                            }
#endif
                            app.Run(MainWindow);
                            OptionsControlIOObject.Save();
                        }
                }
                else
                {
                    try
                    {
                        StringBuilder sBuilder = new StringBuilder();
                        bool addedFiles = false;
                        for (int i = 0; i < args.Length; ++i)
                        {
                            if (!string.IsNullOrWhiteSpace(args[i]))
                            {
                                FileInfo fInfo = new FileInfo(args[i]);
                                if (fInfo.Exists)
                                {
                                    string ext = fInfo.Extension.ToLowerInvariant().Trim(new char[] { '.', ' ' });
                                    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) { } //dont f**k the user up with irrelevant data
                }
            }
        }
 private async void Command_Decompile(MainWindow win)
 {
     OpenFileDialog ofd = new OpenFileDialog();
     ofd.Filter = "Sourcepawn Plugins (*.smx)|*.smx";
     ofd.Title = "Select plugin to decompile";
     var result = ofd.ShowDialog();
     if (result.Value)
     {
         if (!string.IsNullOrWhiteSpace(ofd.FileName))
         {
             FileInfo fInfo = new FileInfo(ofd.FileName);
             if (fInfo.Exists)
             {
                 ProgressDialogController task = null;
                 if (win != null)
                 {
                     task = await this.ShowProgressAsync("Decompiling", fInfo.FullName, false, this.MetroDialogOptions);
                     MainWindow.ProcessUITasks();
                 }
                 string destFile = fInfo.FullName + ".sp";
                 File.WriteAllText(destFile, LysisDecompiler.Analyze(fInfo), Encoding.UTF8);
                 TryLoadSourceFile(destFile, true, false);
                 if (task != null)
                 {
                     await task.CloseAsync();
                 }
             }
         }
     }
 }
 public PipeInteropServer(MainWindow window)
 {
     _window = window;
 }