public CustomGameVersion(GameSaveInfo.Game parent, DirectoryInfo location, string saves, string ignores)
            : base(parent, "Windows", null, "Custom")
        {
            DetectedLocations          locs = Core.locations.interpretPath(location.FullName);
            DetectedLocationPathHolder loc  = locs.getMostAccurateLocation();

            if (loc.EV == EnvironmentVariable.VirtualStore)
            {
                string drive    = Path.GetPathRoot(loc.FullDirPath);
                string new_path = Path.Combine(drive, loc.Path);
                loc = Core.locations.interpretPath(new_path).getMostAccurateLocation();
            }

            switch (loc.EV)
            {
            case EnvironmentVariable.ProgramFiles:
            case EnvironmentVariable.ProgramFilesX86:
            case EnvironmentVariable.Drive:
                loc.EV = EnvironmentVariable.InstallLocation;
                break;
            }


            LocationPath locpath = new LocationPath(this.Locations, loc.EV, loc.Path);

            this.Locations.Paths.Add(locpath);


            FileType type = this.addFileType("Custom");

            string  path, file;
            Include save;

            if (saves != null && ignores != "")
            {
                path = Path.GetDirectoryName(saves);
                file = Path.GetFileName(saves);
                save = type.addSave(path, file);
            }
            else
            {
                save = type.addSave(null, null);
            }

            if (ignores != null && ignores != "")
            {
                path = Path.GetDirectoryName(ignores);
                file = Path.GetFileName(ignores);
                Exclude except = save.addExclusion(path, file);
            }

            if (Core.settings.EmailSender != null)
            {
                this.Contributors.Add(Core.settings.EmailSender);
            }
            else
            {
                this.Contributors.Add("Anonymous");
            }
        }
        protected override DetectedLocations getPaths(ScummVM get_me)
        {
            if (get_me.Name == "scummvm")
                Console.Out.Write("");

            List<DetectedLocationPathHolder> paths = new List<DetectedLocationPathHolder>();
            if (Locations == null) {
                setup();
            }
            if (install_path != null) {
                paths.AddRange(loadLocations(install_path, get_me, null));
            }

            DetectedLocations return_me = new DetectedLocations();

            foreach (string user in Locations.Keys) {
                if (get_me.Name != "scummvm" && Locations[user].ContainsKey("scummvm")) {
                    foreach (DetectedLocationPathHolder path in loadLocations(Locations[user]["scummvm"], get_me, user)) {
                        DirectoryInfo info = new DirectoryInfo(path.FullDirPath);
                        if (info.GetFiles(get_me.Name + "*").Length > 0) {
                            return_me.Add(path);
                        }
                    }
                }

                if (Locations[user].ContainsKey(get_me.Name)) {
                    return_me.AddRange(loadLocations(Locations[user][get_me.Name], get_me, user));
                }
            }

            return return_me;
        }
 protected override DetectedLocations getPaths(LocationPath get_me)
 {
     DetectedLocations return_me = new DetectedLocations();
     DirectoryInfo test;
     DetectedLocationPathHolder add_me;
     switch (get_me.EV) {
         case EnvironmentVariable.InstallLocation:
             LocationPath temp = new LocationPath(get_me);
             string[] chopped = temp.Path.Split(Path.DirectorySeparatorChar);
             for (int i = 0; i < chopped.Length; i++) {
                 temp.ReplacePath(chopped[i]);
                 for (int j = i + 1; j < chopped.Length; j++) {
                     temp.AppendPath(chopped[j]);
                 }
                 temp.EV = EnvironmentVariable.Drive;
                 return_me.AddRange(getPaths(temp));
                 temp.EV = EnvironmentVariable.AltSavePaths;
                 return_me.AddRange(getPaths(temp));
             }
             break;
         case EnvironmentVariable.AltSavePaths:
             foreach (AltPathHolder alt_path in Core.settings.save_paths) {
                 if (PermissionsHelper.isReadable(alt_path.path)) {
                     if (get_me.Path != null && get_me.Path.Length > 0)
                         test = new DirectoryInfo(Path.Combine(alt_path.path, get_me.Path));
                     else
                         test = new DirectoryInfo(alt_path.path);
                     if (test.Exists) {
                         DetectedLocations locs = Core.locations.interpretPath(alt_path.path, get_me.Path);
                         foreach (DetectedLocationPathHolder loc in locs) {
                             return_me.Add(loc);
                         }
                     }
                 }
             }
             break;
         case EnvironmentVariable.Drive:
             foreach (string drive in drives) {
                 if (get_me.Path != null && get_me.Path.Length > 0)
                     test = new DirectoryInfo(Path.Combine(drive, get_me.Path));
                 else
                     test = new DirectoryInfo(drive);
                 if (test.Exists) {
                     add_me = new DetectedLocationPathHolder(get_me, drive, null);
                     return_me.Add(add_me);
                 }
             }
             break;
         default:
             return base.getPaths(get_me);
     }
     return return_me;
 }
