예제 #1
0
        private static void CopyResourceToStreamAssetDirectory(string platform)
        {
            string buildPlatform = platform;

            string platformDir = Path.Combine(Path.GetFullPath(binPath), buildPlatform);

            string streamAssetDir = Path.Combine(Application.streamingAssetsPath, "res");

            streamAssetDir = PackRes_Def.GetPlatformPathString(streamAssetDir);

            //Debug.Log("platformDir " + platformDir);
            //Debug.Log("streamAssetDir " + streamAssetDir);
            //Debug.Log("GetCurrentDirectory " + Directory.GetCurrentDirectory());
            if (Directory.Exists(streamAssetDir))
            {
                Directory.Delete(streamAssetDir, true);
            }
            Directory.CreateDirectory(streamAssetDir);

            DirectoryInfo source = new DirectoryInfo(platformDir);

            FileInfo[] files = source.GetFiles();
            for (int i = 0; i < files.Length; i++)
            {
                string destName = Path.Combine(streamAssetDir, files[i].Name);
                File.Copy(files[i].FullName, destName);
            }

            //copy the idx file and md5 file to resources folder
            string idxFilePath          = Path.Combine(platformDir, idxFileName);
            string checksumFilePath     = Path.Combine(platformDir, bundleMd5FileName);
            string destIdxFilePath      = Path.Combine(Path.GetFullPath("Assets/Resources"), idxFileName);
            string destChecksumFilePath = Path.Combine(Path.GetFullPath("Assets/Resources"), bundleMd5FileName);

            if (File.Exists(destIdxFilePath))
            {
                File.Delete(destIdxFilePath);
            }
            File.Copy(idxFilePath, destIdxFilePath);
            if (File.Exists(destChecksumFilePath))
            {
                File.Delete(destChecksumFilePath);
            }
            File.Copy(checksumFilePath, destChecksumFilePath);

            EditorApplication.ExecuteMenuItem("Assets/Refresh");
        }
예제 #2
0
        public static void AddFileChecksum(Dictionary <string, string> dict, string filePath)
        {
            if (!File.Exists(filePath))
            {
                dict[filePath] = "NULL";
                throw new PackRes_Def.PckException("file missing? " + filePath);
            }

            if (dict.ContainsKey(filePath))
            {
                return;
            }

            MD5 md5 = MD5.Create();

            FileStream fs = new FileStream(filePath, FileMode.Open);

            byte[] result = md5.ComputeHash(fs);
            fs.Close();
            dict[filePath] = BitConverter.ToString(result).Replace("-", "").ToLower();

            string metaFilePath = AssetDatabase.GetTextMetaDataPathFromAssetPath(filePath);

            if (File.Exists(metaFilePath))
            {
                fs     = new FileStream(metaFilePath, FileMode.Open);
                result = md5.ComputeHash(fs);
                fs.Close();
                dict[metaFilePath] = BitConverter.ToString(result).Replace("-", "").ToLower();
            }

            string[] depends = AssetDatabase.GetDependencies(new string[] { filePath });
            foreach (string dep in depends)
            {
                string temp = PackRes_Def.GetPlatformPathString(dep);
                AddFileChecksum(dict, temp);
            }
        }
