Exemple #1
0
 public static void loadXml()
 {
     TranslatingProgressHandler.setTranslatedMessage("LoadingGameXmls");
     supress_duplicate_game_warnings = false;
     xml = new GameXmlFiles();
     model.Clear();
     if (xml.Entries.Count > 0)
     {
         TranslatingProgressHandler.setTranslatedMessage("LoadingGamesData");
         foreach (GameSaveInfo.Game game in xml.Entries)
         {
             foreach (GameVersion version in game.Versions)
             {
                 try {
                     GameEntry entry;
                     if (version is CustomGameVersion)
                     {
                         entry = new CustomGameEntry(version as CustomGameVersion);
                     }
                     else
                     {
                         entry = new GameEntry(version);
                     }
                     addGame(entry);
                 } catch (Exception e) {
                     TranslatingMessageHandler.SendException(e);
                 }
             }
         }
     }
 }
 protected void forwardExceptions(object sender, RunWorkerCompletedEventArgs e)
 {
     if (e.Error != null)
     {
         TranslatingMessageHandler.SendException(e.Error);
     }
 }
Exemple #3
0
 private void checkExceptions(object sender, RunWorkerCompletedEventArgs e)
 {
     if (e.Error != null)
     {
         TranslatingMessageHandler.SendException(e.Error);
     }
 }
Exemple #4
0
 void worker_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
 {
     if (e.Error != null)
     {
         TranslatingMessageHandler.SendException(e.Error);
         worker.RunWorkerAsync();
     }
     NotifyPropertyChanged("Status");
     NotifyPropertyChanged("Active");
 }
