예제 #1
0
        public static bool IsAndroidStructure(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);
        }
예제 #2
0
        public PCGameStructure(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");
            }

            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;
            SetScriptingBackend();
        }
예제 #3
0
        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);
        }
예제 #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, DataName);

            if (!Directory.Exists(dataPath))
            {
                return(false);
            }
            string resourcePath = Path.Combine(dinfo.FullName, ContentsName, ResourcesName);

            if (!Directory.Exists(resourcePath))
            {
                return(false);
            }
            return(true);
        }
예제 #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();
        }
예제 #6
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");
                }
            }

            DataPathes = dataPathes.ToArray();
            Files      = files;
            Assemblies = assemblies;
            SetScriptingBackend();
            Name = Files.First().Key;
        }
예제 #7
0
        public WebPlayerStructure(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");
            }

            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;
            m_fileCollection.AssemblyManager.ScriptingBackEnd = ScriptingBackEnd.Mono;
        }
        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");
            }

            m_dataPath = Path.Combine(rootPath, AssetName, BinName, DataName);
            if (!DirectoryUtils.Exists(m_dataPath))
            {
                throw new Exception($"Data directory hasn't beed found");
            }

            if (obbPath != null)
            {
                m_obbRoot = new DirectoryInfo(DirectoryUtils.ToLongPath(obbPath));
                if (!m_obbRoot.Exists)
                {
                    throw new Exception($"Obb directory '{obbPath}' doesn't exist");
                }

                m_obbDataPath = Path.Combine(obbPath, AssetName, BinName, DataName);
                if (!DirectoryUtils.Exists(m_obbDataPath))
                {
                    throw new Exception($"Obb data directory hasn't beed found");
                }
            }

            DirectoryInfo managedDirectory = new DirectoryInfo(DirectoryUtils.ToLongPath(ManagedPath));

            if (!managedDirectory.Exists)
            {
                throw new Exception($"Managed directory hasn't been found");
            }

            foreach (FileInfo assemblyFile in managedDirectory.EnumerateFiles())
            {
                if (AssemblyManager.IsAssembly(assemblyFile.Name))
                {
                    if (MonoManager.IsMonoAssembly(assemblyFile.Name))
                    {
                        m_fileCollection.AssemblyManager.ScriptingBackEnd = ScriptingBackEnd.Mono;
                    }
                    else
                    {
                        m_fileCollection.AssemblyManager.ScriptingBackEnd = ScriptingBackEnd.Il2Cpp;
                    }
                    break;
                }
            }
        }
예제 #9
0
        public static bool IsPCStructure(string path)
        {
            DirectoryInfo dinfo = new DirectoryInfo(DirectoryUtils.ToLongPath(path));

            if (!dinfo.Exists)
            {
                return(false);
            }
            return(IsRootPCDirectory(dinfo));
        }
예제 #10
0
        public static bool IsWebPlayerStructure(string path)
        {
            DirectoryInfo dinfo = new DirectoryInfo(DirectoryUtils.ToLongPath(path));

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

            return(GetWebPlayerName(dinfo, out string _));
        }
예제 #11
0
        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 virtual IEnumerable <string> FetchAssemblies()
        {
            DirectoryInfo managedDirectory = new DirectoryInfo(DirectoryUtils.ToLongPath(ManagedPath));

            foreach (FileInfo assemblyFile in managedDirectory.EnumerateFiles())
            {
                if (AssemblyManager.IsAssembly(assemblyFile.Name))
                {
                    yield return(assemblyFile.FullName);
                }
            }
        }
        public override IEnumerable <string> FetchFiles()
        {
            foreach (string file in base.FetchFiles())
            {
                yield return(file);
            }
            string        assetPath      = Path.Combine(m_root.FullName, AssetName);
            DirectoryInfo assetDirectory = new DirectoryInfo(DirectoryUtils.ToLongPath(assetPath));

            foreach (string assetBundle in FetchGameAssetBundles(assetDirectory))
            {
                yield return(assetBundle);
            }
        }
예제 #14
0
        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();
        }
예제 #15
0
 public void AddFiles(IEnumerable <string> pathes)
 {
     foreach (string path in pathes)
     {
         if (FileMultiStream.Exists(path))
         {
             AddFile(path);
         }
         else if (DirectoryUtils.Exists(path))
         {
             DirectoryInfo directory = new DirectoryInfo(DirectoryUtils.ToLongPath(path));
             AddDirectory(directory);
         }
         else
         {
             throw new Exception($"Neither file nor directory with path '{path}' exists");
         }
     }
 }
 protected static string GetPresentDirectoryName(string rootPath, string directoryName)
 {
     if (RunetimeUtils.IsRunningOnMono)
     {
         if (DirectoryUtils.Exists(rootPath))
         {
             directoryName = Path.GetFileName(directoryName).ToLowerInvariant();
             DirectoryInfo root = new DirectoryInfo(DirectoryUtils.ToLongPath(rootPath));
             foreach (DirectoryInfo directory in root.EnumerateDirectories())
             {
                 if (directory.Name.ToLowerInvariant() == directoryName)
                 {
                     return(directory.Name);
                 }
             }
         }
     }
     return(directoryName);
 }
 protected static string GetPresentFileName(string rootPath, string fileName)
 {
     if (RunetimeUtils.IsRunningOnMono)
     {
         if (DirectoryUtils.Exists(rootPath))
         {
             fileName = Path.GetFileName(fileName).ToLowerInvariant();
             DirectoryInfo root = new DirectoryInfo(DirectoryUtils.ToLongPath(rootPath));
             foreach (FileInfo file in root.EnumerateFiles())
             {
                 if (file.Name.ToLowerInvariant() == fileName)
                 {
                     return(file.Name);
                 }
             }
         }
     }
     return(fileName);
 }
