Exemplo n.º 1
0
        /*
         * public static string pathSaveData = Path.Combine(pathData, "SaveData");
         * public static string pathWpTmp = Path.Combine(pathData, "SaveData", "wptmp");
         * public static string pathWallpapers = Path.Combine(pathData, "wallpapers");
         * public static string pathTmpData = Path.Combine(pathData, "tmpdata");
         * public static string pathWpData = Path.Combine(pathData, "tmpdata", "wpdata");
         */
        protected override void OnStartup(StartupEventArgs e)
        {
            //delete residue tempfiles if any!
            FileOperations.EmptyDirectory(Path.Combine(pathData, "tmpdata"));
            try
            {
                //create directories if not exist
                Directory.CreateDirectory(Path.Combine(pathData, "SaveData"));
                Directory.CreateDirectory(Path.Combine(pathData, "SaveData", "wptmp"));
                Directory.CreateDirectory(Path.Combine(pathData, "wallpapers"));
                Directory.CreateDirectory(Path.Combine(pathData, "tmpdata"));
                Directory.CreateDirectory(Path.Combine(pathData, "tmpdata", "wpdata"));
            }
            catch (Exception ex)
            {
                //not logging here, just display & terminate.
                MessageBox.Show(ex.Message, Props.Resources.txtLivelyErrorMsgTitle, MessageBoxButton.OK, MessageBoxImage.Error);
                Environment.Exit(1);
            }

            SaveData.LoadConfig();

            #region language
            //CultureInfo.CurrentCulture = new CultureInfo("ru-RU", false); //not working?
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(SaveData.config.Language);
            //System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CN"); //zh-CN
            #endregion language

            if (!SaveData.config.SafeShutdown)
            {
                //clearing previous wp persisting image if any (not required, subProcess clears it).
                SetupDesktop.RefreshDesktop();

                Directory.CreateDirectory(Path.Combine(pathData, "ErrorLogs"));
                string fileName = DateTime.Now.ToString("yyyyMMdd_HHmmss", CultureInfo.InvariantCulture) + ".txt";
                if (File.Exists(Path.Combine(pathData, "ErrorLogs", fileName)))
                {
                    fileName = Path.GetRandomFileName() + ".txt";
                }

                try
                {
                    File.Copy(Path.Combine(pathData, "logfile.txt"),
                              Path.Combine(pathData, "ErrorLogs", fileName));
                }
                catch (IOException e1)
                {
                    System.Diagnostics.Debug.WriteLine(e1.ToString());
                }

                var result = MessageBox.Show(Props.Resources.msgSafeModeWarning +
                                             Path.Combine(pathData, "ErrorLogs", fileName)
                                             , Props.Resources.txtLivelyErrorMsgTitle, MessageBoxButton.YesNo);

                if (result == MessageBoxResult.No)
                {
                    SetupDesktop.wallpapers.Clear();
                    SaveData.SaveWallpaperLayout(); //deleting saved wallpaper arrangements.
                }
            }
            SaveData.config.SafeShutdown = false;
            SaveData.SaveConfig();

            #region theme
            // add custom accent and theme resource dictionaries to the ThemeManager
            // you should replace MahAppsMetroThemesSample with your application name
            // and correct place where your custom accent lives
            //ThemeManager.AddAccent("CustomAccent1", new Uri("pack://application:,,,/CustomAccent1.xaml"));

            // get the current app style (theme and accent) from the application
            // you can then use the current theme and custom accent instead set a new theme
            Tuple <AppTheme, Accent> appStyle = ThemeManager.DetectAppStyle(Application.Current);

            //white theme disabled temp: for v0.8
            if (SaveData.config.Theme == 9 || SaveData.config.Theme == 10)
            {
                SaveData.config.Theme = 0;
                SaveData.SaveConfig();
                ThemeManager.ChangeAppStyle(Application.Current,
                                            ThemeManager.GetAccent(SaveData.livelyThemes[SaveData.config.Theme].Accent),
                                            ThemeManager.GetAppTheme(SaveData.livelyThemes[SaveData.config.Theme].Base)); // or appStyle.Item1
            }
            else
            {
                // setting accent & theme
                ThemeManager.ChangeAppStyle(Application.Current,
                                            ThemeManager.GetAccent(SaveData.livelyThemes[SaveData.config.Theme].Accent),
                                            ThemeManager.GetAppTheme(SaveData.livelyThemes[SaveData.config.Theme].Base)); // or appStyle.Item1
            }

            // now change app style to the custom accent and current theme
            //ThemeManager.ChangeAppStyle(Application.Current, ThemeManager.GetAccent("CustomAccent1"), ThemeManager.GetAppTheme(SaveData.livelyThemes[SaveData.config.Theme].Base));
            #endregion theme

            base.OnStartup(e);

            SetupExceptionHandling();
            w = new MainWindow();

            if (SaveData.config.IsFirstRun)
            {
                //SaveData.config.isFirstRun = false; //only after minimizing to tray isFirstRun is set to false.
                SaveData.SaveConfig(); //creating disk file temp, not needed!

                w.Show();
                w.UpdateWallpaperLibrary();

                Dialogues.HelpWindow hw = new Dialogues.HelpWindow
                {
                    Owner = w,
                    WindowStartupLocation = WindowStartupLocation.CenterOwner
                };
                hw.ShowDialog();
            }

            if (SaveData.config.IsRestart)
            {
                SaveData.config.IsRestart = false;
                SaveData.SaveConfig();

                w.Show();
                w.UpdateWallpaperLibrary();
                //w.ShowMainWindow();

                w.tabControl1.SelectedIndex = 2; //settings tab
                //SetupDesktop.SetFocus();
                //w.Activate();
            }
        }