Exemple #5
0
        public static void DetectBackups()
        {
            ProgressHandler.saveMessage();
            model.Clear();
            if (!Core.settings.IsBackupPathSet)
            {
                return;
            }
            ProgressHandler.state = ProgressState.Normal;
            string path = null;

            path = Core.settings.backup_path;
            FileInfo[] read_us = new DirectoryInfo(path).GetFiles("*.gb7");

            ProgressHandler.value = 0;
            if (read_us.Length > 0)
            {
                ProgressHandler.max = read_us.Length;
                TranslatingProgressHandler.setTranslatedMessage("LoadingArchives", ProgressHandler.value.ToString(), read_us.Length.ToString());
                foreach (FileInfo read_me in read_us)
                {
                    ProgressHandler.value++;

                    try {
                        Archive add_me = new Archive(read_me);
                        if (add_me != null)
                        {
                            model.AddWithSort(add_me);
                        }
                    } catch (Exception e) {
                        TranslatingMessageHandler.SendException(e);
                    }
                }
            }

            ProgressHandler.state = ProgressState.None;
            ProgressHandler.value = 0;
            ProgressHandler.restoreMessage();
        }
        void BackupProgramHandler_DoWork(object sender, DoWorkEventArgs e)
        {
            if (Core.settings.IsBackupPathSet || archive_name_override != null)
            {
                if (archive_name_override != null)
                {
                    output_path = Path.GetDirectoryName(archive_name_override);
                }
                else
                {
                    output_path = Core.settings.backup_path;
                }


                IList <GameEntry> games;

                if (back_these_up != null && back_these_up.Count > 0)
                {
                    games = back_these_up;
                }
                else
                {
                    if (Games.detected_games_count == 0)
                    {
                        Games.detectGames();
                    }
                    games = Games.DetectedGames.Items;
                }

                if (games.Count > 0)
                {
                    ProgressHandler.value = 1;
                    ProgressHandler.max   = games.Count;
                    TranslatingProgressHandler.setTranslatedMessage("GamesToBeBackedUpCount", games.Count.ToString());


                    foreach (GameEntry game in games)
                    {
                        if (CancellationPending)
                        {
                            return;
                        }

                        //if(archive_name_override!=null)
                        //all_users_archive = new ArchiveHandler(new FileInfo(archive_name_override),game.id);

                        if (games.Count == 1)
                        {
                            TranslatingProgressHandler.setTranslatedMessage("BackingUpSingleGame", game.Title);
                        }
                        else
                        {
                            TranslatingProgressHandler.setTranslatedMessage("BackingUpMultipleGames", game.Title, ProgressHandler.value.ToString(), games.Count.ToString());
                        }

                        List <DetectedFile> files;
                        if (only_these_files != null && only_these_files.Count > 0)
                        {
                            files = only_these_files;
                        }
                        else
                        {
                            files = game.Saves.Flatten();
                            ;
                        }


                        Archive override_archive = null;

                        try {
                            DictionaryList <Archive, DetectedFile> backup_files = new DictionaryList <Archive, DetectedFile>();
                            foreach (DetectedFile file in files)
                            {
                                ArchiveID archive_id;
                                Archive   archive;
                                if (CancellationPending)
                                {
                                    return;
                                }

                                archive_id = new ArchiveID(game.id, file);

                                if (archive_name_override != null)
                                {
                                    if (override_archive == null)
                                    {
                                        file.Type = null;
                                    }
                                    override_archive = new Archive(new FileInfo(archive_name_override), new ArchiveID(game.id, file));
                                    archive          = override_archive;
                                }
                                else
                                {
                                    if (Archives.Get(archive_id) == null)
                                    {
                                        Archives.Add(new Archive(output_path, new ArchiveID(game.id, file)));
                                    }
                                    archive = Archives.Get(archive_id);
                                }

                                backup_files.Add(archive, file);
                            }
                            if (CancellationPending)
                            {
                                return;
                            }

                            foreach (KeyValuePair <Archive, List <DetectedFile> > backup_file in backup_files)
                            {
                                if (override_archive == null)
                                {
                                    backup_file.Key.backup(backup_file.Value, false, false);
                                }
                                else
                                {
                                    backup_file.Key.backup(backup_file.Value, true, false);
                                }
                            }
                        } catch (Exception ex) {
                            TranslatingMessageHandler.SendException(ex);
                        } finally {
                            ProgressHandler.value++;
                        }
                    }
                }
                else
                {
                    TranslatingMessageHandler.SendError("NothingToBackup");
                }
            }
            else
            {
                TranslatingMessageHandler.SendError("BackupPathNotSet");
            }
        }
        protected override void doWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            base.doWork(sender, e);

            path_candidates = new SimpleModel <LocationPath>();
            user_candidates = new SimpleModel <string>();

            ProgressHandler.state = ProgressState.Indeterminate;
            try {
                if (archive == null)
                {
                }
            } catch (Exception ex) {
                TranslatingMessageHandler.SendException(ex);
            }


            if (ArgArchives.Count > 0)
            {
                archive = new Archive(new FileInfo(ArgArchives.Dequeue()));
            }

            if (archive == null)
            {
                throw new TranslateableException("NoRestoreFileSelected");
            }

            TranslatingProgressHandler.setTranslatedMessage("DetectingGameForRestoration");

            if (!archive.Exists)
            {
                throw new TranslateableException("FileNotFound", archive.ArchivePath);
            }

            GameID selected_game = archive.id.Game;
            string backup_owner  = archive.id.Owner;
            string archive_type  = archive.id.Type;


            try {
                game_data = Games.detectGame(selected_game);
            } catch (Exception ex) {
                TranslatingMessageHandler.SendException(ex);
            }

            NotifyPropertyChanged("GameNotDetected");


            if (game_data != null)
            {
                // This adds hypothetical locations
                foreach (LocationPath location in game_data.Locations.Paths)
                {
                    if (game_data.DetectionRequired)
                    {
                        break;
                    }

                    filterPathCandidates(location);
                }


                // This add already found locations
                foreach (DetectedLocationPathHolder location in game_data.DetectedLocations)
                {
                    location.IsSelected = true;
                    switch (location.EV)
                    {
                    case EnvironmentVariable.ProgramFiles:
                    case EnvironmentVariable.ProgramFilesX86:
                        // This adds a fake VirtualStore folder, just in case
                        if (Core.locations.uac_enabled)
                        {
                            DetectedLocationPathHolder temp = new DetectedLocationPathHolder(location, Core.locations.getFolder(EnvironmentVariable.LocalAppData, location.owner), location.owner);
                            temp.ReplacePath(Path.Combine("VirtualStore", location.FullDirPath.Substring(3)));
                            temp.EV = EnvironmentVariable.LocalAppData;
                            addPathCandidate(temp);
                        }
                        addPathCandidate(location);
                        break;

                    default:
                        addPathCandidate(location);
                        break;
                    }
                }

                //if (archive.id.Game.OS!=null&&archive.id.Game.OS.StartsWith("PS")) {

                //    foreach (string drive in Core.locations.ps.GetDriveCandidates()) {
                //        DetectedLocationPathHolder loc = new DetectedLocationPathHolder(EnvironmentVariable.Drive, drive, null);
                //            addPathCandidate(loc);
                //    }
                //}
            }

            if (archive.id.OriginalEV != EnvironmentVariable.None &&
                archive.id.OriginalRelativePath != null)
            {
                LocationPath path = new LocationPath(archive.id.OriginalEV, archive.id.OriginalRelativePath);
                filterPathCandidates(path);
            }

            if (archive.id.OriginalLocation != null)
            {
                DetectedLocations          locs = Core.locations.interpretPath(archive.id.OriginalLocation);
                DetectedLocationPathHolder loc  = locs.getMostAccurateLocation();
                if (loc != null)
                {
                    addPathCandidate(loc);
                }
            }


            if (path_candidates.Count == 1)
            {
                multiple_paths = false;
                NotifyPropertyChanged("only_path");
            }
            else if (path_candidates.Count > 1)
            {
                multiple_paths = true;
            }
            else
            {
                throw new TranslateableException("NoRestorePathsDetected", this.archive.id.ToString());
            }
        }