Exemple #4
0
        protected string censorDirectory(DirectoryInfo dir)
        {
            DetectedLocations paths = Core.locations.interpretPath(dir.FullName.TrimEnd(Path.DirectorySeparatorChar));

            if (paths.Count == 0)
            {
                return(dir.FullName);
            }
            else
            {
                return(paths.getMostAccurateLocation().FullRelativeDirPath);
            }
        }
Exemple #5
0
        public DetectedLocations interpretPath(params string[] interpret_me)
        {
            if (interpret_me.Length == 0)
                throw new Exception("Not enough paths!");

            string path = interpret_me[0].TrimEnd(Path.DirectorySeparatorChar);
            for (int i = 1; i < interpret_me.Length; i++) {
                path = Path.Combine(path, interpret_me[i].TrimEnd(Path.DirectorySeparatorChar));
            }

            DetectedLocations return_me = new DetectedLocations();
            path = correctPath(path);
            if (path == null) {
                return return_me;
            }

            foreach (KeyValuePair<HandlerType, ALocationHandler> handler in handlers) {
                return_me.AddRange(handler.Value.interpretPath(path));
            }

            return return_me;
        }
Exemple #6
0
 public DetectedLocations getPaths(ALocation get_me)
 {
     DetectedLocations return_me = new DetectedLocations();
     foreach (KeyValuePair<HandlerType, ALocationHandler> handler in handlers) {
         return_me.AddRange(handler.Value.getPaths(get_me));
     }
     return return_me;
 }
        protected override DetectedLocations getPaths(LocationShortcut get_me)
        {
            FileInfo the_shortcut;
            //StringBuilder start_menu;
            DetectedLocations return_me = new DetectedLocations();
            String path;

            List<string> paths = this.getPaths(get_me.ev);
            the_shortcut = null;

            foreach (string check_me in paths) {
                the_shortcut = new FileInfo(Path.Combine(check_me, get_me.path));
                if (the_shortcut.Exists)
                    break;
            }

            if (the_shortcut != null && the_shortcut.Exists) {
                IWshRuntimeLibrary.WshShell shell = new IWshRuntimeLibrary.WshShell();
                IWshRuntimeLibrary.IWshShortcut link = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(the_shortcut.FullName);

                try {
                    path = Path.GetDirectoryName(link.TargetPath);
                    path = get_me.modifyPath(path);
                    return_me.AddRange(Core.locations.interpretPath(path));
                } catch { }
            }
            return return_me;
        }
        protected override DetectedLocations getPaths(LocationRegistry get_me)
        {
            DetectedLocations return_me = new DetectedLocations();

            RegistryHandler reg;

            // This handles if the root is a registry key
            if (get_me.Key != null) {
                reg = new RegistryHandler(get_me.Root, get_me.Key, false);

                if (reg.key_found) {
                    try {
                        string path;
                        if (get_me.Value == null)
                            path = reg.getValue("");
                        else
                            path = reg.getValue(get_me.Value);

                        if (path != null) {
                            if (path.Contains("/"))
                                path = path.Split('/')[0].Trim();

                            if (path.Contains("\""))
                                path = path.Trim('\"').Trim();

                            if (Path.HasExtension(path))
                                path = Path.GetDirectoryName(path);

                            path = get_me.modifyPath(path);
                            if (Directory.Exists(path)) {
                                return_me.AddRange(Core.locations.interpretPath(new DirectoryInfo(path).FullName));
                            }
                        }
                    } catch (Exception e) {
                        throw new TranslateableException("RegistryKeyLoadError", e);
                    }
                }
            }
            return return_me;
        }
        protected override DetectedLocations getPaths(LocationPath get_me)
        {
            //if(get_me.rel_root!= EnvironmentVariable.Public)
            // return new List<DetectedLocationPathHolder>();
            DetectedLocations return_me = new DetectedLocations();
            DetectedLocationPathHolder add_me;
            DirectoryInfo test;
            switch (get_me.EV) {
                case EnvironmentVariable.InstallLocation:
                    LocationPath temp = new LocationPath(get_me);
                    string[] chopped = temp.Path.Split(Path.DirectorySeparatorChar);
                    for (int i = 0; i < chopped.Length; i++) {
                        temp.ReplacePath(chopped[i]);
                        for (int j = i + 1; j < chopped.Length; j++) {
                            temp.AppendPath(chopped[j]);
                        }
                        temp.EV = EnvironmentVariable.ProgramFiles;
                        return_me.AddRange(getPaths(temp));
                    }
                    return_me.AddRange(base.getPaths(get_me));
                    break;
                case EnvironmentVariable.ProgramFiles:
                case EnvironmentVariable.ProgramFilesX86:
                    // Always checks both the VirtualStore and the real Program Files,
                    // to make sure nothing is missed, especially in the case of old games
                    // that may or may not use the VirtualStore
                    if (!get_me.override_virtual_store && platform_version == "WindowsVista") {
                        LocationPath virtualstore_info = new LocationPath(get_me);
                        virtualstore_info.EV = EnvironmentVariable.LocalAppData;

                        if (x64) {
                            virtualstore_info.ReplacePath(Path.Combine("VirtualStore", global.getFolder(EnvironmentVariable.ProgramFilesX86).BaseFolder.Substring(3), virtualstore_info.Path));
                            return_me.AddRange(getPaths(virtualstore_info));
                            virtualstore_info = new LocationPath(get_me);
                            virtualstore_info.EV = EnvironmentVariable.LocalAppData;
                        }
                        virtualstore_info.ReplacePath(Path.Combine("VirtualStore", global.getFolder(EnvironmentVariable.ProgramFiles).BaseFolder.Substring(3), virtualstore_info.Path));
                        return_me.AddRange(getPaths(virtualstore_info));
                    }

                    if (x64) {
                        if (get_me.Path != null && get_me.Path.Length > 0)
                            test = new DirectoryInfo(Path.Combine(global.getFolder(EnvironmentVariable.ProgramFilesX86).BaseFolder, get_me.Path));
                        else
                            test = new DirectoryInfo(global.getFolder(EnvironmentVariable.ProgramFilesX86).BaseFolder);
                        if (test.Exists) {
                            add_me = new DetectedLocationPathHolder(get_me, global.getFolder(EnvironmentVariable.ProgramFilesX86).BaseFolder, null);
                            return_me.Add(add_me);
                        }
                    }

                    if (get_me.Path != null && get_me.Path.Length > 0)
                        test = new DirectoryInfo(Path.Combine(global.getFolder(EnvironmentVariable.ProgramFiles).BaseFolder, get_me.Path));
                    else
                        test = new DirectoryInfo(global.getFolder(EnvironmentVariable.ProgramFiles).BaseFolder);

                    if (test.Exists) {
                        add_me = new DetectedLocationPathHolder(get_me, global.getFolder(EnvironmentVariable.ProgramFiles).BaseFolder, null);
                        return_me.Add(add_me);
                    }
                    break;
                default:
                    return base.getPaths(get_me);
            }
            return return_me;
        }
        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());
            }
        }