public static bool IsAndroidObbStructure(string path) { DirectoryInfo directory = new DirectoryInfo(DirectoryUtils.ToLongPath(path)); if (!directory.Exists) { return(false); } int match = GetRootAndroidDirectoryMatch(directory); if (match != 8) { return(false); } string dataPath = Path.Combine(path, AssetName, BinName, DataName); if (!DirectoryUtils.Exists(dataPath)) { return(false); } return(true); }
public AndroidGameStructure(FileCollection collection, string rootPath, string obbPath) : base(collection) { if (string.IsNullOrEmpty(rootPath)) { throw new ArgumentNullException(rootPath); } m_root = new DirectoryInfo(DirectoryUtils.ToLongPath(rootPath)); if (!m_root.Exists) { throw new Exception($"Root directory '{rootPath}' doesn't exist"); } string apkDataPath = Path.Combine(rootPath, AssetName, BinName, DataName); DirectoryInfo apkDataDirectory = new DirectoryInfo(DirectoryUtils.ToLongPath(apkDataPath)); if (!apkDataDirectory.Exists) { throw new Exception($"Data directory hasn't been found"); } List <string> dataPathes = new List <string>() { apkDataPath }; DirectoryInfo obbDataDirectory = null; if (obbPath != null) { m_obbRoot = new DirectoryInfo(DirectoryUtils.ToLongPath(obbPath)); if (!m_obbRoot.Exists) { throw new Exception($"Obb directory '{obbPath}' doesn't exist"); } string obbDataPath = Path.Combine(obbPath, AssetName, BinName, DataName); if (!DirectoryUtils.Exists(obbDataPath)) { throw new Exception($"Obb data directory '{obbDataPath}' hasn't beed found"); } dataPathes.Add(obbDataPath); } DataPathes = dataPathes.ToArray(); Dictionary <string, string> files = new Dictionary <string, string>(); CollectGameFiles(apkDataDirectory, files); if (obbDataDirectory != null) { CollectGameFiles(obbDataDirectory, files); } CollectApkAssetBundles(files); Files = files; Dictionary <string, string> assemblies = new Dictionary <string, string>(); CollectMainAssemblies(apkDataDirectory, assemblies); Assemblies = assemblies; SetScriptingBackend(); }
public static bool IsWebGLStructure(string path) { DirectoryInfo root = new DirectoryInfo(DirectoryUtils.ToLongPath(path)); if (!root.Exists) { return(false); } foreach (FileInfo fi in root.EnumerateFiles()) { if (fi.Extension == HtmlExtension) { foreach (DirectoryInfo di in root.EnumerateDirectories()) { switch (di.Name) { case DevelopmentName: { foreach (FileInfo file in di.EnumerateFiles()) { if (file.Extension == DataExtension) { return(true); } } } break; case ReleaseName: { foreach (FileInfo file in di.EnumerateFiles()) { if (file.Extension == DataGzExtension) { return(true); } } } break; case BuildName: { foreach (FileInfo file in di.EnumerateFiles()) { if (file.Name.EndsWith(DataWebExtension, StringComparison.Ordinal)) { return(true); } } } break; } } return(false); } } return(false); }
public static bool IsMacStructure(string path) { DirectoryInfo dinfo = new DirectoryInfo(DirectoryUtils.ToLongPath(path)); if (!dinfo.Exists) { return(false); } if (!dinfo.Name.EndsWith(AppExtension, StringComparison.Ordinal)) { return(false); } string dataPath = Path.Combine(dinfo.FullName, ContentsName, DataFolderName); if (!Directory.Exists(dataPath)) { return(false); } string resourcePath = Path.Combine(dinfo.FullName, ContentsName, ResourcesName); if (!Directory.Exists(resourcePath)) { return(false); } return(true); }
public PCGameStructure(string rootPath) { if (string.IsNullOrEmpty(rootPath)) { throw new ArgumentNullException(rootPath); } m_root = new DirectoryInfo(DirectoryUtils.ToLongPath(rootPath)); if (!m_root.Exists) { throw new Exception($"Directory '{rootPath}' doesn't exist"); } if (!GetDataPCDirectory(m_root, out string dataPath, out string name)) { throw new Exception($"Data directory hasn't been found"); } Name = name; DataPathes = new string[] { dataPath }; DirectoryInfo dataDirectory = new DirectoryInfo(DirectoryUtils.ToLongPath(dataPath)); Dictionary <string, string> files = new Dictionary <string, string>(); CollectGameFiles(dataDirectory, files); CollectStreamingAssets(dataDirectory, files); Files = files; Dictionary <string, string> assemblies = new Dictionary <string, string>(); CollectMainAssemblies(dataDirectory, assemblies); Assemblies = assemblies; }
public WebPlayerStructure(string rootPath) { if (string.IsNullOrEmpty(rootPath)) { throw new ArgumentNullException(rootPath); } m_root = new DirectoryInfo(DirectoryUtils.ToLongPath(rootPath)); if (!m_root.Exists) { throw new Exception($"Directory '{rootPath}' doesn't exist"); } if (!GetWebPlayerName(m_root, out string name)) { throw new Exception($"Web player asset bundle data hasn't been found"); } Name = name; DataPathes = new string[] { rootPath }; Dictionary <string, string> files = new Dictionary <string, string>(); string abPath = Path.Combine(m_root.FullName, Name + AssetBundleExtension); files.Add(Name, abPath); CollectStreamingAssets(m_root, files); Files = files; Dictionary <string, string> assemblies = new Dictionary <string, string>(); CollectMainAssemblies(m_root, assemblies); Assemblies = assemblies; }
public MixedGameStructure(IEnumerable <string> pathes) { Dictionary <string, string> files = new Dictionary <string, string>(); Dictionary <string, string> assemblies = new Dictionary <string, string>(); HashSet <string> dataPathes = new HashSet <string>(); foreach (string path in SelectUniquePathes(pathes)) { if (MultiFileStream.Exists(path)) { string name = MultiFileStream.GetFileName(path); AddFile(files, name, path); string directory = Path.GetDirectoryName(path); dataPathes.Add(directory); } else if (DirectoryUtils.Exists(path)) { DirectoryInfo directory = new DirectoryInfo(DirectoryUtils.ToLongPath(path)); CollectFromDirectory(directory, files, assemblies, dataPathes); } else { throw new Exception($"Neither file nor directory at '{path}' exists"); } } DataPathes = dataPathes.ToArray(); Files = files; Assemblies = assemblies; Name = Files.Count == 0 ? string.Empty : Files.First().Key; }
public static string GetUniqueName(string dirPath, string fileName, int maxNameLength) { string ext = null; string name = null; int maxLength = maxNameLength - 4; string validFileName = fileName; if (validFileName.Length > maxLength) { ext = Path.GetExtension(validFileName); name = Path.GetFileNameWithoutExtension(validFileName).Substring(0, maxLength - ext.Length); validFileName = name + ext; } dirPath = DirectoryUtils.ToLongPath(dirPath); if (!Directory.Exists(dirPath)) { return(validFileName); } string filePath = ToLongPath(Path.Combine(dirPath, validFileName)); if (!File.Exists(filePath)) { return(validFileName); } ext = ext ?? Path.GetExtension(validFileName); name = name ?? Path.GetFileNameWithoutExtension(validFileName); string escapedName = Regex.Escape(name); List <string> files = new List <string>(); DirectoryInfo dirInfo = new DirectoryInfo(DirectoryUtils.ToLongPath(dirPath, true)); Regex regex = new Regex($@"(?i)^{escapedName}(_[\d]+)?\.[^\.]+$"); foreach (FileInfo fileInfo in dirInfo.EnumerateFiles($"{name}_*{ext}")) { if (regex.IsMatch(fileInfo.Name)) { files.Add(fileInfo.Name.ToLower()); } } if (files.Count == 0) { return($"{name}_0{ext}"); } string lowName = name.ToLower(); for (int i = 1; i < int.MaxValue; i++) { string newName = $"{lowName}_{i}."; if (files.All(t => !t.StartsWith(newName, StringComparison.Ordinal))) { return($"{name}_{i}{ext}"); } } throw new Exception($"Can't generate unique name for file {fileName} in directory {dirPath}"); }
public static bool IsPCStructure(string path) { DirectoryInfo dinfo = new DirectoryInfo(DirectoryUtils.ToLongPath(path)); if (!dinfo.Exists) { return(false); } return(IsRootPCDirectory(dinfo)); }
public static bool IsiOSStructure(string path) { DirectoryInfo root = new DirectoryInfo(DirectoryUtils.ToLongPath(path)); if (!root.Exists) { return(false); } return(GetDataiOSDirectory(root, out string _, out string _)); }
public static bool IsWebPlayerStructure(string path) { DirectoryInfo dinfo = new DirectoryInfo(DirectoryUtils.ToLongPath(path)); if (!dinfo.Exists) { return(false); } return(GetWebPlayerName(dinfo, out string _)); }
public static bool IsSwitchStructure(string path) { DirectoryInfo rootInfo = new DirectoryInfo(DirectoryUtils.ToLongPath(path)); if (!rootInfo.Exists) { return(false); } if (!DirectoryUtils.Exists(Path.Combine(rootInfo.FullName, ExecutableName))) { return(false); } return(GetDataSwitchDirectory(rootInfo, out string _)); }
public MacGameStructure(FileCollection collection, string rootPath) : base(collection) { if (string.IsNullOrEmpty(rootPath)) { throw new ArgumentNullException(rootPath); } m_root = new DirectoryInfo(DirectoryUtils.ToLongPath(rootPath)); if (!m_root.Exists) { throw new Exception($"Directory '{rootPath}' doesn't exist"); } Name = m_root.Name.Substring(0, m_root.Name.Length - AppExtension.Length); string dataPath = Path.Combine(m_root.FullName, ContentsName, DataName); if (!Directory.Exists(dataPath)) { throw new Exception("Data directory hasn't been found"); } string resourcePath = Path.Combine(m_root.FullName, ContentsName, ResourcesName); if (!Directory.Exists(resourcePath)) { throw new Exception("Resources directory hasn't been found"); } DataPathes = new string[] { dataPath, resourcePath }; DirectoryInfo dataDirectory = new DirectoryInfo(DirectoryUtils.ToLongPath(dataPath)); Dictionary <string, string> files = new Dictionary <string, string>(); CollectGameFiles(dataDirectory, files); CollectStreamingAssets(dataDirectory, files); Files = files; Dictionary <string, string> assemblies = new Dictionary <string, string>(); CollectMainAssemblies(dataDirectory, assemblies); Assemblies = assemblies; SetScriptingBackend(); }
public static string GetUniqueName(string dirPath, string fileName, int maxNameLength) { string ext = null; string name = null; int maxLength = maxNameLength - 4; string validFileName = fileName; if (validFileName.Length > maxLength) { ext = Path.GetExtension(validFileName); name = validFileName.Substring(0, maxLength - ext.Length); validFileName = name + ext; } dirPath = DirectoryUtils.ToLongPath(dirPath); if (!Directory.Exists(dirPath)) { return(validFileName); } name = name ?? Path.GetFileNameWithoutExtension(validFileName); if (!IsReservedName(name)) { string filePath = ToLongPath(Path.Combine(dirPath, validFileName)); if (!File.Exists(filePath)) { return(validFileName); } } ext = ext ?? Path.GetExtension(validFileName); for (int counter = 0; counter < int.MaxValue; counter++) { string proposedName = $"{name}_{counter}{ext}"; if (!File.Exists(Path.Combine(dirPath, proposedName))) { return(proposedName); } } throw new Exception($"Can't generate unique name for file {fileName} in directory {dirPath}"); }
public MixedGameStructure(FileCollection collection, IEnumerable <string> pathes) : base(collection) { Dictionary <string, string> files = new Dictionary <string, string>(); Dictionary <string, string> assemblies = new Dictionary <string, string>(); HashSet <string> dataPathes = new HashSet <string>(); foreach (string path in pathes) { if (FileMultiStream.Exists(path)) { string name = FileMultiStream.GetFileName(path); files.Add(name, path); string directory = Path.GetDirectoryName(path); dataPathes.Add(directory); } else if (DirectoryUtils.Exists(path)) { DirectoryInfo directory = new DirectoryInfo(DirectoryUtils.ToLongPath(path)); CollectFromDirectory(directory, files, assemblies, dataPathes); } else { throw new Exception($"Neither file nor directory at '{path}' exists"); } } if (files.Count == 0) { throw new Exception("No files has been found"); } DataPathes = dataPathes.ToArray(); Files = files; Assemblies = assemblies; SetScriptingBackend(); Name = Files.First().Key; }
public WebGLStructure(FileCollection collection, string rootPath) : base(collection) { if (string.IsNullOrEmpty(rootPath)) { throw new ArgumentNullException(rootPath); } m_root = new DirectoryInfo(DirectoryUtils.ToLongPath(rootPath)); if (!m_root.Exists) { throw new Exception($"Directory '{rootPath}' doesn't exist"); } Dictionary <string, string> files = new Dictionary <string, string>(); string buildPath = Path.Combine(m_root.FullName, BuildName); if (Directory.Exists(buildPath)) { DirectoryInfo buildDirectory = new DirectoryInfo(buildPath); foreach (FileInfo file in buildDirectory.EnumerateFiles()) { if (file.Name.EndsWith(DataWebExtension, StringComparison.Ordinal)) { Name = file.Name.Substring(0, file.Name.Length - DataWebExtension.Length); files.Add(Name, file.FullName); break; } } DataPathes = new string[] { rootPath, buildPath }; } else { string developmentPath = Path.Combine(m_root.FullName, DevelopmentName); if (Directory.Exists(developmentPath)) { DirectoryInfo buildDirectory = new DirectoryInfo(developmentPath); foreach (FileInfo file in buildDirectory.EnumerateFiles()) { if (file.Extension == DataExtension) { Name = file.Name.Substring(0, file.Name.Length - DataExtension.Length); files.Add(Name, file.FullName); break; } } DataPathes = new string[] { rootPath, developmentPath }; } else { string releasePath = Path.Combine(m_root.FullName, ReleaseName); if (Directory.Exists(releasePath)) { DirectoryInfo buildDirectory = new DirectoryInfo(releasePath); foreach (FileInfo file in buildDirectory.EnumerateFiles()) { if (file.Extension == DataGzExtension) { Name = file.Name.Substring(0, file.Name.Length - DataGzExtension.Length); files.Add(Name, file.FullName); break; } } DataPathes = new string[] { rootPath, releasePath }; } else { throw new Exception("Build directory hasn't been found"); } } } if (files.Count == 0) { throw new Exception("No files has been found"); } CollectStreamingAssets(m_root, files); Files = files; Assemblies = new Dictionary <string, string>(); //m_fileCollection.AssemblyManager.ScriptingBackEnd = ScriptingBackEnd.Il2Cpp; }
public static string GetUniqueName(string dirPath, string fileName, int maxNameLength) { string ext = null; string name = null; int maxLength = maxNameLength - 4; string validFileName = fileName; if (validFileName.Length > maxLength) { ext = Path.GetExtension(validFileName); name = Path.GetFileNameWithoutExtension(validFileName).Substring(0, maxLength - ext.Length); validFileName = name + ext; } dirPath = DirectoryUtils.ToLongPath(dirPath); if (!Directory.Exists(dirPath)) { return(validFileName); } string filePath = ToLongPath(Path.Combine(dirPath, validFileName)); if (!File.Exists(filePath)) { return(validFileName); } ext = ext ?? Path.GetExtension(validFileName); name = name ?? Path.GetFileNameWithoutExtension(validFileName); string escapedName = Regex.Escape(name); List <string> files = new List <string>(); DirectoryInfo dirInfo = new DirectoryInfo(dirPath); /* MRH - this line was causing the error below. * DirectoryInfo dirInfo = new DirectoryInfo(DirectoryUtils.ToLongPath(dirPath, true)); * - think this fix is okay because dirPath is set to the "ToLongPath()" about 16 code lines above * * error: System.ArgumentException: Illegal characters in path. * at System.Security.Permissions.FileIOPermission.EmulateFileIOPermissionChecks(String fullPath) * at System.IO.DirectoryInfo.Init(String path, Boolean checkHost) * at uTinyRipper.FileUtils.GetUniqueName(String dirPath, String fileName, Int32 maxNameLength) in * C:\Users\Maha\source\repos\UtinyRipper\uTinyRipperCore\Utils\FileUtils.cs:line 145 */ Regex regex = new Regex($@"(?i)^{escapedName}(_[\d]+)?\.[^\.]+$"); foreach (FileInfo fileInfo in dirInfo.EnumerateFiles($"{name}_*{ext}")) { if (regex.IsMatch(fileInfo.Name)) { files.Add(fileInfo.Name.ToLower()); } } if (files.Count == 0) { return($"{name}_0{ext}"); } string lowName = name.ToLower(); for (int i = 1; i < int.MaxValue; i++) { string newName = $"{lowName}_{i}."; if (files.All(t => !t.StartsWith(newName, StringComparison.Ordinal))) { return($"{name}_{i}{ext}"); } } throw new Exception($"Can't generate unique name for file {fileName} in directory {dirPath}"); }