public override void Initialize() { // Global ubisoft save location DirectoryInfo ubisoft_save = null; RegistryHandler ubi_reg = new RegistryHandler("local_machine", @"SOFTWARE\Ubisoft\Launcher", false); if (!ubi_reg.key_found) { ubi_reg = new RegistryHandler("local_machine", @"SOFTWARE\Wow6432Node\Ubisoft\Launcher", false); } if (!String.IsNullOrEmpty(ubi_reg.getValue("InstallDir")) && Directory.Exists(Path.Combine(ubi_reg.getValue("InstallDir"), "savegames"))) { ubisoft_save = new DirectoryInfo(Path.Combine(ubi_reg.getValue("InstallDir"), "savegames")); } else if (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("ProgramW6432")) && Directory.Exists(Path.Combine(Environment.GetEnvironmentVariable("ProgramW6432"), "Ubisoft", "Ubisoft Game Launcher"))) { ubisoft_save = new DirectoryInfo(Path.Combine(Environment.GetEnvironmentVariable("ProgramW6432"), "Ubisoft", "Ubisoft Game Launcher", "savegames")); } else if (Directory.Exists(Path.Combine(Environment.GetEnvironmentVariable("PROGRAMFILES"), "Ubisoft", "Ubisoft Game Launcher"))) { ubisoft_save = new DirectoryInfo(Path.Combine(Environment.GetEnvironmentVariable("PROGRAMFILES"), "Ubisoft", "Ubisoft Game Launcher", "savegames")); } if (ubisoft_save != null && ubisoft_save.Exists) { this.AddPath(EnvironmentVariable.UbisoftSaveStorage, ubisoft_save.FullName); //this.AddPath(EnvironmentVariable.UbisoftSaveStorage, ubisoft_save, true); } // Per-user? //DirectoryInfo ubisoft_save = new DirectoryInfo(Path.Combine(add_me.getFolder(EnvironmentVariable.LocalAppData).BaseFolder, @"Ubisoft Game Launcher\savegame_storage")); //if (ubisoft_save.Exists) { // add_me.setEvFolder(EnvironmentVariable.UbisoftSaveStorage, ubisoft_save); //} }
protected override void resetSteamPath() { string reg_path = null, set_path = null; RegistryHandler steam = new RegistryHandler(RegRoot.local_machine,"SOFTWARE\\Valve\\Steam",false); reg_path = isSteamPath(steam.getValue("InstallPath")); set_path = isSteamPath(Core.settings.steam_override); if(set_path!=null) path = set_path; else if(reg_path!=null) path = reg_path; else path = null; if (path!=null) { DirectoryInfo read_me = new DirectoryInfo(Path.Combine(path,"steamapps")); DirectoryInfo[] read_us; if(read_me.Exists) { read_us = read_me.GetDirectories(); foreach(DirectoryInfo subDir in read_us) { if(subDir.Name.ToLower()!="common"&&subDir.Name.ToLower()!="sourcemods"&&subDir.Name.ToLower()!="media") { setUserEv(subDir.Name,EnvironmentVariable.SteamUser,subDir.FullName); } } steam_apps_path = read_me.FullName; DirectoryInfo common_folder = new DirectoryInfo(Path.Combine(steam_apps_path,"common")); if(common_folder.Exists) global.setEvFolder(EnvironmentVariable.SteamCommon,common_folder.FullName); DirectoryInfo source_mods = new DirectoryInfo(Path.Combine(steam_apps_path,"SourceMods")); if(source_mods.Exists) global.setEvFolder(EnvironmentVariable.SteamSourceMods,source_mods.FullName); } read_me = new DirectoryInfo(Path.Combine(path,"userdata")); if(read_me.Exists) { read_us = read_me.GetDirectories(); foreach(DirectoryInfo subDir in read_us) { setUserEv(subDir.Name,EnvironmentVariable.SteamUserData,subDir.FullName); } userdata_path = read_me.FullName; } } else { userdata_path = null; steam_apps_path = null; } }
protected override void resetSteamPath() { string reg_path = null, set_path = null; RegistryHandler steam = new RegistryHandler("local_machine", "SOFTWARE\\Valve\\Steam", false); reg_path = isSteamPath(steam.getValue("InstallPath")); set_path = isSteamPath(Core.settings.steam_override); if (set_path != null) path = set_path; else if (reg_path != null) path = reg_path; else path = null; if (path != null) { DirectoryInfo read_me = new DirectoryInfo(Path.Combine(path, "steamapps")); // Loads the steam isntall path folders loadSteamPaths(read_me); // Loads the alt steam library folders if (File.Exists(Path.Combine(path, "config", "config.vdf"))) { config_file = new SteamConfigFile(Path.Combine(path, "config", "config.vdf")); foreach (string folder in config_file.BaseInstallFolders) { read_me = new DirectoryInfo(Path.Combine(folder, "SteamApps")); loadSteamPaths(read_me); } } // Loads the steam cloud folders read_me = new DirectoryInfo(Path.Combine(path, "userdata")); if (read_me.Exists) { DirectoryInfo[] read_us; read_us = read_me.GetDirectories(); foreach (DirectoryInfo subDir in read_us) { setUserEv(subDir.Name, EnvironmentVariable.SteamUserData, subDir.FullName); } userdata_path = read_me.FullName; } } else { userdata_path = null; steam_apps_path = null; } }
public MonitorHandler() : base("") { if(!Core.all_users_mode) { if(File.Exists(Core.programs.monitor)) { monitor_found = true; monitor_path = Core.programs.monitor; } else { monitor_found = false; } } else { monitor_found = false; } RegistryHandler reg = new RegistryHandler(RegRoot.current_user,@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run",false); if (reg.getValue("MASGAUMonitor")!=null) monitor_enabled = true; else monitor_enabled = false; }
public SystemLocationHandler() : base() { // The global variables if (Environment.GetEnvironmentVariable("ProgramW6432") != null) { global.setEvFolder(EnvironmentVariable.ProgramFiles, Environment.GetEnvironmentVariable("ProgramW6432")); global.setEvFolder(EnvironmentVariable.ProgramFilesX86, Environment.GetEnvironmentVariable("PROGRAMFILES(X86)")); } else { global.setEvFolder(EnvironmentVariable.ProgramFiles, Environment.GetEnvironmentVariable("PROGRAMFILES")); //global.setEvFolder(EnvironmentVariable.ProgramFilesX86,Environment.GetEnvironmentVariable("PROGRAMFILES")); } if (Environment.GetEnvironmentVariable("LOCALAPPDATA") != null) { xp = false; } else { xp = true; } if (xp) platform_version = "WindowsXP"; else platform_version = "WindowsVista"; global.setEvFolder(EnvironmentVariable.StartMenu, Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu)); // Not really used //common_program_files = Environment.GetEnvironmentVariable("COMMONPROGRAMFILES"); foreach (DriveInfo look_here in DriveInfo.GetDrives()) { if (look_here.IsReady && (look_here.DriveType == DriveType.Fixed || look_here.DriveType == DriveType.Removable)) { drives.Add(look_here.Name); } } //host_name = Environment.GetEnvironmentVariable("COMPUTERNAME"); global.setEvFolder(EnvironmentVariable.AllUsersProfile, Environment.GetEnvironmentVariable("ALLUSERSPROFILE")); if (platform_version == "WindowsVista") global.setEvFolder(EnvironmentVariable.Public, Environment.GetEnvironmentVariable("PUBLIC")); global.setEvFolder(EnvironmentVariable.CommonApplicationData, Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)); if (!xp) { RegistryHandler uac_status = new RegistryHandler("local_machine", @"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System", false); if (uac_status.getValue("EnableLUA") == "1") { uac_enabled = true; } } string[] split = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).Split(Path.DirectorySeparatorChar); StringBuilder user_root = new StringBuilder(split[0]); if (xp) { for (int i = 1; i < split.Length - 2; i++) { user_root.Append(Path.DirectorySeparatorChar + split[i]); } } else { for (int i = 1; i < split.Length - 3; i++) { user_root.Append(Path.DirectorySeparatorChar + split[i]); } } // Global ubisoft save location DirectoryInfo ubisoft_save = null; RegistryHandler ubi_reg = new RegistryHandler("local_machine", @"SOFTWARE\Ubisoft\Launcher", false); if (!ubi_reg.key_found) { ubi_reg = new RegistryHandler("local_machine", @"SOFTWARE\Wow6432Node\Ubisoft\Launcher", false); } if (ubi_reg.getValue("InstallDir") != null && Directory.Exists(Path.Combine(ubi_reg.getValue("InstallDir"), "savegames"))) { uac_enabled = true; ubisoft_save = new DirectoryInfo(Path.Combine(ubi_reg.getValue("InstallDir"), "savegames")); } else if (Environment.GetEnvironmentVariable("ProgramW6432") != null && Directory.Exists(Path.Combine(Environment.GetEnvironmentVariable("ProgramW6432"), "Ubisoft", "Ubisoft Game Launcher"))) { ubisoft_save = new DirectoryInfo(Path.Combine(Environment.GetEnvironmentVariable("ProgramW6432"), "Ubisoft", "Ubisoft Game Launcher", "savegames")); } else if (Directory.Exists(Path.Combine(Environment.GetEnvironmentVariable("PROGRAMFILES"), "Ubisoft", "Ubisoft Game Launcher"))) { ubisoft_save = new DirectoryInfo(Path.Combine(Environment.GetEnvironmentVariable("PROGRAMFILES"), "Ubisoft", "Ubisoft Game Launcher", "savegames")); } if (ubisoft_save != null && ubisoft_save.Exists) { global.setEvFolder(EnvironmentVariable.UbisoftSaveStorage, ubisoft_save, true); } //Per-user variables loadUsersData("current_user", null); if (Core.StaticAllUsersMode) { // All this crap lets me get data from other user's registries IntPtr token = new IntPtr(0); int retval = 0; TOKEN_PRIVILEGES TP = new TOKEN_PRIVILEGES(); TOKEN_PRIVILEGES TP2 = new TOKEN_PRIVILEGES(); LUID RestoreLuid = new LUID(); LUID BackupLuid = new LUID(); int return_length = 0; TOKEN_PRIVILEGES oldPriveleges = new TOKEN_PRIVILEGES(); System.Diagnostics.Process process = System.Diagnostics.Process.GetCurrentProcess(); //IntPtr hndle = GetModuleHandle(null); //retval = OpenProcessToken(hndle, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref token); retval = OpenProcessToken(process.Handle, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref token); retval = LookupPrivilegeValue(null, SE_RESTORE_NAME, ref RestoreLuid); TP.PrivilegeCount = 1; TP.Privileges.attributes = SE_PRIVILEGE_ENABLED; TP.Privileges.luid = RestoreLuid; retval = AdjustTokenPrivileges(token, 0, ref TP, TP.Size(), ref oldPriveleges, ref return_length); if (retval == 0) throw new TranslateableException("ProcessRestorePermissionError", retval.ToString()); retval = LookupPrivilegeValue(null, SE_BACKUP_NAME, ref BackupLuid); TP2.PrivilegeCount = 1; TP2.Privileges.attributes = SE_PRIVILEGE_ENABLED; TP2.Privileges.luid = BackupLuid; retval = AdjustTokenPrivileges(token, 0, ref TP2, TP2.Size(), ref oldPriveleges, ref return_length); if (retval == 0) throw new TranslateableException("ProcessBackupPermissionError", retval.ToString()); Console.WriteLine(retval); foreach (DirectoryInfo user_folder in new DirectoryInfo(user_root.ToString()).GetDirectories()) { if (user_folder.Name.ToLower() == "default user") continue; if (user_folder.Name.ToLower() == "default") continue; if (user_folder.Name.ToLower() == "all users") continue; string hive_file = Path.Combine(user_folder.FullName, "NTUSER.DAT"); if (!File.Exists(hive_file)) continue; int h = RegLoadKey(HKEY_USERS, user_folder.Name, hive_file); //int h = RegLoadAppKey(hive_file,out hKey, RegSAM.AllAccess,REG_PROCESS_APPKEY,0); if (h == 32) continue; if (h != 0) throw new TranslateableException("UserRegistryLoadError", user_folder.Name, h.ToString()); //sub_key = new RegistryHandler(hKey); //sub_key = new RegistryHandler(RegRoot.users,user_folder.Name,false); loadUsersData("users", user_folder.Name); string result = RegUnLoadKey(HKEY_USERS, user_folder.Name).ToString(); } } initialized = true; }
private void loadUsersData(string reg_root, string path) { RegistryHandler user_key; if (path == null) user_key = new RegistryHandler(reg_root, @"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", false); else user_key = new RegistryHandler(reg_root, path + @"\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", false); UserData add_me; string[] split; try { split = user_key.getValue("AppData").Split(Path.DirectorySeparatorChar); if (xp) add_me = new UserData(split[split.Length - 2]); else add_me = new UserData(split[split.Length - 3]); add_me.setEvFolder(EnvironmentVariable.AppData, user_key.getValue("AppData")); add_me.setEvFolder(EnvironmentVariable.Desktop, user_key.getValue("Desktop")); add_me.setEvFolder(EnvironmentVariable.StartMenu, user_key.getValue("Start Menu")); add_me.setEvFolder(EnvironmentVariable.LocalAppData, user_key.getValue("Local AppData")); //DirectoryInfo ubisoft_save = new DirectoryInfo(Path.Combine(add_me.getFolder(EnvironmentVariable.LocalAppData).BaseFolder, @"Ubisoft Game Launcher\savegame_storage")); //if (ubisoft_save.Exists) { // add_me.setEvFolder(EnvironmentVariable.UbisoftSaveStorage, ubisoft_save); //} DirectoryInfo flash_share = new DirectoryInfo(Path.Combine(add_me.getFolder(EnvironmentVariable.AppData).BaseFolder, @"Macromedia\Flash Player\#SharedObjects")); if (flash_share.Exists) { add_me.setEvFolder(EnvironmentVariable.FlashShared, flash_share, true); } //add_me.local_settings = user_key.GetValue("Local Settings").ToString(); //add_me.start_menu = user_key.getValue("Start Menu"); StringBuilder user_dir = new StringBuilder(split[0]); if (xp) { for (int i = 1; i < split.Length - 1; i++) { user_dir.Append(Path.DirectorySeparatorChar + split[i]); } } else { for (int i = 1; i < split.Length - 2; i++) { user_dir.Append(Path.DirectorySeparatorChar + split[i]); } } add_me.setEvFolder(EnvironmentVariable.UserProfile, user_dir.ToString()); add_me.setEvFolder(EnvironmentVariable.UserDocuments, user_key.getValue("Personal")); if (platform_version == "WindowsVista") add_me.setEvFolder(EnvironmentVariable.VirtualStore, Path.Combine(user_key.getValue("Local AppData"), "VirtualStore")); user_key.close(); if (path == null) user_key = new RegistryHandler(reg_root, @"Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", false); else user_key = new RegistryHandler(reg_root, path + @"\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", false); string saved_games = user_key.getValue("{4C5C32FF-BB9D-43B0-B5B4-2D72E54EAAA4}"); if (saved_games != null) { if (saved_games.StartsWith("%USERPROFILE%")) { saved_games = Path.Combine(user_dir.ToString(), saved_games.Substring(14)); } add_me.setEvFolder(EnvironmentVariable.SavedGames, saved_games); } else { if (Directory.Exists(Path.Combine(user_dir.ToString(), "Saved Games"))) { add_me.setEvFolder(EnvironmentVariable.SavedGames, Path.Combine(user_dir.ToString(), "Saved Games")); } } this.Add(add_me); user_key.close(); } catch (Exception) { return; } }
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; }
private void loadUsersData(string reg_root, string path) { RegistryHandler user_key; if (String.IsNullOrEmpty(path)) user_key = new RegistryHandler(reg_root, @"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", false); else user_key = new RegistryHandler(reg_root, path + @"\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", false); string user_name; string[] split; try { split = user_key.getValue("AppData").Split(Path.DirectorySeparatorChar); if (Version == WindowsVersion.WindowsXP) user_name = split[split.Length - 2]; else user_name = split[split.Length - 3]; this.AddPath(EnvironmentVariable.AppData, user_key.getValue("AppData"),user_name); this.AddPath(EnvironmentVariable.Desktop, user_key.getValue("Desktop"),user_name); this.AddPath(EnvironmentVariable.StartMenu, user_key.getValue("Start Menu"), user_name); this.AddPath(EnvironmentVariable.LocalAppData, user_key.getValue("Local AppData"), user_name); //add_me.local_settings = user_key.GetValue("Local Settings").ToString(); //add_me.start_menu = user_key.getValue("Start Menu"); StringBuilder user_dir = new StringBuilder(split[0]); if (Version== WindowsVersion.WindowsXP) { for (int i = 1; i < split.Length - 1; i++) { user_dir.Append(Path.DirectorySeparatorChar + split[i]); } } else { for (int i = 1; i < split.Length - 2; i++) { user_dir.Append(Path.DirectorySeparatorChar + split[i]); } } this.AddPath(EnvironmentVariable.UserProfile, user_dir.ToString(), user_name); this.AddPath(EnvironmentVariable.UserDocuments, user_key.getValue("Personal"), user_name); if (Version == WindowsVersion.WindowsVista) this.AddPath(EnvironmentVariable.VirtualStore, Path.Combine(user_key.getValue("Local AppData"), "VirtualStore"), user_name); user_key.close(); if (String.IsNullOrEmpty(path)) user_key = new RegistryHandler(reg_root, @"Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", false); else user_key = new RegistryHandler(reg_root, path + @"\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders", false); string saved_games = user_key.getValue("{4C5C32FF-BB9D-43B0-B5B4-2D72E54EAAA4}"); if (!String.IsNullOrEmpty(saved_games)) { if (saved_games.StartsWith("%USERPROFILE%")) { saved_games = Path.Combine(user_dir.ToString(), saved_games.Substring(14)); } this.AddPath(EnvironmentVariable.SavedGames, saved_games, user_name); } else { if (Directory.Exists(Path.Combine(user_dir.ToString(), "Saved Games"))) { this.AddPath(EnvironmentVariable.SavedGames, Path.Combine(user_dir.ToString(), "Saved Games"), user_name); } } user_key.close(); this.Users.Add(user_name); } catch (Exception) { return; } }
private void loadUsersData(RegRoot reg_root, string path) { RegistryHandler user_key; if(path==null) user_key = new RegistryHandler(reg_root,@"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders",false); else user_key = new RegistryHandler(reg_root,path + @"\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders",false); UserData add_me; string[] split ; try { split = user_key.getValue("AppData").Split(Path.DirectorySeparatorChar); if(xp) add_me = new UserData(split[split.Length-2]); else add_me = new UserData(split[split.Length-3]); add_me.setEvFolder(EnvironmentVariable.AppData,user_key.getValue("AppData")); DirectoryInfo flash_share = new DirectoryInfo(Path.Combine(add_me.getFolder(EnvironmentVariable.AppData),@"Macromedia\Flash Player\#SharedObjects")); if(flash_share.Exists) { DirectoryInfo[] flash_users = flash_share.GetDirectories(); switch(flash_users.Length) { case 0: break; case 1: add_me.setEvFolder(EnvironmentVariable.FlashShared,flash_users[0].FullName); break; default: add_me.setEvFolder(EnvironmentVariable.FlashShared,flash_users[0].FullName); break; } } add_me.setEvFolder(EnvironmentVariable.LocalAppData,user_key.getValue("Local AppData")); //add_me.local_settings = user_key.GetValue("Local Settings").ToString(); //add_me.start_menu = user_key.getValue("Start Menu"); StringBuilder user_dir = new StringBuilder(split[0]); if(xp) { for(int i = 1;i<split.Length-1;i++) { user_dir.Append(Path.DirectorySeparatorChar + split[i]); } } else { for(int i = 1;i<split.Length-2;i++) { user_dir.Append(Path.DirectorySeparatorChar + split[i]); } } add_me.setEvFolder(EnvironmentVariable.UserProfile,user_dir.ToString()); add_me.setEvFolder(EnvironmentVariable.UserDocuments,user_key.getValue("Personal")); if(platform_version== PlatformVersion.Vista) add_me.setEvFolder(EnvironmentVariable.VirtualStore,Path.Combine(user_key.getValue("Local AppData"),"VirtualStore")); user_key.close(); if(path==null) user_key = new RegistryHandler(reg_root,@"Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders",false); else user_key = new RegistryHandler(reg_root,path + @"\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders",false); string saved_games = user_key.getValue("{4C5C32FF-BB9D-43B0-B5B4-2D72E54EAAA4}"); if(saved_games!=null) { if(saved_games.StartsWith("%USERPROFILE%")) { saved_games = Path.Combine(user_dir.ToString(),saved_games.Substring(14)); } add_me.setEvFolder(EnvironmentVariable.SavedGames,saved_games); } else { if(Directory.Exists(Path.Combine(user_dir.ToString(), "Saved Games"))) { add_me.setEvFolder(EnvironmentVariable.SavedGames,Path.Combine(user_dir.ToString(), "Saved Games")); } } this.Add(add_me); user_key.close(); } catch { return; } }
protected override List<DetectedLocationPathHolder> getPaths(LocationRegistryHolder get_me) { List<DetectedLocationPathHolder> return_me = new List<DetectedLocationPathHolder>(); 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 MException("Error While Loading Registry Key", e.Message, e, false); } } } return return_me; }