public static IErrorResponse CheckValidInstallPath(AbsolutePath path, AbsolutePath?downloadFolder) { if (!path.Exists) { return(ErrorResponse.Success); } // Check folder does not have a Wabbajack ModList if (path.EnumerateFiles(false).Where(file => file.Exists).Any(file => file.Extension == Consts.ModListExtension)) { return(ErrorResponse.Fail($"Cannot install into a folder with a Wabbajack ModList inside of it")); } // Check if folder is empty if (path.IsEmptyDirectory) { return(ErrorResponse.Success); } // Check if folders indicative of a previous install exist var checks = new List <RelativePath>() { Consts.MO2ModFolderName, Consts.MO2ProfilesFolderName }; if (checks.All(c => path.Combine(c).Exists)) { return(ErrorResponse.Success); } // If we have a MO2 install, assume good to go if (path.EnumerateFiles(false).Any(file => { if (file.FileName == Consts.ModOrganizer2Exe) { return(true); } if (file.FileName == Consts.ModOrganizer2Ini) { return(true); } return(false); })) { return(ErrorResponse.Success); } // If we don't have a MO2 install, and there's any file that's not in the downloads folder, mark failure if (downloadFolder.HasValue && path.EnumerateFiles(true).All(file => file.InFolder(downloadFolder.Value))) { return(ErrorResponse.Success); } return(ErrorResponse.Fail($"Either delete everything except the downloads folder, or pick a new location. Cannot install to this folder as it has unexpected files.")); }
public static IErrorResponse CheckValidInstallPath(AbsolutePath path, AbsolutePath?downloadFolder) { if (!path.Exists) { return(ErrorResponse.Success); } // Check folder does not have a Wabbajack ModList if (path.EnumerateFiles(false).Where(file => file.Exists).Any(file => file.Extension == Consts.ModListExtension)) { return(ErrorResponse.Fail($"Cannot install into a folder with a Wabbajack ModList inside of it")); } // Check folder is either empty, or a likely valid previous install if (path.IsEmptyDirectory) { return(ErrorResponse.Success); } // If we have a MO2 install, assume good to go if (path.EnumerateFiles(false).Any(file => { if (file.FileName == Consts.ModOrganizer2Exe) { return(true); } if (file.FileName == Consts.ModOrganizer2Ini) { return(true); } return(false); })) { return(ErrorResponse.Success); } // If we don't have a MO2 install, and there's any file that's not in the downloads folder, mark failure if (downloadFolder.HasValue && path.EnumerateFiles(true).All(file => file.InFolder(downloadFolder.Value))) { return(ErrorResponse.Success); } return(ErrorResponse.Fail($"Cannot install to this folder as it has unknown files that could be deleted")); }
public static IErrorResponse CheckValidInstallPath(AbsolutePath path, AbsolutePath?downloadFolder, GameMetaData?game) { // Check if null path if (string.IsNullOrEmpty(path.ToString())) { return(ErrorResponse.Fail("Please select an install directory.")); } // Check if child of game folder if (game?.TryGetGameLocation() != null && path.IsChildOf(game.TryGetGameLocation())) { return(ErrorResponse.Fail("Cannot install to game directory.")); } // Check if child of Program Files var programFilesPath = KnownFolders.ProgramFiles.Path; if (programFilesPath != null) { if (path.IsChildOf(new AbsolutePath(programFilesPath))) { return(ErrorResponse.Fail("Cannot install to Program Files directory.")); } } // If the folder doesn't exist, it's empty so we don't need to check further if (!path.Exists) { return(ErrorResponse.Success); } // Check folder does not have a Wabbajack ModList if (path.EnumerateFiles(false).Where(file => file.Exists).Any(file => file.Extension == Consts.ModListExtension)) { return(ErrorResponse.Fail($"Cannot install into a folder with a Wabbajack ModList inside of it.")); } // Check if folder is empty if (path.IsEmptyDirectory) { return(ErrorResponse.Success); } // Check if folders indicative of a previous install exist var checks = new List <RelativePath>() { Consts.MO2ModFolderName, Consts.MO2ProfilesFolderName }; if (checks.All(c => path.Combine(c).Exists)) { return(ErrorResponse.Success); } // If we have a MO2 install, assume good to go if (path.EnumerateFiles(false).Any(file => { if (file.FileName == Consts.ModOrganizer2Exe) { return(true); } if (file.FileName == Consts.ModOrganizer2Ini) { return(true); } return(false); })) { return(ErrorResponse.Success); } // If we don't have a MO2 install, and there's any file that's not in the downloads folder, mark failure if (downloadFolder.HasValue && path.EnumerateFiles(true).All(file => file.InFolder(downloadFolder.Value))) { return(ErrorResponse.Success); } return(ErrorResponse.Fail($"Either delete everything except the downloads folder, or pick a new location. Cannot install to this folder as it has unexpected files.")); }