Ejemplo n.º 1
0
        protected override void doWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            base.doWork(sender, e);

            path_candidates = new ObservableCollection<LocationPathHolder>();
            user_candidates = new ObservableCollection<string>();

            ProgressHandler.progress_state = ProgressState.Indeterminate;

            if(archive==null) {
                string[] args = Environment.GetCommandLineArgs();
                if(args.Length>0) {
                    foreach(string arg in args) {
                        if(!arg.StartsWith("-")&&(arg.EndsWith(Core.extension)||arg.EndsWith(Core.extension + "\""))) {
                            archive = new ArchiveHandler(new FileInfo(arg.Trim('\"')));
                        }
                    }
                }
            }

            if(archive==null)
                throw new MException("Nothing To Do","No File Was Selected To Restore",false);

            ProgressHandler.progress_message = "Detecting game for restoration...";

            if (!File.Exists(archive.file_name))
                throw new MException("Not there","The specified backup doesn't exist",false);

            GameID selected_game = archive.id.game;
            string backup_owner = archive.id.owner;
            string archive_type = archive.id.type;

            if(!Core.games.all_games.ContainsObjectWithID(selected_game))
                throw new MException("Unknown","MASGAU doesn't have information for the game: " + selected_game.ToString(),true);

            game_data = Core.games.all_games.GetObjectWithID(selected_game);
            game_data.detect();

            // This adds hypothetical locations
            foreach(LocationPathHolder location in game_data.location_paths) {
                if(game_data.detection_required)
                    break;

                //if(location.path==null)
                    //continue;
                if(location.platform_version!=PlatformVersion.All&&location.platform_version!=Core.locations.platform_version)
                    continue;

                if(location.rel_root==EnvironmentVariable.InstallLocation||
                    location.rel_root==EnvironmentVariable.SteamCommon)
                    continue;

                // Adds user-friendly menu entries to the root selector
                switch(location.rel_root) {
                    case EnvironmentVariable.SteamSourceMods:
                        if(Core.locations.steam_detected)
                            addPathCandidate(location);
                        break;
                    case EnvironmentVariable.SteamUser:
                        if(Core.locations.steam_detected&&Core.locations.getUsers(EnvironmentVariable.SteamUser).Count>0)
                            addPathCandidate(location);
                        break;
                    case EnvironmentVariable.SteamUserData:
                        if(Core.locations.steam_detected&&Core.locations.getUsers(EnvironmentVariable.SteamUserData).Count>0)
                            addPathCandidate(location);
                        break;
                    default:
                        addPathCandidate(location);
                        break;
                }
            }

            // This add already found locations
            foreach(KeyValuePair<string,DetectedLocationPathHolder> location in game_data.detected_locations) {
                location.Value.IsSelected = true;
                switch(location.Value.rel_root) {
                    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.Value);
                            temp.abs_root = null;
                            temp.owner = location.Value.owner;
                            temp.path = Path.Combine("VirtualStore", location.Value.full_dir_path.Substring(3));
                            temp.rel_root = EnvironmentVariable.LocalAppData;
                            addPathCandidate(temp);
                        }
                        addPathCandidate(location.Value);
                        break;
                    default:
                        addPathCandidate(location.Value);
                        break;
                }
            }

            if(path_candidates.Count==1) {
                multiple_paths = false;
                NotifyPropertyChanged("only_path");
            } else if(path_candidates.Count>1) {
                multiple_paths = true;
            } else {
                throw new MException("Can't Restore If We Can't Find It","No restore paths detected for " + this.archive.id.ToString(),false);
            }
        }