Exemplo n.º 1
0
        private static Dictionary <string, string> ReadVersionFileByPath(string filePath)
        {
            Dictionary <string, string> versionInfo = new Dictionary <string, string>();

            byte[] versionbytes = ABHelper.ReadFileToBytes(filePath);
            if (null == versionbytes)
            {
                return(versionInfo);
            }

            ABHelper.Encrypt(ref versionbytes); //RC4 加密文件
            string versionTxt = Encoding.UTF8.GetString(versionbytes);

            if (!string.IsNullOrEmpty(versionTxt))
            {
                //ui/tips.ab:ba2de82e3fc42e750d317b133096dfea:0:22455:fa7917d4974436b1214dc313fccda2a5
                //路径:内容md5:版号:size:路径md5
                string[] split = versionTxt.Split('\r');
                foreach (string k in split)
                {
                    string[] split2 = k.Split(':');
                    versionInfo.Add(split2[4], split2[0]);
                }
            }

            return(versionInfo);
        }
Exemplo n.º 2
0
        // 拷贝目录,包括
        private static void DirCopy(string srcPath, string tarPath, string fileExtension = null)
        {
            try
            {
                bool needAddExtension = !string.IsNullOrEmpty(fileExtension);

                // 检查目标目录是否以目录分割字符结束如果不是则添加
                if (tarPath[tarPath.Length - 1] != System.IO.Path.DirectorySeparatorChar)
                {
                    tarPath += System.IO.Path.DirectorySeparatorChar;
                }
                // 判断目标目录是否存在如果不存在则新建
                if (!System.IO.Directory.Exists(tarPath))
                {
                    System.IO.Directory.CreateDirectory(tarPath);
                }
                // 得到源目录的文件列表,该里面是包含文件以及目录路径的一个数组
                // 如果你指向copy目标文件下面的文件而不包含目录请使用下面的方法
                // string[] fileList = Directory.GetFiles(srcPath);
                string[] fileList = System.IO.Directory.GetFileSystemEntries(srcPath);
                // 遍历所有的文件和目录
                foreach (string file in fileList)
                {
                    string targetFileName = tarPath + System.IO.Path.GetFileName(file);

                    // 先当作目录处理如果存在这个目录就递归Copy该目录下面的文件
                    if (System.IO.Directory.Exists(file))
                    {
                        DirCopy(file, targetFileName, fileExtension);
                    }
                    // 否则直接Copy文件
                    else
                    {
                        // 剔除meta文件, .DS打头的文件
                        if (targetFileName.EndsWith(".meta") || targetFileName.Contains(".DS"))
                        {
                            continue;
                        }
                        // 添加后缀
                        if (needAddExtension)
                        {
                            targetFileName = targetFileName + fileExtension;
                        }
                        byte[] content = ABHelper.ReadFileToBytes(file);;
                        if (null == content || content.Length <= 0)
                        {
                            continue;
                        }
                        ABHelper.Encrypt(ref content);
                        ABHelper.WriteFileByBytes(targetFileName, content);
                    }
                }
            }
            catch (Exception e)
            {
                throw;
            }
        }
Exemplo n.º 3
0
        private static byte[] TryLoadLuaFromResource(string fullpath, bool encrypt = true)
        {
            if (string.IsNullOrEmpty(fullpath))
            {
                return(null);
            }
            TextAsset tAsset = Resources.Load <TextAsset>(fullpath);

            if (null == tAsset)
            {
                return(null);
            }

            byte[] bytes = tAsset.bytes;
            if (encrypt)
            {
                ABHelper.Encrypt(ref bytes);
            }
            return(bytes);
        }
Exemplo n.º 4
0
        private static void CopyLuaFiles(string path)
        {
            string filePath = CreatFileUrlMd5(path.Replace("Assets/", "") + ".txt");

            filePath = (CurVersionABExportPath + filePath).ToLower();
            string fileFolder = Path.GetDirectoryName(filePath);

            if (!Directory.Exists(fileFolder))
            {
                Directory.CreateDirectory(fileFolder);
            }
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            // 加密
            byte[] bytes = ABHelper.ReadFileToBytes(path);
            ABHelper.Encrypt(ref bytes); //RC4 加密lua文件
            ABHelper.WriteFileByBytes(filePath, bytes);
        }
Exemplo n.º 5
0
        private static byte[] TryLoadLuaFromFile(string fullpath, bool encrypt = true)
        {
            byte[] bytes = ABHelper.ReadFileToBytes(fullpath);
            if (null == bytes)
            {
                return(null);
            }

            if (encrypt)
            {
                ABHelper.Encrypt(ref bytes);
            }
            // 转换为utf8
            using (Stream stream = new MemoryStream(bytes))
            {
                using (StreamReader sr = new StreamReader(stream))
                {
                    string code = sr.ReadToEnd();
                    return(System.Text.Encoding.UTF8.GetBytes(code));
                }
            }
        }
Exemplo n.º 6
0
        // 生成lua的bytecode
        private static void GenLuaByteCode(string sourceDirName, string destDirName, bool copySubDirs = true)
        {
            DirectoryInfo dir = new DirectoryInfo(sourceDirName);

            if (!dir.Exists)
            {
                throw new DirectoryNotFoundException("Source directory does not exist or could not be found: " + sourceDirName);
            }

            DirectoryInfo[] dirs = dir.GetDirectories();
            if (!Directory.Exists(destDirName))
            {
                Directory.CreateDirectory(destDirName);
            }

            // 遍历所有文件
            FileInfo[] files = dir.GetFiles();
            foreach (FileInfo file in files)
            {
                // 剔除meta文件, .DS打头的文件
                if (file.Name.EndsWith(".meta") || file.Name.Contains(".DS"))
                {
                    continue;
                }

                string sourcePath      = Path.Combine(sourceDirName, file.Name);
                string destinationPath = Path.Combine(destDirName, file.Name);

#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
                // 路径转义字符替换
                sourcePath      = sourcePath.Replace("/", "\\");
                destinationPath = destinationPath.Replace("/", "\\");
#endif
                // 目标路径,加个txt后缀
                destinationPath = destinationPath + ".txt";

                // 编译bytecode
                m_process.StartInfo.FileName         = m_luajitExePath;
                m_process.StartInfo.Arguments        = string.Format(" -b {0} {1}", sourcePath, destinationPath);
                m_process.StartInfo.WorkingDirectory = m_luajitWorkingPath;

                try
                {
                    m_process.Start();
                    m_process.WaitForExit();
                }
                catch (Exception e)
                {
                    Debug.LogError(e.Message);
                }

                // Debug.Log("~~~~~执行输出\n" + m_process.StandardOutput.ReadToEnd());
                // Debug.Log("~~~~~执行错误\n" + m_process.StandardError.ReadToEnd());
                // Debug.Log("~~~~~执行返回码:" + m_process.ExitCode);

                // 处理成功后
                if (m_process.ExitCode == 0)
                {
                    byte[] content = ABHelper.ReadFileToBytes(sourcePath);
                    ABHelper.Encrypt(ref content);
                    ABHelper.WriteFileByBytes(destinationPath, content);
                }
            }

            if (copySubDirs)
            {
                foreach (DirectoryInfo subdir in dirs)
                {
                    string temppath = Path.Combine(destDirName, subdir.Name);
                    GenLuaByteCode(subdir.FullName, temppath, copySubDirs);
                }
            }
        }