예제 #18
0
        public PCGameStructure(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");
            }

            m_dataPath = GetDataPCDirectory(m_root);
            if (m_dataPath == null)
            {
                throw new Exception($"Data directory hasn't been found");
            }

            DirectoryInfo managedDirectory = new DirectoryInfo(DirectoryUtils.ToLongPath(ManagedPath));

            if (!managedDirectory.Exists)
            {
                throw new Exception($"Managed directory hasn't been found");
            }

            foreach (FileInfo assemblyFile in managedDirectory.EnumerateFiles())
            {
                if (AssemblyManager.IsAssembly(assemblyFile.Name))
                {
                    if (MonoManager.IsMonoAssembly(assemblyFile.Name))
                    {
                        m_fileCollection.AssemblyManager.ScriptingBackEnd = ScriptingBackEnd.Mono;
                    }
                    else
                    {
                        m_fileCollection.AssemblyManager.ScriptingBackEnd = ScriptingBackEnd.Il2Cpp;
                    }
                    break;
                }
            }
        }
        public virtual IEnumerable <string> FetchFiles()
        {
            string filePath = Path.Combine(MainDataPath, MainDataName);

            if (FileMultiStream.Exists(filePath))
            {
                yield return(filePath);
            }

            filePath = Path.Combine(MainDataPath, GlobalGameManagerName);
            if (FileMultiStream.Exists(filePath))
            {
                yield return(filePath);
            }

            foreach (string dataPath in DataPathes)
            {
                DirectoryInfo dataDirectory = new DirectoryInfo(DirectoryUtils.ToLongPath(dataPath));
                foreach (FileInfo levelFile in dataDirectory.EnumerateFiles())
                {
                    if (m_levelName.IsMatch(levelFile.Name))
                    {
                        yield return(levelFile.FullName);
                    }
                }

                string        streamingPath      = Path.Combine(dataPath, StreamingName);
                DirectoryInfo streamingDirectory = new DirectoryInfo(DirectoryUtils.ToLongPath(streamingPath));
                if (streamingDirectory.Exists)
                {
                    foreach (string path in FetchAssetBundles(streamingDirectory))
                    {
                        yield return(path);
                    }
                }
            }
        }
예제 #20
0
        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;
        }
예제 #21
0
        private static void CheckWritePermission(string path)
        {
            WindowsIdentity  identity           = WindowsIdentity.GetCurrent();
            WindowsPrincipal principal          = new WindowsPrincipal(identity);
            bool             isInRoleWithAccess = false;

            try
            {
                DirectoryInfo               di    = new DirectoryInfo(DirectoryUtils.ToLongPath(path));
                DirectorySecurity           ds    = di.GetAccessControl();
                AuthorizationRuleCollection rules = ds.GetAccessRules(true, true, typeof(NTAccount));

                foreach (AuthorizationRule rule in rules)
                {
                    FileSystemAccessRule fsAccessRule = rule as FileSystemAccessRule;
                    if (fsAccessRule == null)
                    {
                        continue;
                    }

                    if ((fsAccessRule.FileSystemRights & FileSystemRights.Write) != 0)
                    {
                        NTAccount ntAccount = rule.IdentityReference as NTAccount;
                        if (ntAccount == null)
                        {
                            continue;
                        }

                        if (principal.IsInRole(ntAccount.Value))
                        {
                            if (fsAccessRule.AccessControlType == AccessControlType.Deny)
                            {
                                isInRoleWithAccess = false;
                                break;
                            }
                            isInRoleWithAccess = true;
                        }
                    }
                }
            }
            catch (UnauthorizedAccessException)
            {
            }

            if (!isInRoleWithAccess)
            {
                // is run as administrator?
                if (principal.IsInRole(WindowsBuiltInRole.Administrator))
                {
                    return;
                }

                // try run as admin
                Process  proc = new Process();
                string[] args = Environment.GetCommandLineArgs();
                proc.StartInfo.FileName        = args[0];
                proc.StartInfo.Arguments       = string.Join(" ", args.Skip(1).Select(t => $"\"{t}\""));
                proc.StartInfo.UseShellExecute = true;
                proc.StartInfo.Verb            = "runas";

                try
                {
                    proc.Start();
                    Environment.Exit(0);
                }
                catch (Win32Exception ex)
                {
                    //The operation was canceled by the user.
                    const int ERROR_CANCELLED = 1223;
                    if (ex.NativeErrorCode == ERROR_CANCELLED)
                    {
                        Logger.Instance.Log(LogType.Error, LogCategory.General, $"You can't export to folder {path} without Administrator permission");
                        Console.ReadKey();
                    }
                    else
                    {
                        Logger.Instance.Log(LogType.Error, LogCategory.General, $"You have to restart application as Administator in order to export to folder {path}");
                        Console.ReadKey();
                    }
                }
            }
        }