Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FormDatabaseMigrate"/> class.
        /// </summary>
        public FormDatabaseMigrate()
        {
            InitializeComponent();

            // ReSharper disable once StringLiteralTypo
            DBLangEngine.DBName = "lang.sqlite";

            if (Utils.ShouldLocalize() != null)
            {
                DBLangEngine.InitializeLanguage("amp.Messages", Utils.ShouldLocalize(), false);
                return; // After localization don't do anything more.
            }

            DBLangEngine.InitializeLanguage("amp.Messages");
        }
Ejemplo n.º 2
0
    static void Main()
    {
        string[] args = Environment.GetCommandLineArgs();

        // not obsolete for the migration to the new settings..
#pragma warning disable 618
        SettingsOld.FromOldSettings(Settings);
#pragma warning restore 618

        Settings.Load(Settings.SettingFileName);

        // wait for the possible install process to finnish..
        VPKSoft.WaitForProcessUtil.WaitForProcess.WaitForProcessArguments(args, 30);

        foreach (var arg in args)
        {
            if (arg.StartsWith("--restoreBackup"))
            {
                var restoreParameters = arg.Split('=');
                if (restoreParameters.Length == 2)
                {
                    if (File.Exists(restoreParameters[1]))
                    {
                        while (AppRunning.CheckIfRunningNoAdd("VPKSoft.amp.sharp#"))
                        {
                            Thread.Sleep(100);
                        }

                        try
                        {
                            using (ZipFile zip = ZipFile.Read(restoreParameters[1]))
                            {
                                zip.ExtractAll(Paths.GetAppSettingsFolder(Misc.AppType.Winforms),
                                               ExtractExistingFileAction.OverwriteSilently);
                            }
                        }
                        catch (Exception ex)
                        {
                            // log the exception..
                            ExceptionLogger.LogError(ex);
                        }
                    }
                }
            }
        }


        Process localizeProcess = Utils.CreateDBLocalizeProcess(Paths.AppInstallDir);
        // localizeProcess..

        if (localizeProcess != null)
        {
            localizeProcess.Start();
            return;
        }

        if (!Debugger.IsAttached)
        {
            ExceptionLogger.Bind(); // bind before any visual objects are created
        }

        ExceptionLogger.ApplicationCrashData += ExceptionLogger_ApplicationCrashData;


        // Save languages
        if (Utils.ShouldLocalize() != null)
        {
            // ReSharper disable once ObjectCreationAsStatement
            new FormMain();
            // ReSharper disable once ObjectCreationAsStatement
            new FormPsycho();
            // ReSharper disable once ObjectCreationAsStatement
            new FormProgressBackground();
            // ReSharper disable once ObjectCreationAsStatement
            new FormAddAlbum();
            // ReSharper disable once ObjectCreationAsStatement
            new FormRename();
            // ReSharper disable once ObjectCreationAsStatement
            new FormQueueSnapshotName();        // 16.10.17
            // ReSharper disable once ObjectCreationAsStatement
            new FormSavedQueues();              // 18.10.17
            // ReSharper disable once ObjectCreationAsStatement
            new FormModifySavedQueue();         // 19.10.17
            // ReSharper disable once ObjectCreationAsStatement
            new FormSettings();                 // 21.10.17
            // ReSharper disable once ObjectCreationAsStatement
            new FormTagInfo();                  // 11.02.18
            // ReSharper disable once ObjectCreationAsStatement
            new FormAlbumNaming();              // 27.10.18
            // ReSharper disable once ObjectCreationAsStatement
            new FormDatabaseUpdatingProgress(); // 27.10.18
            // ReSharper disable once ObjectCreationAsStatement
            new FormHelp();                     // 28.10.18
            // ReSharper disable once ObjectCreationAsStatement
            new FormRandomizePriority();        // 30.10.18
            // ReSharper disable once ObjectCreationAsStatement
            new FormDatabaseMigrate();          // 01.09.19
            // ReSharper disable once ObjectCreationAsStatement
            new FormThemeSettings();

            ExceptionLogger.ApplicationCrashData -= ExceptionLogger_ApplicationCrashData;
            ExceptionLogger.UnBind(); // unbind so the truncate thread is stopped successfully
            return;
        }
        // End save languages

#pragma warning disable 618
        // required for history reasons..
        if (Settings.DbUpdateRequiredLevel < 1)
#pragma warning restore 618
        {
            if (AppRunning.CheckIfRunningNoAdd("VPKSoft.amp.DBUpdate.sharp#"))
            {
                ExceptionLogger.ApplicationCrashData -= ExceptionLogger_ApplicationCrashData;
                ExceptionLogger.UnBind(); // unbind so the truncate thread is stopped successfully
                return;
            }
            DBLangEngine.UseCulture = Settings.Culture; // set the localization value..
            Application.Run(new FormDatabaseUpdatingProgress());
            ExceptionLogger.ApplicationCrashData -= ExceptionLogger_ApplicationCrashData;
            ExceptionLogger.UnBind(); // unbind so the truncate thread is stopped successfully
#pragma warning disable 618
            // required for history reasons..
            Settings.DbUpdateRequiredLevel = 1;
#pragma warning restore 618
            Process.Start(new ProcessStartInfo(Path.Combine(Paths.AppInstallDir, "amp.exe"))); // the database is updated..
            return;
        }

        if (AppRunning.CheckIfRunningNoAdd("VPKSoft.amp.sharp#"))
        {
            ExceptionLogger.LogMessage($"Application is running. Checking for open file requests. The current directory is: '{Environment.CurrentDirectory}'.");
            try
            {
                RpcSelfClient <string> ipcClient = new RpcSelfClient <string>(50671);

                // only send the existing files to the running instance, don't send the executable
                // file name thus the start from 1..
                for (int i = 1; i < args.Length; i++)
                {
                    string file = args[i];

                    ExceptionLogger.LogMessage($"Request file open: '{file}'.");
                    bool exists;

                    if ((exists = File.Exists(file)) ||
                        file == ArgumentNext ||
                        file == ArgumentPrevious ||
                        file == ArgumentPlayPause)
                    {
                        if (exists)
                        {
                            ExceptionLogger.LogMessage($"File exists: '{file}'. Send open request.");
                        }
                        else
                        {
                            file = file.TrimStart('-');
                            file = file[0].ToString().ToUpperInvariant() + file.Substring(1);
                            ExceptionLogger.LogMessage($"Send playback request: '{file}'.");
                        }

                        ipcClient.SendData(file);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionLogger.LogError(ex);
                // just in case something fails with the IPC communication..
            }
            ExceptionLogger.ApplicationCrashData -= ExceptionLogger_ApplicationCrashData;
            ExceptionLogger.UnBind(); // unbind so the truncate thread is stopped successfully..
            return;
        }

        AppRunning.CheckIfRunning("VPKSoft.amp.sharp#");

        // create an IPC server at localhost, the port was randomized in the development phase..
        IpcServer = new RpcSelfHost <string>(50671);

        // subscribe to the IPC event if the application receives a message from another instance of this application..
        IpcServer.MessageReceived += MessageReceived;

        PositionCore.Bind(ApplicationType.WinForms); // attach the PosLib to the application
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        DBLangEngine.UseCulture = Settings.Culture;    // set the localization value..
        Application.Run(new FormMain());
        FormHelp.DisposeSingleton();                   // release the help form if any..
        PositionCore.UnBind(ApplicationType.WinForms); // release the event handlers used by the PosLib and save the default data

        // unsubscribe the IpcClientServer MessageReceived event handler..
        IpcServer.MessageReceived -= MessageReceived;
        IpcServer.Dispose();

        ExceptionLogger.ApplicationCrashData -= ExceptionLogger_ApplicationCrashData;
        ExceptionLogger.UnBind(); // unbind so the truncate thread is stopped successfully
        AppRunning.DisposeMutexByName("VPKSoft.amp.sharp#");

        // run a possible software (as of the time of the writing the software is this one.)..
        if (File.Exists(RunProgramOnExit))
        {
            Process.Start(RunProgramOnExit, RunProgramOnExitArguments);
        }
        else if (FormMain.RestartRequired)
        {
            Process.Start(Application.ExecutablePath);
        }
    }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FormScript"/> class.
        /// </summary>
        public FormScript()
        {
            // Add this form to be positioned..
            PositionForms.Add(this);

            // add positioning..
            PositionCore.Bind(ApplicationType.WinForms);

            InitializeComponent();

            DBLangEngine.DBName = "lang.sqlite"; // Do the VPKSoft.LangLib == translation..

            if (Utils.ShouldLocalize() != null)
            {
                DBLangEngine.InitializeLanguage("ScriptNotepad.Localization.Messages", Utils.ShouldLocalize(), false);
                return; // After localization don't do anything more..
            }

            suspendChangedEvent = true; // suspend the event handler as the contents of the script is about to change..

            // initialize the language/localization database..
            DBLangEngine.InitializeLanguage("ScriptNotepad.Localization.Messages");

            // localize the script type default names..
            defaultNameScriptTemplateText =
                DBLangEngine.GetMessage("msgDefaultScriptSnippetText", "A text script snippet|As in a script for manipulating Scintilla contents as text");

            defaultNameScriptTemplateLines =
                DBLangEngine.GetMessage("msgDefaultScriptSnippetLines", "A line script snippet|As in a script for manipulating Scintilla contents as lines");

            // localize the currently supported script types..
            tsbComboScriptType.Items.Clear();
            tsbComboScriptType.Items.Add(
                DBLangEngine.GetMessage("msgScriptTypeText", "Script text|As in the C# script type should be handling the Scintilla's contents as text")
                );

            tsbComboScriptType.Items.Add(
                DBLangEngine.GetMessage("msgScriptTypeLines", "Script lines|As in the C# script type should be handling the Scintilla's contents as lines")
                );

            tsbComboScriptType.SelectedItem =
                DBLangEngine.GetMessage("msgScriptTypeText", "Script text|As in the C# script type should be handling the Scintilla's contents as text");

            // set the default script for manipulating text..
            scintillaScript.Text = scriptRunnerText.CSharpScriptBase;

            // set the text for the default script snippet..
            tstScriptName.Text = defaultNameScriptTemplateText;

            CreateNewCodeSnippet(); // create a new CODE_SNIPPETS class instance..

            // set the lexer as C#..
            ScintillaLexers.CreateLexer(scintillaScript, LexerType.Cs);

            // highlight the braces..
            SetBraceHighlights();

            suspendChangedEvent = false; // "resume" the event handler..

            // track the instances of this form so the changes can be delegated to each other..
            FormScriptInstances.Add(this);
        }