Example #1
0
        private static bool GetDataiOSDirectory(DirectoryInfo rootDirectory, out string dataPath, out string appName)
        {
            dataPath = null;
            appName  = null;

            string        payloadPath      = Path.Combine(rootDirectory.FullName, PayloadName);
            DirectoryInfo payloadDirectory = new DirectoryInfo(payloadPath);

            if (!payloadDirectory.Exists)
            {
                return(false);
            }

            foreach (DirectoryInfo dinfo in payloadDirectory.EnumerateDirectories())
            {
                if (dinfo.Name.EndsWith(AppExtension, StringComparison.Ordinal))
                {
                    appName  = dinfo.Name.Substring(0, dinfo.Name.Length - AppExtension.Length);
                    dataPath = Path.Combine(dinfo.FullName, iOSDataName);
                    if (DirectoryUtils.Exists(dataPath))
                    {
                        return(true);
                    }
                }
            }

            dataPath = null;
            appName  = null;
            return(false);
        }
Example #2
0
        private static bool GetDataPCDirectory(DirectoryInfo rootDiectory, out string dataPath, out string name)
        {
            name = null;
            int exeCount = 0;

            foreach (FileInfo finfo in rootDiectory.EnumerateFiles())
            {
                if (finfo.Extension == ExeExtension)
                {
                    exeCount++;
                    name = Path.GetFileNameWithoutExtension(finfo.Name);
                    string dataFolder = $"{name}_{DataPostfix}";
                    dataPath = Path.Combine(rootDiectory.FullName, dataFolder);
                    if (DirectoryUtils.Exists(dataPath))
                    {
                        return(true);
                    }
                }
            }

            if (exeCount > 0)
            {
                name     = exeCount == 1 ? name : rootDiectory.Name;
                dataPath = Path.Combine(rootDiectory.FullName, DataPostfix);
                if (DirectoryUtils.Exists(dataPath))
                {
                    return(true);
                }
            }

            name     = null;
            dataPath = null;
            return(false);
        }
Example #3
0
        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);
        }
Example #4
0
        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 (!DirectoryUtils.Exists(dataPath))
            {
                return(false);
            }
            string resourcePath = Path.Combine(dinfo.FullName, ContentsName, ResourcesName);

            if (!DirectoryUtils.Exists(resourcePath))
            {
                return(false);
            }
            return(true);
        }
Example #5
0
        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();
        }
Example #6
0
        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;
        }
Example #7
0
        private static string[] GetFiles(string dirPath, string fileName)
        {
            if (!DirectoryUtils.Exists(dirPath))
            {
                return(new string[0]);
            }

            string filePatern = fileName + ".split*";

            return(DirectoryUtils.GetFiles(dirPath, filePatern));
        }
Example #8
0
        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 _));
        }
Example #9
0
        private static bool GetDataSwitchDirectory(DirectoryInfo rootDirectory, out string dataPath)
        {
            dataPath = null;
            string romPath = Path.Combine(rootDirectory.FullName, RomName);

            if (!DirectoryUtils.Exists(romPath))
            {
                return(false);
            }

            string ldataPath = Path.Combine(romPath, DataFolderName);

            if (!DirectoryUtils.Exists(ldataPath))
            {
                return(false);
            }

            dataPath = ldataPath;
            return(true);
        }
        private static bool GetDataLinuxDirectory(DirectoryInfo rootDiectory, out string dataPath, out string name)
        {
            foreach (FileInfo finfo in rootDiectory.EnumerateFiles())
            {
                if (finfo.Extension == x86Extension || finfo.Extension == x64Extension)
                {
                    name = Path.GetFileNameWithoutExtension(finfo.Name);
                    string dataFolder = $"{name}_{DataFolderName}";
                    dataPath = Path.Combine(rootDiectory.FullName, dataFolder);
                    if (DirectoryUtils.Exists(dataPath))
                    {
                        return(true);
                    }
                }
            }

            name     = null;
            dataPath = null;
            return(false);
        }
Example #11
0
        protected void CollectMainAssemblies(DirectoryInfo root, IDictionary <string, string> assemblies)
        {
            string managedPath = Path.Combine(root.FullName, ManagedName);

            if (DirectoryUtils.Exists(managedPath))
            {
                DirectoryInfo managedDirectory = new DirectoryInfo(managedPath);
                CollectAssemblies(managedDirectory, assemblies);
            }
            else
            {
                string libPath = Path.Combine(root.FullName, LibName);
                if (DirectoryUtils.Exists(libPath))
                {
                    CollectAssemblies(root, assemblies);
                    DirectoryInfo libDirectory = new DirectoryInfo(libPath);
                    CollectAssemblies(libDirectory, assemblies);
                }
            }
        }
Example #12
0
        public MacGameStructure(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");
            }

            Name = m_root.Name.Substring(0, m_root.Name.Length - AppExtension.Length);

            string dataPath = Path.Combine(m_root.FullName, ContentsName, DataFolderName);

            if (!DirectoryUtils.Exists(dataPath))
            {
                throw new Exception("Data directory wasn't found");
            }
            string resourcePath = Path.Combine(m_root.FullName, ContentsName, ResourcesName);

            if (!DirectoryUtils.Exists(resourcePath))
            {
                throw new Exception("Resources directory wasn't 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;
        }
Example #13
0
        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, true);
            if (!DirectoryUtils.Exists(dirPath))
            {
                return(validFileName);
            }

            name = name ?? Path.GetFileNameWithoutExtension(validFileName);
            if (!IsReservedName(name))
            {
                if (!File.Exists(Path.Combine(dirPath, validFileName)))
                {
                    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}");
        }
Example #14
0
        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;
        }
Example #15
0
        public WebGLGameStructure(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");
            }

            Dictionary <string, string> files = new Dictionary <string, string>();
            string buildPath = Path.Combine(m_root.FullName, BuildName);

            if (DirectoryUtils.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 (DirectoryUtils.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 (DirectoryUtils.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 wasn't found");
                    }
                }
            }

            if (files.Count == 0)
            {
                throw new Exception("No files were found");
            }

            CollectStreamingAssets(m_root, files);
            Files = files;

            Assemblies = new Dictionary <string, string>();
        }