Exemplo n.º 2
0
        protected override void OnStartup(StartupEventArgs e)
        {
            Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "\\SaveData"); //create if not exist
            SaveData.LoadConfig();

            #region language
            //CultureInfo.CurrentCulture = new CultureInfo("ru-RU", false); //not working?
            System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(SaveData.config.Language);
            //System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-CN"); //zh-CN
            #endregion language

            if (!SaveData.config.SafeShutdown)
            {
                //clearing previous wp persisting image if any.
                SetupDesktop.RefreshDesktop();

                Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "\\ErrorLogs\\");
                string fileName = DateTime.Now.ToString("yyyyMMdd_HHmmss", CultureInfo.InvariantCulture) + ".txt";
                if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\ErrorLogs\\" + fileName))
                {
                    fileName = Path.GetRandomFileName() + ".txt";
                }

                try
                {
                    File.Copy(AppDomain.CurrentDomain.BaseDirectory + "\\logfile.txt",
                              AppDomain.CurrentDomain.BaseDirectory + "\\ErrorLogs\\" + fileName);
                }
                catch (IOException e1)
                {
                    System.Diagnostics.Debug.WriteLine(e1.ToString());
                }

                var result = MessageBox.Show(Props.Resources.msgSafeModeWarning +
                                             AppDomain.CurrentDomain.BaseDirectory + "ErrorLogs\\" + fileName
                                             , Props.Resources.txtLivelyErrorMsgTitle, MessageBoxButton.YesNo);

                if (result == MessageBoxResult.No)
                {
                    SetupDesktop.wallpapers.Clear();
                    SaveData.SaveWallpaperLayout(); //deleting saved wallpaper arrangements.
                }
            }
            SaveData.config.SafeShutdown = false;
            SaveData.SaveConfig();

            base.OnStartup(e);
            SetupExceptionHandling();
            w = new MainWindow();

            if (SaveData.config.IsFirstRun)
            {
                //SaveData.config.isFirstRun = false; //only after minimizing to tray isFirstRun is set to false.
                SaveData.SaveConfig(); //creating disk file temp, not needed!

                w.Show();
                w.UpdateWallpaperLibrary();

                HelpWindow hw = new HelpWindow
                {
                    Owner = w,
                    WindowStartupLocation = WindowStartupLocation.CenterOwner
                };
                hw.ShowDialog();
            }

            if (SaveData.config.IsRestart)
            {
                SaveData.config.IsRestart = false;
                SaveData.SaveConfig();

                //w.WindowStartupLocation = WindowStartupLocation.Manual;
                w.Show();
                w.UpdateWallpaperLibrary();

                w.tabControl1.SelectedIndex = 2; //settings tab
            }
        }