private void loadDirectory(XmlElement dir, Game game) { XmlElement path = null, reg = null; string include = null, exclude = null; foreach (XmlElement ele in dir.ChildNodes) { switch (ele.Name) { case "path": path = ele; break; case "include": include = ele.InnerText; break; case "exclude": exclude = ele.InnerText; break; case "reg": reg = ele; break; default: throw new NotSupportedException(ele.Name); } } string specialpath = path.Attributes["specialpath"].Value; ALocation loc = null; EnvironmentVariable ev = EnvironmentVariable.None; RegRoot reg_root = RegRoot.none; string reg_key = null; string reg_value = null; string rel_path = path.InnerText; bool linkable = false; bool needs_file_path = false; switch (specialpath) { case "%REGISTRY%": reg_root = getRegRoot(reg); reg_key = getRegKey(reg); reg_value = getRegValue(reg); break; case "%APPDATA%": ev = EnvironmentVariable.AppData; linkable = true; break; case "%DOCUMENTS%": ev = EnvironmentVariable.UserDocuments; linkable = true; break; case "%APPDATA_COMMON%": ev = EnvironmentVariable.CommonApplicationData; linkable = true; break; case "%APPDATA_LOCAL%": ev = EnvironmentVariable.LocalAppData; linkable = true; break; case "%SAVED_GAMES%": ev = EnvironmentVariable.SavedGames; linkable = true; break; case "%USER_PROFILE%": ev = EnvironmentVariable.UserProfile; linkable = true; break; case "%SHARED_DOCUMENTS%": ev = EnvironmentVariable.Public; rel_path = System.IO.Path.Combine("Documents",rel_path); linkable = true; break; case "%STEAM_CLOUD%": ev = EnvironmentVariable.SteamUserData; break; case "%STEAM_CACHE%": ev = EnvironmentVariable.SteamUser; linkable = true; break; case "%STEAM%": if (rel_path.ToLower().StartsWith(@"steamapps\common\")) { ev = EnvironmentVariable.SteamCommon; rel_path = rel_path.Substring(17).Trim(System.IO.Path.DirectorySeparatorChar); } else if (rel_path.ToLower().StartsWith(@"steamapps\sourcemods\")) { ev = EnvironmentVariable.SteamSourceMods; rel_path = rel_path.Substring(21).Trim(System.IO.Path.DirectorySeparatorChar); } else { throw new NotSupportedException(rel_path); } linkable = true; needs_file_path = true; break; case "%UPLAY%": ev = EnvironmentVariable.UbisoftSaveStorage; break; case "": ev = EnvironmentVariable.Drive; rel_path = rel_path.Substring(Path.GetPathRoot(rel_path).Length); linkable = true; needs_file_path = true; break; default: throw new NotSupportedException(specialpath); } GameVersion version; String path_prepend = null; rel_path = correctPath(rel_path); if(ev!= EnvironmentVariable.None) { switch (ev) { case EnvironmentVariable.AppData: case EnvironmentVariable.UserDocuments: case EnvironmentVariable.CommonApplicationData: case EnvironmentVariable.Public: case EnvironmentVariable.SteamCommon: case EnvironmentVariable.SavedGames: case EnvironmentVariable.LocalAppData: case EnvironmentVariable.UserProfile: case EnvironmentVariable.SteamUser: case EnvironmentVariable.SteamSourceMods: if(!game.hasVersion("Windows",null,null)) game.addVersion("Windows",null,null); version = game.getVersion("Windows",null,null); break; case EnvironmentVariable.SteamUserData: if (!game.hasVersion(null, "SteamCloud", null)) game.addVersion(null, "SteamCloud", null); version = game.getVersion(null, "SteamCloud", null); break; case EnvironmentVariable.UbisoftSaveStorage: if (!game.hasVersion(null, "UbisoftSaveStorage", null)) game.addVersion(null, "UbisoftSaveStorage", null); version = game.getVersion(null, "UbisoftSaveStorage", null); break; default: throw new NotSupportedException(ev.ToString()); } switch (ev) { case EnvironmentVariable.SteamUser: case EnvironmentVariable.SteamCommon: case EnvironmentVariable.SteamSourceMods: case EnvironmentVariable.SteamUserData: if (rel_path.Contains('\\')) { int index = rel_path.IndexOf('\\'); path_prepend = rel_path.Substring(index+1); rel_path = rel_path.Substring(0, index); } break; } loc = new LocationPath(version.Locations,ev, rel_path); } else { if(!game.hasVersion("Windows",null,null)) game.addVersion("Windows",null,null); version = game.getVersion("Windows",null,null); loc = new LocationRegistry(version.Locations, reg_root.ToString(), correctReg(reg_key), reg_value); if (rel_path != null && rel_path != "") path_prepend = correctPath(rel_path); } version.addLocation(loc); FileType type = version.addFileType(null); foreach (string inc in include.Split('|')) { Include save; string add_path = null; if (needs_file_path) add_path = ""; if (path_prepend != null) { add_path = path_prepend; } string file = correctPath(inc); if (file.Contains('\\')) { string[] splits = file.Split('\\'); for (int i = 0; i < splits.Length; i++) { if (i < splits.Length - 1) { if (add_path != null) add_path = Path.Combine(add_path, splits[i]); else add_path = splits[i]; } else { file = splits[i]; } } } if (file == "*.*"||file=="*") { save = type.addSave(add_path, null); } else { save = type.addSave(add_path, file); } foreach (string exc in exclude.Split('|')) { if (exc != "") { save.addExclusion(add_path, exc); } } } if (linkable) { if(path_prepend!=null) { version.addLink(path_prepend); }else if (needs_file_path) { version.addLink(""); } else version.addLink(null); } version.addContributor("GameSaveManager"); }
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; }