public override string getAbsoluteRoot(LocationPath parse_me, string user) { switch (parse_me.EV) { case EnvironmentVariable.Drive: if (parse_me is DetectedLocationPathHolder) { DetectedLocationPathHolder holder = (DetectedLocationPathHolder)parse_me; return(holder.AbsoluteRoot); } else { foreach (string drive in drives) { if (Directory.Exists(Path.Combine(drive, parse_me.Path))) { return(Path.Combine(drive, parse_me.Path)); } } return(null); } default: return(base.getAbsoluteRoot(parse_me, user)); } }
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"); } }
public IEnumerable <DetectedLocationPathHolder> createDetectedLocations(LocationPath loc, string owner) { List <DetectedLocationPathHolder> return_me = new List <DetectedLocationPathHolder>(); foreach (string folder in this.Keys) { DetectedLocationPathHolder add_me = new DetectedLocationPathHolder(loc.EV, this[folder], loc.Path, owner); return_me.Add(add_me); } return(return_me); }
//protected DetectedLocations filterLocations(DetectedLocations locs, ScummVM scumm, string user) { // List<string> keys = new List<string>(locs.Keys); // foreach (string key in keys) { // if (!filterLocation(locs[key], scumm, user)) { // locs.Remove(key); // } // } // return locs; //} protected bool filterLocation(DetectedLocationPathHolder loc, ScummVM scumm, string user) { DirectoryInfo dir = new DirectoryInfo(loc.FullDirPath); string pattern = scumm.Name + "*"; if (dir.GetFiles(pattern).Length > 0) { loc.owner = user; return(true); } return(false); }
public MonitorPath(GameEntry game, DetectedLocationPathHolder path) : base(path.FullDirPath, "*") { this.Path = path; this.Game = game; this.IncludeSubdirectories = true; this.Created += new FileSystemEventHandler(changed); this.Changed += new FileSystemEventHandler(changed); this.Deleted += new FileSystemEventHandler(changed); this.Renamed += new RenamedEventHandler(changed); }
public ArchiveID(GameID game, DetectedFile first_file) { this.Game = game; this.Owner = first_file.owner; this.Type = first_file.Type; DetectedLocationPathHolder loc = first_file.OriginalLocation; OriginalLocation = loc.FullDirPath; OriginalEV = loc.EV; OriginalRelativePath = loc.Path; }
public void restoreBackup(LocationPath path, string user, RunWorkerCompletedEventHandler when_done) { string target; if (path is ManualLocationPathHolder) { ManualLocationPathHolder loc = path as ManualLocationPathHolder; target = loc.ManualPath; } else if (path is DetectedLocationPathHolder) { DetectedLocationPathHolder loc = path as DetectedLocationPathHolder; target = loc.FullDirPath; } else { target = Core.locations.getAbsolutePath(path, user); } restoreBackup(target, when_done); }
public void addPathCandidate(LocationPath location) { // Checks if the provided path is the original archive path if (location is DetectedLocationPathHolder) { DetectedLocationPathHolder loc = location as DetectedLocationPathHolder; if (archive.id.OriginalLocation != null && archive.id.OriginalLocation.ToLower() == loc.FullDirPath.ToLower()) { loc.MatchesOriginalPath = true; } } // If path is a manuallly added path, we remove all other manual paths, // Then we don't compare further, since it doesn't matter if (location is ManualLocationPathHolder) { for (int i = 0; i < path_candidates.Count; i++) { if (path_candidates[i] is ManualLocationPathHolder) { path_candidates.RemoveAt(i); } } path_candidates.Insert(0, location); return; } if (location is DetectedLocationPathHolder) { // If the new path is a real, existant path DetectedLocationPathHolder loc = location as DetectedLocationPathHolder; for (int i = 0; i < path_candidates.Count; i++) { if (path_candidates[i] is DetectedLocationPathHolder) { // If the present path is a real, detected path DetectedLocationPathHolder path = path_candidates[i] as DetectedLocationPathHolder; // We compare the absolute paths if (path.FullDirPath.ToLower() == loc.FullDirPath.ToLower()) { // If it's two real, detected paths that are the same location, we compare EVs if (loc.EV > path.EV) { // If the new EV is better, then we replace the old one path_candidates.RemoveAt(i); path_candidates.AddWithSort(loc); } return; } else { // If the paths don't match, then we compare Ev-relative paths if (path.FullRelativeDirPath.ToLower() == loc.FullRelativeDirPath.ToLower()) { //if they're the same, then we compare for matching if (loc.MatchesOriginalPath) { path_candidates.RemoveAt(i); path_candidates.AddWithSort(loc); } return; } } } else { // If the existing path is an theoretical path path LocationPath path = path_candidates[i]; if (loc.FullRelativeDirPath.ToLower() == path.FullRelativeDirPath.ToLower()) { // If both paths are based on the same EV/path combo // Then the real path supercedes the fake path path_candidates.RemoveAt(i); path_candidates.AddWithSort(loc); return; } else { // Otherwise we don't do anything } } } } else { switch (location.EV) { case EnvironmentVariable.Drive: case EnvironmentVariable.ProgramFiles: case EnvironmentVariable.ProgramFilesX86: return; } // If the new path is only a theoretical path for (int i = 0; i < path_candidates.Count; i++) { LocationPath path = path_candidates[i]; if (path.FullRelativeDirPath.ToLower() == location.FullRelativeDirPath.ToLower()) { // If the relative paths match we compare the EVs for the more accurate one if (location.EV > path.EV) { // If the new path has a more accurate EV, we replace the old one path_candidates.RemoveAt(i); path_candidates.AddWithSort(location); } return; } else { // If the relative paths don't match, then they have nothign to do with eachother // so we'll just let the test continue } } } path_candidates.AddWithSort(location); return; }
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()); } }
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(test.FullName); 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); }
protected override void analyzerWork() { outputLine("Game Name: " + game.Title); this.path = game.DetectedLocations.getMostAccurateLocation(); if (path.EV == EnvironmentVariable.VirtualStore) { string drive = Path.GetPathRoot(path.FullDirPath); string new_path = Path.Combine(drive, path.Path); this.path = Core.locations.interpretPath(new_path).getMostAccurateLocation(); } string[] folders = this.path.Path.Split(System.IO.Path.DirectorySeparatorChar); string found_path = null; for (int i = folders.Length - 1; i >= 0; i--) { string temp_path = folders[0]; for (int j = 1; j <= i; j++) { temp_path = Path.Combine(temp_path, folders[j]); } DirectoryInfo dir = new DirectoryInfo(Path.Combine(path.AbsoluteRoot, temp_path)); if (dir.GetFiles("*.exe").Length > 0) { found_path = temp_path; break; } } if (found_path != null) { path.ReplacePath(found_path); } outputLine("Operating System: "); outputLine(Environment.OSVersion.VersionString); ProgressHandler.max += 4; outputLine(); outputLine("Path: "); outputPath(path.FullDirPath); outputLine(); try { scanForScumm(path.FullDirPath); } catch (Exception ex) { outputLine("Error while attempting to cehck for ScummVM path entries:"); recordException(ex); } try { TranslatingProgressHandler.setTranslatedMessage("DumpingFolder"); ProgressHandler.value++; outputLine(Environment.NewLine + "Folder Dump: "); travelFolder(path.FullDirPath); } catch (Exception ex) { outputLine("Error while attempting to search the save folder:"); recordException(ex); } }
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); } }
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); }