예제 #3
0
        public static PackRes_Def.PackSetting ParsePackSetting(string configFilePath)
        {
            FileIniDataParser iniParser = new FileIniDataParser();
            IniData           data      = iniParser.LoadFile(configFilePath);

            PackRes_Def.PackSetting packSetting = new PackRes_Def.PackSetting();

            SectionData sectionData = data.Sections.GetSectionData("global_settings");


            packSetting.cfg_path = GetValFromCfg(sectionData, "cfg_path");
            packSetting.cfg_path = PackRes_Def.GetPlatformPathString(packSetting.cfg_path);

            packSetting.cfg_file = GetValFromCfg(sectionData, "cfg_file");
            packSetting.cfg_file = PackRes_Def.GetPlatformPathString(packSetting.cfg_file);

            packSetting.res_path = GetValFromCfg(sectionData, "res_path");
            packSetting.res_path = PackRes_Def.GetPlatformPathString(packSetting.res_path);

            packSetting.option   = GetValFromCfg(sectionData, "option");
            packSetting.exp_path = Path.GetFullPath(GetValFromCfg(sectionData, "exp_path"));
            packSetting.exp_path = PackRes_Def.GetPlatformPathString(packSetting.exp_path);

            packSetting.bundle_path  = GetValFromCfg(sectionData, "bundle_path");
            packSetting.bundle_path  = PackRes_Def.GetPlatformPathString(packSetting.bundle_path);
            packSetting.res_idx_path = GetValFromCfg(sectionData, "res_idx_path");
            packSetting.res_idx_path = PackRes_Def.GetPlatformPathString(packSetting.res_idx_path);

            packSetting.index_file = GetValFromCfg(sectionData, "index_file");

            packSetting.policy = GetValFromCfg(sectionData, "policy");

            string compress_str = GetValFromCfg(sectionData, "compress");

            if (compress_str == "false")
            {
                packSetting.compress = false;
            }
            else if (compress_str == "true")
            {
                packSetting.compress = true;
            }
            else
            {
                Debug.LogError("invalid compress setting");
            }

            //parse the file type list
            packSetting.fileTypeList = new List <string>();
            string type_str = GetValFromCfg(sectionData, "res_type_list");

            string[] type_arry = type_str.Split('|');
            foreach (string ty in type_arry)
            {
                if (ty != null && ty != "")
                {
                    packSetting.fileTypeList.Add(ty);
                }
            }
            return(packSetting);
        }
예제 #4
0
        public static List <PackRes_Def.BundleData> ParseResCfg(string pckCfgFile, string srcPath,
                                                                string option, bool compress)
        {
            SectionDataCollection sectionList = GetSectsFromCfg(pckCfgFile);

            if (sectionList == null || sectionList.Count == 0)
            {
                return(null);
            }

            //get all settings
            List <PackRes_Def.BundleData> bundlelist = new List <PackRes_Def.BundleData>();

            foreach (SectionData sect in sectionList)
            {
                PackRes_Def.BundleData bundledata = new PackRes_Def.BundleData();
                bundledata.bundleFile = sect.SectionName.Trim(PackRes_Def.trim);
                bundledata.bundleFile = PackRes_Def.GetPlatformPathString(bundledata.bundleFile);

                bundledata.option   = option;
                bundledata.compress = compress;

                string source = GetValFromCfg(sect, "source");
                if (source == null || source == "")
                {
                    throw new PackRes_Def.PckException("can not get source file in section: " + sect);
                }
                else
                {
                    string[]      files    = source.Split('|');
                    List <string> srcFiles = new List <string>();
                    List <string> srcNames = new List <string>();
                    foreach (string file in files)
                    {
                        string tmp  = file.Trim(PackRes_Def.trim);
                        string name = Path.GetFileName(tmp);
                        if (name.StartsWith("*."))
                        {
                            string   path  = Path.GetDirectoryName(tmp);
                            string[] names = Directory.GetFiles(Path.Combine(srcPath, path), name, SearchOption.AllDirectories);

                            foreach (string n in names)
                            {
                                string n0 = Path.GetFileName(n);
                                srcFiles.Add(n);    //(Path.Combine(srcPath, Path.Combine(path, n0)));
                                srcNames.Add(n0);
                            }
                        }
                        else
                        {
                            srcNames.Add(name);
                            srcFiles.Add(Path.Combine(srcPath, tmp));
                        }
                    }

                    bundledata.srcFiles = srcFiles.ToArray();
                    bundledata.names    = srcNames.ToArray();
                }
                bundlelist.Add(bundledata);
            }
            return(bundlelist);
        }