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)
        {
            if (isPortableBuild)
            {
                PathData = AppDomain.CurrentDomain.BaseDirectory;
            }
            else
            {
                PathData = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Lively Wallpaper");
            }
            //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, "SaveData", "wpdata"));
                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, something must be seriously wrong.. 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?
            try
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(SaveData.config.Language);
            }
            catch (CultureNotFoundException)
            {
                System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
            }
            //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

            #region nlog
            var config = new NLog.Config.LoggingConfiguration();

            // Targets where to log to: File and Console
            var logfile = new NLog.Targets.FileTarget("logfile")
            {
                FileName = Path.Combine(PathData, "logfile.txt"), DeleteOldFileOnStartup = true
            };
            var logconsole = new NLog.Targets.ConsoleTarget("logconsole");

            // Rules for mapping loggers to targets
            config.AddRule(LogLevel.Info, LogLevel.Fatal, logconsole);
            config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile);

            // Apply config
            NLog.LogManager.Configuration = config;
            #endregion nlog

            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(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "docs", "help_vid_1.mp4"))
                {
                    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
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     SaveData.appRules = appRulesCollection.ToList();
     SaveData.SaveApplicationRules();
 }
Exemplo n.º 3
0
 private void ChkBoxCreateZip_Checked(object sender, RoutedEventArgs e)
 {
     SaveData.config.LivelyZipGenerate = chkBoxCreateZip.IsChecked.Value;
     SaveData.SaveConfig();
 }
Exemplo n.º 4
0
 private void ChkBoxCreatePreview_Checked(object sender, RoutedEventArgs e)
 {
     SaveData.config.PreviewGIF.CaptureGif = chkBoxCreatePreview.IsChecked.Value;
     SaveData.SaveConfig();
 }
Exemplo n.º 5
0
        private async void Button_Create_Click(object sender, RoutedEventArgs e)
        {
            tmpInfo.Title   = textboxTitle.Text;
            tmpInfo.Author  = textboxAuthor.Text;
            tmpInfo.Desc    = textboxDesc.Text;
            tmpInfo.Contact = textboxWebsite.Text;
            tmpInfo.License = textboxLicense.Text;
            //tmpInfo.Type = (SetupDesktop.WallpaperType)comboBoxType.SelectedItem;
            tmpInfo.Type      = wallpaperTypes[comboBoxType.SelectedIndex].Type;
            tmpInfo.Arguments = textboxArgs.Text;

            if (folderContents.Count == 0 || String.IsNullOrWhiteSpace(tmpInfo.FileName))
            {
                MessageBox.Show(Properties.Resources.txtMsgSelectWallpaperFile);
                return;
            }

            if (String.IsNullOrEmpty(tmpInfo.Title) || String.IsNullOrEmpty(tmpInfo.Desc) || String.IsNullOrEmpty(tmpInfo.Author)
                )    //|| String.IsNullOrEmpty(tmpInfo.contact) )
            {
                MessageBox.Show(Properties.Resources.txtMsgFillAllFields);
                return;
            }

            /*
             * //Optional
             * if( !File.Exists(tmpInfo.Thumbnail) || !File.Exists(tmpInfo.Preview) )
             * {
             *  MessageBox.Show(Properties.Resources.txtSelectPreviewThumb);
             *  return;
             * }
             */

            SaveFileDialog saveFileDialog1 = new SaveFileDialog
            {
                Title           = "Select location to save the file",
                Filter          = "Lively/zip file|*.zip",
                OverwritePrompt = true
            };

            if (saveFileDialog1.ShowDialog() == true)
            {
                if (!String.IsNullOrEmpty(saveFileDialog1.FileName))
                {
                    //to write to Livelyinfo.json file only, tmp object.
                    SaveData.LivelyInfo tmp = new SaveData.LivelyInfo(tmpInfo);
                    tmp.FileName  = Path.GetFileName(tmp.FileName);
                    tmp.Preview   = Path.GetFileName(tmp.Preview);
                    tmp.Thumbnail = Path.GetFileName(tmp.Thumbnail);

                    SaveData.SaveWallpaperMetaData(tmp, AppDomain.CurrentDomain.BaseDirectory + "\\tmpdata");

                    /*
                     * //if previous livelyinfo.json file(s) exists in wallpaper directory, remove all of them.
                     * folderContents.RemoveAll(x => Path.GetFileName(x).Equals(Path.GetFileName(folderContents[folderContents.Count - 1]),
                     *                  StringComparison.InvariantCultureIgnoreCase));
                     */
                    folderContents.Add(AppDomain.CurrentDomain.BaseDirectory + @"tmpdata\LivelyInfo.json");

                    //btnCreateWallpaer.IsEnabled = false;
                    await CreateZipFile(saveFileDialog1.FileName, folderContents);

                    string folderPath = System.IO.Path.GetDirectoryName(saveFileDialog1.FileName);
                    if (Directory.Exists(folderPath))
                    {
                        ProcessStartInfo startInfo = new ProcessStartInfo
                        {
                            Arguments = folderPath,
                            FileName  = "explorer.exe"
                        };
                        Process.Start(startInfo);
                    }

                    //this.NavigationService.GoBack(); //won't work, since prev is window, not page.
                    var wnd = Window.GetWindow(this);
                    wnd.Close();
                }
            }
            else
            {
                return;
            }
        }
Exemplo n.º 6
0
        protected override void OnStartup(StartupEventArgs e)
        {
            //delete residue tempfiles
            FileOperations.EmptyDirectory(AppDomain.CurrentDomain.BaseDirectory + "\\tmpdata");

            //create directories if not exist
            Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "\\SaveData");
            Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "\\wallpapers");
            Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "\\SaveData\\wptmp");
            Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "\\tmpdata");
            Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "\\tmpdata\\wpdata");

            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();

            #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);


            // 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();

                HelpWindow hw = new 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();
            }
        }