예제 #1
0
 static void Main()
 {
     ExceptionLogger.Bind();
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     Application.Run(new FormMain());
     ExceptionLogger.UnBind();
 }
예제 #2
0
파일: Program.cs 프로젝트: VPKSoft/amp
    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);
        }
    }
예제 #3
0
파일: Program.cs 프로젝트: VPKSoft/vamp
        static void Main()
        {
            string[] args = Environment.GetCommandLineArgs();

            bool runSetting          = false;
            bool runPhotoAlbumEditor = false;

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

            //localizeProcess.

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

            foreach (string arg in args)
            {
                if (arg == "--configure")
                {
                    runSetting = true;
                }

                if (arg == "--photos")
                {
                    runPhotoAlbumEditor = true;
                }
            }

            if (runSetting)
            {
                if (VPKSoft.Utils.AppRunning.CheckIfRunning("vamp#_normal_setting"))
                {
                    return;
                }
                else
                {
                    ExceptionLogger.Bind(1); // bind before any visual objects are created..
                    ExceptionLogger.ApplicationCrash += ExceptionLogger_ApplicationCrash;
                    Settings.InitSettings();
                    DBLangEngine.UseCulture = Settings.Culture; // set the localization value..
                    Application.Run(new FormSettings());
                    ExceptionLogger.UnBind();                   // unbind so the truncate thread is stopped successfully..
                    return;
                }
            }
            if (runPhotoAlbumEditor)
            {
                if (VPKSoft.Utils.AppRunning.CheckIfRunning("vamp#_normal_photos"))
                {
                    return;
                }
                else
                {
                    ExceptionLogger.Bind(2); // bind before any visual objects are created..
                    ExceptionLogger.ApplicationCrash += ExceptionLogger_ApplicationCrash;
                    Settings.InitSettings();
                    DBLangEngine.UseCulture = Settings.Culture; // set the localization value..
                    Application.Run(new FormPhotoAlbumEditor());
                    ExceptionLogger.UnBind();                   // unbind so the truncate thread is stopped successfully..
                    return;
                }
            }
            else
            {
                if (VPKSoft.Utils.AppRunning.CheckIfRunning("vamp#_normal"))
                {
                    return;
                }
            }

            if (Utils.ShouldLocalize() == null)
            {
                FormSplash.ShowFormSplash();
            }

            FormSplash.SetStatus(FormSplash.MsgBindExceptionLogger, 100);
            ExceptionLogger.Bind(); // bind before any visual objects are created
            ExceptionLogger.ApplicationCrash += ExceptionLogger_ApplicationCrash;
            FormSplash.SetStatus(FormSplash.MsgVisualStyles, 0);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            FormSplash.SetStatus(FormSplash.MsgVisualStyles, 100);

            AppDomain.CurrentDomain.AssemblyResolve += Resolver;

            // Save languages
            if (VPKSoft.LangLib.Utils.ShouldLocalize() != null)
            {
                new FormMain();
                new FormPlayer();
                new FormSelectSubtitle();
                new FormDialogSelectFileOrDirectory();
                new FormWebBrowserGecko(string.Empty);
                new FormWebBrowserChromium(string.Empty);
                new FormDialogSelectPlaybackPosition();
                new FormDialogSelectLocation();
                new FormAmpMusicPlayer();
                new FormDialogError();
                new FormDialogSelectCustomContent();
                new FormSplash();
                new FormSettings();
                new FormTMDBLoadProgress();
                new FormPhotoAlbumEditor();
                new FormDialogPhotoAlbumQueryName();
                new FormSelectMovie();
                new FormDialogPhotoAlbumSelectBaseDirectory();
                new FormDialogConfirmQuery();
                ExceptionLogger.UnBind(); // unbind so the truncate thread is stopped successfully..
                return;
            }

            Settings.InitSettings();
            DBLangEngine.UseCulture = Settings.Culture; // set the localization value..

            ExceptionLogger.LogMessage(AppDomain.CurrentDomain.BaseDirectory);

            InitGeckoFx();

            LoadApp(); // Initialize the Chromium web browser

            Xpcom.Shutdown();
            ExceptionLogger.UnBind(); // unbind so the truncate thread is stopped successfully..
        }
 public MainWindow()
 {
     InitializeComponent();
     ExceptionLogger.Bind();
     ExceptionLogger.LogMessage("Application start: " + System.Windows.Application.ResourceAssembly.GetName().Name);
 }