Exemple #8
0
        void worker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            MonitorFile file;

            while (!worker.CancellationPending)
            {
                NotifyPropertyChanged("Active");
                NotifyPropertyChanged("Status");
                if (QueueCount == 0)
                {
                    // No new files? Take a nap.
                    try {
                        Thread.Sleep(100);
                    } catch (Exception ex) {
                        TranslatingMessageHandler.SendException(ex);
                    }
                    continue;
                }

                lock (FileQueue) {
                    file = FileQueue.Dequeue();
                }

                if (!file.Path.Game.IsMonitored)
                {
                    continue;
                }

                FileInfo fi   = new FileInfo(Path.Combine(file.root, file.path));
                GameID   game = file.Path.Game.id;
                switch (file.change_type)
                {
                case System.IO.WatcherChangeTypes.Changed:
                case System.IO.WatcherChangeTypes.Created:
                case System.IO.WatcherChangeTypes.Renamed:
                    if (!fi.Exists)
                    {
                        continue;
                    }
                    List <DetectedFile> these_files = file.Path.Game.GetSavesMatching(file.full_path);
                    if (these_files.Count == 0)
                    {
                        continue;
                    }
                    foreach (DetectedFile this_file in these_files)
                    {
                        _status = game.Name + " updating " + Path.Combine(this_file.Path, this_file.Name);
                        NotifyPropertyChanged("Status");

                        if (this_file.FullDirPath == null)
                        {
                            continue;
                        }

                        Archive archive = Archives.GetArchive(game, this_file);

                        try {
                            if (archive == null)
                            {
                                if (this_file.owner == null)
                                {
                                    archive = new Archive(Core.settings.backup_path, new ArchiveID(game, this_file));
                                }
                                else
                                {
                                    archive = new Archive(Core.settings.backup_path, new ArchiveID(game, this_file));
                                }
                                Archives.Add(archive);
                            }
                            //monitorNotifier.ShowBalloonTip(10, "Safety Will Robinson", "Trying to archive " + file.path, ToolTipIcon.Info);
                            MessageHandler.suppress_messages = true;
                            List <DetectedFile> temp_list = new List <DetectedFile>();
                            temp_list.Add(this_file);
                            archive.backup(temp_list, false, true);
                        } catch {
                            //monitorNotifier.ShowBalloonTip(10,"Danger Will Robinson","Error while trying to archive " + file.path,ToolTipIcon.Error);
                            // If something goes wrong during backup, it's probable the file copy.
                            // Reinsert the file to the end of the queue, then move on to the next one.
                            if (!FileQueue.Contains(file))
                            {
                                FileQueue.Enqueue(file);
                            }
                        } finally {
                            MessageHandler.suppress_messages = false;
                        }
                    }
                    break;
                }
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                }

                _status = null;
            }
            NotifyPropertyChanged("Status");
            NotifyPropertyChanged("Active");
        }