예제 #1
0
        static Settings()
        {
            if (File.Exists(CONFIG))
            {
                bool overwrite =false;
                try
                {
                    setti = Load(CONFIG, out overwrite);
                }
                catch (Exception ex) //eror while loading config (file broken?)
                {
                    if (File.Exists(CONFIGBAK)) //There's a backup, hurray!
                    {
                        try
                        {
                            setti = Load(CONFIGBAK, out overwrite); //try to load backup
                            overwrite = true; //Overwrite broken config anyway (not only if updated)
                            MessageBox.Show(
                                "SjUpdater was not terminated properly ("+CONFIG+" broken). Old Settings restored from backup ("+CONFIGBAK+"). " +
                                "Submit a Bugreport if you see this message often. Details:\n"+ ex,
                                "SjUpdater was not terminated properly");
                        }
                        catch (Exception ex2) //Loading backup failed as well :(
                        {
                            MessageBox.Show(
                             "SjUpdater was not terminated properly (" + CONFIG + " broken). Backup (" + CONFIGBAK + ") couldn't be restored either. " +
                             "Your config was deleted and you have to start over again :( . " +
                             "Report the following to the developer:\n" + ex2,
                             "SjUpdater was not terminated properly");
                        }
                    }
                    else //No Backup available :(
                    {
                        MessageBox.Show(
                               "SjUpdater was not terminated properly (" + CONFIG + " broken) and " +
                               "there was no backup (" + CONFIGBAK + ") for your config available. " +
                               "Your config was deleted and you have to start over again :( . " +
                               "Submit a Bugreport if you see this message often. Details:\n" + ex,
                               "SjUpdater was not terminated properly");
                    }
                }

                if (setti != null) //loading ok
                {
                    if (overwrite) setti.Save(CONFIG); //if we need to save the changes because of a settings migration
                    File.Copy(CONFIG, CONFIGBAK, true); //backup the successfully loadable file.
                }
            }
            if(setti==null) //either the user has started the application for the first time or the config could not be loaded
            {
                setti = new Settings(); //Create a new settings instance/file
                setti.Save(CONFIG); //and save it
                File.Copy(CONFIG, CONFIGBAK, true); //backup the new file (paranoid)
            }
        }
예제 #2
0
 static Settings()
 {
     if (File.Exists("config.xml"))
     {
         bool overwrite;
         setti = Load("config.xml",out overwrite);
         if (setti != null && overwrite)
         {
             setti.Save("config.xml");
         }
     }
     if(setti==null)
     {
         setti = new Settings();
         setti.Save("config.xml");
     }
 }
예제 #3
0
        public MainWindow()
        {
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
            Application.Current.SessionEnding += Current_SessionEnding;

            //Commands
            ShowClickedCommand = new SimpleCommand<object, ShowTileViewModel>(OnShowViewClicked);
            SettingsCommand = new SimpleCommand<object, object>(SettingsClicked);
            IconClickedCommand = new SimpleCommand<object, object>(IconClicked);
            TerminateCommand = new SimpleCommand<object, object>(Terminate);

            //Settings & Theme
            _setti = Settings.Instance;

            _currentAccent = ThemeManager.GetAccent(_setti.ThemeAccent);
            _currentTheme = ThemeManager.GetAppTheme(_setti.ThemeBase);
            CurrentAccent = _setti.ThemeAccent;

            updateTimer = new Timer();
            //Updater
            _updater = new UpdateWindow("http://dreamcooled.github.io/sjupdater/latest", true, "SjUpdater.exe", "-uf " + Stats.GetVersionString());
            _updater.updateStartedEvent += (a, dsa) =>
                                           {
                                               Terminate(null);
                                               Stats.TrackAction(Stats.TrackActivity.AppUpdate);
                                           };

            //Start!
            InitializeComponent();
            if (Environment.GetCommandLineArgs().Contains("-nogui"))
                Hide();

            //Initialize view
            _viewModel = new MainWindowViewModel(_setti.TvShows);
            DataContext = _viewModel;


            //Enhance TreeView with Multiselection Extension
            //Note: We could also pass a observable collection to the first method, and get changes from the CollectionChanged Event on the observablecollection
            //But this way (custom event) we get less Events, which speeds up the GUI
            TreeViewExtensions.SetSelectedItems(ShowTreeView, _selectedEpisodeTreeItems);
            TreeViewExtensions.AddSelectionChangedListener(ShowTreeView,_selectedEpisodeTreeItems_CollectionChanged); 

            SwitchPage(0);

            //Autoupdate timer
            if (_setti.UpdateTime > 0) //Autoupdate enabled
            {
                var t = new Timer(_setti.UpdateTime);
                t.Elapsed += t_Elapsed;
                t.Start();
            }

            //Inital update
            Update();

            //Stats

            Stats.StatsUrl = "http://sjupdater.batrick.de/stats";
            Stats.AllowCustom = !_setti.NoPersonalData;
            Stats.TrackAction(Stats.TrackActivity.AppStart);
            Stats.TrackCustomVariable("Shows", _setti.TvShows.Select(s => s.Name));

            if (_setti.CheckForUpdates)
            {
                _updater.Show(false, true);
                updateTimer = new Timer(1000 * 60 * 30); // 30 minutes
                updateTimer.Elapsed += (o, args) => Dispatcher.Invoke(() => _updater.Show(false, true));
                updateTimer.Start();
            }
        }
예제 #4
0
        private static Settings Import(Settings actualSettings, int actualVersion, int targetVersion)
        {
            if (actualVersion > targetVersion) return null;
            if ((targetVersion - actualVersion) > 1)
            {
                Settings s1 = Import(actualSettings, actualVersion, actualVersion + 1);
                return Import(s1, actualVersion + 1, targetVersion);
            }

            switch (actualVersion)
            {
                case 1: //upgrading from v1 to v2

                    foreach (var favShow in actualSettings.TvShows)
                    {
                        for (int i = favShow.Seasons.Count-1; i>=0; i--)
                        {
                            var favSeason = favShow.Seasons[i];
                            if (favSeason.Number == -1)
                            {
                                foreach (var downloadData in favSeason.Episodes.SelectMany(favEpisode => favEpisode.Downloads))
                                {
                                    favShow.NonSeasons.Add(downloadData);
                                }
                                favShow.Seasons.RemoveAt(i);
                            }
                            else
                            {
                                var nonEpisode = favSeason.Episodes.FirstOrDefault(favEpisode => favEpisode.Number == -1);
                                if (nonEpisode != null)
                                {
                                    foreach (var downloadData in nonEpisode.Downloads)
                                    {
                                        favSeason.NonEpisodes.Add(downloadData);
                                    }
                                    favSeason.Episodes.Remove(nonEpisode);
                                }
                            }
                        }

                        favShow.SetResetOnRefresh();
                    }
                    break;

            }

            return actualSettings;
        }