public static void DownloadEvoCardAll(Action <string> onComplete = null, string tag = null)
        {
            _onComplete = onComplete;
            _tag        = tag;

            ResIndex resIndex = GetIndexFile(ResPath.EvoCardPackageIndex);

            DownloadManager.Clear();

            ResPack resPack = resIndex.packageDict["EvoCard"];

            _releasePath = resPack.releasePath;
            if (resPack.packageType == FileType.Zip)
            {
                ResItem item = new ResItem()
                {
                    Md5  = resPack.packageMd5,
                    Path = AppConfig.Instance.assetsServer + "/" + AppConfig.Instance.version + "/" +
                           resPack.downloadPath,
                    Size     = resPack.packageSize,
                    FileType = resPack.packageType
                };

                _downloadingWindow          = PopupManager.ShowWindow <DownloadingWindow>(Constants.DownloadingWindowPath);
                _downloadingWindow.Content  = I18NManager.Get("Download_Downloading");
                _downloadingWindow.Progress = I18NManager.Get("Download_Progress", 0);
                DownloadManager.Load(item, AssetLoader.ExternalDownloadPath + "/" + resPack.downloadPath,
                                     OnCompleteEvoCard,
                                     OnErrorEvoCard, OnProgress);
            }
        }
Exemple #2
0
        public static bool IsNeedDownLoad(int chapter)
        {
            bool     isNeed   = false;
            ResIndex resIndex = GetIndexFile(ResPath.MainStoryIndex);

            if (resIndex == null)
            {
                return(isNeed);
            }

            if (resIndex.packageDict.ContainsKey(chapter.ToString()))
            {
                ResPack resPack = resIndex.packageDict[chapter.ToString()];

                foreach (var resItem in resPack.items)
                {
                    FileInfo fileInfo =
                        new FileInfo(AssetLoader.ExternalHotfixPath + "/" + resPack.releasePath + "/" + resItem.Path);
                    if (fileInfo.Exists == false || fileInfo.Length != resItem.Size)
                    {
                        isNeed = true;
                        break;
                    }
                }
            }

            return(isNeed);
        }
        public static void DownloadAllBundle(Action <string> onComplete, string tag = null)
        {
            _onComplete = onComplete;
            _tag        = tag;

            _releasePath = "";

            ResIndex resIndex = GetIndexFile(ResPath.AllResources);

            if (resIndex == null)
            {
                onComplete?.Invoke(tag);
                return;
            }

            ResPack resPack = resIndex.packageDict[ResPath.AllResources];

            if (resPack.packageType == FileType.Zip)
            {
                ResItem item = new ResItem()
                {
                    Md5  = resPack.packageMd5,
                    Path = AppConfig.Instance.assetsServer + "/" + AppConfig.Instance.version + "/" +
                           resPack.downloadPath,
                    Size     = resPack.packageSize,
                    FileType = resPack.packageType
                };

                DownloadManager.Load(item, AssetLoader.ExternalDownloadPath + "/" + resPack.downloadPath,
                                     OnCompleteFullLoading, OnFullLoadingError, OnProgressFullLoading);

                LoadingProgress.Instance.Show(resPack.packageSize);
                LoadingProgress.Instance.SetPercent(0);
            }
        }
Exemple #4
0
    static void GenerateIndexFile(string destDir, string language, string moduleName, string indexFileName,
                                  string releasePath, string packagePath, bool useSubDir = true, FileType fileType = FileType.Zip,
                                  bool ignoreItems = false)
    {
        releasePath = "AssetBundles/" + SystemTag + "/" + releasePath;

        ResIndex resIndex = new ResIndex();

        resIndex.language    = language;
        resIndex.belong      = moduleName;
        resIndex.packageDict = new Dictionary <string, ResPack>();

        string[] dirs = new string[] { destDir };

        if (useSubDir)
        {
            dirs = Directory.GetDirectories(destDir);
        }

        for (int i = 0; i < dirs.Length; i++)
        {
            ResPack resPack = new ResPack();
            resPack.id = new FileInfo(dirs[i]).Name;

            if (ignoreItems == false)
            {
                resPack.items = new List <ResItem>();
                string[] files = Directory.GetFiles(dirs[i]);
                for (int j = 0; j < files.Length; j++)
                {
                    string   filePath = files[j];
                    FileInfo fileInfo = new FileInfo(filePath);
                    ResItem  resItem  = new ResItem();
                    resItem.Path = fileInfo.Name;
                    resItem.Md5  = MD5Util.Get(filePath);
                    resItem.Size = fileInfo.Length;
                    resPack.items.Add(resItem);
                }
            }

            resPack.packageType = fileType;
            if (fileType == FileType.Zip)
            {
                resPack.packageMd5   = MD5Util.Get(packagePath + "/" + resPack.id + ".zip");
                resPack.packageSize  = new FileInfo(packagePath + "/" + resPack.id + ".zip").Length;
                resPack.downloadPath = GetPackageStorePath() + "/" + resIndex.belong + "/" + resPack.id + ".zip";
            }
            else
            {
                resPack.downloadPath = GetPackageStorePath() + "/" + resIndex.belong;
            }

            resPack.releasePath = releasePath;
            resIndex.packageDict.Add(resPack.id, resPack);
        }

        string json = JsonConvert.SerializeObject(resIndex, Formatting.Indented);

        FileUtil.SaveFileText(OutputPath, indexFileName + ".json", json);
    }
Exemple #5
0
        private static void UnzipBackendStep(Dictionary <string, ResPack> dict, string fileKey,
                                             Action <Dictionary <string, ResPack> > onUnzipComplete)
        {
            ResPack resPack  = dict[fileKey];
            string  filePath = AssetLoader.ExternalDownloadPath + "/" + resPack.downloadPath;

            Loom.RunAsync(() =>
            {
                try
                {
                    ZipUtil.UnzipThread(filePath, AssetLoader.ExternalHotfixPath + "/" + resPack.releasePath);
                }
                catch (IOException e)
                {
                    Debug.LogException(e);
                }

                Loom.QueueOnMainThread(() =>
                {
                    File.Delete(filePath);
                    FileMark fm = new FileMark(AssetLoader.ExternalHotfixPath, ResPath.Backend + "_" + fileKey);
                    fm.UpdateRecord(AppConfig.Instance.version + "");

                    onUnzipComplete?.Invoke(dict);
                });
            });
        }
Exemple #6
0
        public static void DownloadExtendCache(Action <string> onComplete = null, string tag = null, Action <string> onError = null)
        {
            _onComplete = onComplete;
            _onError    = onError;
            _tag        = tag;

            ResIndex resIndex = GetIndexFile(ResPath.Extend);
            ResPack  resPack  = resIndex.packageDict[ResPath.Extend];

            _releasePath = resPack.releasePath;
            if (resPack.packageType == FileType.Zip)
            {
                ResItem item = new ResItem()
                {
                    Md5  = resPack.packageMd5,
                    Path = AppConfig.Instance.assetsServer + "/" + AppConfig.Instance.version + "/" +
                           resPack.downloadPath,
                    Size     = resPack.packageSize,
                    FileType = resPack.packageType
                };

                DownloadManager.Load(item, AssetLoader.ExternalDownloadPath + "/" + resPack.downloadPath,
                                     OnCompleteFullLoading, OnError, OnProgressFullLoading);
                LoadingProgress.Instance.Show(resPack.packageSize);
                LoadingProgress.Instance.SetPercent(0);
            }
        }
        public static void DownloadLoveDiaryCache(string musicId, Action <string> onComplete = null, Action onCancel = null, string tag = null)
        {
            _onComplete        = onComplete;
            _onLoveDiaryCancel = onCancel;
            _tag = tag;

            ResIndex resIndex = GetIndexFile(ResPath.Special);

            string packKey = "lovediary";

            if (!resIndex.packageDict.ContainsKey(packKey))
            {
                FlowText.ShowMessage(I18NManager.Get("Download_ErrorLoveDiary") + musicId);
                _onLoveDiaryCancel?.Invoke();
                return;
            }

            DownloadManager.Clear();
            ResPack resPack = resIndex.packageDict[packKey.ToString()];
            string  resPath = "music/mainplay/" + musicId + ".music";
            var     rm      = resPack.items.Find((m) => { return(m.Path == resPath); });

            if (rm == null)
            {
                return;
            }

            _releasePath = resPack.releasePath;
            if (resPack.packageType == FileType.Original)
            {
                ResItem item = new ResItem()
                {
                    Md5  = rm.Md5,
                    Path = AppConfig.Instance.assetsServer + "/" + AppConfig.Instance.version + "/" +
                           resPack.downloadPath + "/" + resPath,
                    Size     = rm.Size,
                    FileType = resPack.packageType
                };

                //_downloadingWindow = PopupManager.ShowWindow<DownloadingWindow>(Constants.DownloadingWindowPath);
                //_downloadingWindow.Content = I18NManager.Get("Download_Downloading");
                //_downloadingWindow.Progress = I18NManager.Get("Download_Progress", 0);

                string storePath = AssetLoader.ExternalHotfixPath + "/" + _releasePath + "/" + resPath;
                Debug.Log(storePath);
                var downItem = DownloadManager.Load(item, storePath, OnCompleteLoveDiary,
                                                    OnErrorLoveDiary, null, OnErrorLoveDiary);
                //_downloadingWindow.WindowActionCallback = evt =>
                //{
                //    if (evt == WindowEvent.Cancel)
                //    {
                //        onCancel?.Invoke();
                //        downItem.Cancel();
                //    }
                //};
            }
        }
Exemple #8
0
    private static void CreateAllDownloadJsonAndZip()
    {
        //压缩文件
        string packagePath = PackageManager.OutputPath + ResPath.AllResources;

        if (Directory.Exists(packagePath))
        {
            Directory.Delete(packagePath, true);
        }
        Directory.CreateDirectory(packagePath);

        string zipFileName = packagePath + "/" + ResPath.AllResources + ".zip";

        string destDir = PackageManager.GetPackageDir() + "/" + ResPath.AllResources;

        string[] files = Directory.GetFiles(destDir, "*", SearchOption.AllDirectories);

        EditorUtility.DisplayProgressBar("压缩", "正在压缩文件(" + Path.GetFileName(packagePath), 1);

        List <string> pathInZipList = new List <string>();

        for (int i = 0; i < files.Length; i++)
        {
            string str = Path.GetDirectoryName(files[i]);
            str = str.Replace("\\", "/");
            str = str.Replace(PackageManager.GetPackageDir().Replace("\\", "/") + "/" + ResPath.AllResources + "/", "");
            pathInZipList.Add(str + "/");
        }

        ZipUtil.CreateZip(files, zipFileName, pathInZipList.ToArray(), 0);

        EditorUtility.ClearProgressBar();

        //生成Index文件
        ResIndex resIndex = new ResIndex();

        resIndex.language    = PackageManager.Language;
        resIndex.belong      = ResPath.AllResources;
        resIndex.packageDict = new Dictionary <string, ResPack>();

        ResPack resPack = new ResPack();

        resPack.id           = ResPath.AllResources;
        resPack.items        = new List <ResItem>();
        resPack.packageType  = FileType.Zip;
        resPack.packageMd5   = MD5Util.Get(packagePath + "/" + resPack.id + ".zip");
        resPack.packageSize  = new FileInfo(packagePath + "/" + resPack.id + ".zip").Length;
        resPack.downloadPath = PackageManager.GetPackageStorePath() + "/" + resIndex.belong + "/" + resPack.id + ".zip";
        resIndex.packageDict.Add(resPack.id, resPack);

        string json = JsonConvert.SerializeObject(resIndex, Formatting.Indented);

        FileUtil.SaveFileText(PackageManager.OutputPath, ResPath.AllResources + ".json", json);
    }
Exemple #9
0
        public static long GetDownloadAllSize()
        {
            ResIndex resIndex = GetIndexFile(ResPath.AllAudioIndex);

            if (resIndex != null)
            {
                ResPack resPack = resIndex.packageDict["AllAudio"];
                return(resPack.packageSize);
            }
            else
            {
                return(0);
            }
        }
Exemple #10
0
        /// <summary>
        /// 返回未下载的索引数值
        /// </summary>
        /// <returns>未下载的索引数值</returns>
        public static CacheVo CheckMainStoryCache(int chapter)
        {
            Stopwatch sw = Stopwatch.StartNew();

            CacheVo vo = new CacheVo();

            vo.ids = new List <int>();

            ResIndex resIndex = GetIndexFile(ResPath.MainStoryIndex);

            if (resIndex == null)
            {
                return(vo);
            }

            if (resIndex.packageDict.ContainsKey(chapter.ToString()) == false)
            {
                FlowText.ShowMessage(I18NManager.Get("Download_IndexNoExist") + chapter);
                return(vo);
            }

            ResPack resPack = resIndex.packageDict[chapter.ToString()];

            _releasePath = resPack.releasePath;
            foreach (var resItem in resPack.items)
            {
                FileInfo fileInfo =
                    new FileInfo(AssetLoader.ExternalHotfixPath + "/" + _releasePath + "/" + resItem.Path);

                if (fileInfo.Exists == false || fileInfo.Length != resItem.Size)
                {
                    vo.needDownload = true;
                    break;
                }
            }

            if (vo.needDownload)
            {
                vo.ids.Add(Convert.ToInt32(chapter));
            }

            vo.sizeList = new List <long>()
            {
                resPack.packageSize
            };

            Debug.LogError("CheckMainStoryCache 时间:" + sw.ElapsedMilliseconds);

            return(vo);
        }
        public static void DownloadLoveStoryCache(int cardId, Action <string> onComplete = null, string tag = null, Action <string> onCancle = null)
        {
            _onComplete = onComplete;
            _tag        = tag;

            ResIndex resIndex = GetIndexFile(ResPath.LoveStoryIndex);

            if (!resIndex.packageDict.ContainsKey(cardId.ToString()))
            {
                FlowText.ShowMessage(I18NManager.Get("Download_ErrorRole") + cardId);
                return;
            }

            DownloadManager.Clear();

            ResPack resPack = resIndex.packageDict[cardId.ToString()];

            _releasePath = resPack.releasePath;
            if (resPack.packageType == FileType.Zip)
            {
                ResItem item = new ResItem()
                {
                    Md5  = resPack.packageMd5,
                    Path = AppConfig.Instance.assetsServer + "/" + AppConfig.Instance.version + "/" +
                           resPack.downloadPath,
                    Size     = resPack.packageSize,
                    FileType = resPack.packageType
                };

                _downloadingWindow          = PopupManager.ShowWindow <DownloadingWindow>(Constants.DownloadingWindowPath);
                _downloadingWindow.Content  = I18NManager.Get("Download_Downloading");
                _downloadingWindow.Progress = I18NManager.Get("Download_Progress", 0);
                var downloadItem = DownloadManager.Load(item, AssetLoader.ExternalDownloadPath + "/" + resPack.downloadPath,
                                                        OnCompleteLoveStory,
                                                        OnErrorLoveStory, OnProgress);
                //downloadItems = downloadItem;
                _downloadingWindow.WindowActionCallback = evt =>
                {
                    if (evt == WindowEvent.Cancel)
                    {
                        downloadItem.Cancel();
                        onCancle?.Invoke(downloadItem.ErrorText);
                    }
                };
            }
        }
Exemple #12
0
        public static CacheVo CheckAppStartCache()
        {
            Stopwatch sw = Stopwatch.StartNew();

            CacheVo vo = new CacheVo();

            FileMark fm = new FileMark(AssetLoader.ExternalHotfixPath, ResPath.AppStart);

            if (fm.IsMatch)
            {
                return(vo);
            }

            ResIndex resIndex = GetIndexFile(ResPath.AppStart);

            if (resIndex == null)
            {
                return(vo);
            }

            ResPack resPack = resIndex.packageDict[ResPath.AppStart];

            _releasePath = resPack.releasePath;
            foreach (var resItem in resPack.items)
            {
                FileInfo fileInfo =
                    new FileInfo(AssetLoader.ExternalHotfixPath + "/" + _releasePath + "/" + resItem.Path);

                if (fileInfo.Exists == false || fileInfo.Length != resItem.Size)
                {
                    vo.needDownload = true;
                    break;
                }
            }

            vo.sizeList = new List <long>()
            {
                resPack.packageSize
            };

            Debug.LogError("CheckAppStartCache 时间:" + sw.ElapsedMilliseconds);

            return(vo);
        }
Exemple #13
0
        public static CacheVo CheckExtendCache()
        {
            Stopwatch sw = Stopwatch.StartNew();

            CacheVo vo = new CacheVo();

            ResIndex resIndex = GetIndexFile(ResPath.Extend);

            if (resIndex == null)
            {
                return(vo);
            }

            if (IsDownloadMarked())
            {
                return(vo);
            }

            if (resIndex.packageDict.ContainsKey(ResPath.Extend) == false)
            {
                FlowText.ShowMessage(I18NManager.Get("Download_IndexNoExist"));
                return(vo);
            }

            ResPack resPack = resIndex.packageDict[ResPath.Extend];

            _releasePath = resPack.releasePath;

            FileMark fm = new FileMark(AssetLoader.ExternalHotfixPath, ResPath.Backend);

            if (fm.IsMatch == false)
            {
                vo.needDownload = true;
            }

            vo.sizeList = new List <long>()
            {
                resPack.packageSize
            };

            Debug.LogError("CheckExtend 时间:" + sw.ElapsedMilliseconds);

            return(vo);
        }
        public static bool IsLoveDiaryNeedDown(string musicId)
        {
            Stopwatch sw       = Stopwatch.StartNew();
            ResIndex  resIndex = GetIndexFile(ResPath.Special);

            if (resIndex == null)
            {
                return(false);
            }
            Debug.LogError(musicId);
            string packKey = "lovediary";

            if (resIndex.packageDict.ContainsKey(packKey) == false)
            {
                FlowText.ShowMessage(I18NManager.Get("Download_IndexNoExist") + packKey);
                return(false);
            }

            ResPack resPack = resIndex.packageDict[packKey.ToString()];

            _releasePath = resPack.releasePath;


            string resPath = "music/mainplay/" + musicId + ".music";
            var    rm      = resPack.items.Find((m) => { return(m.Path == resPath); });

            if (rm == null)
            {
                return(false);
            }


            string storePath = AssetLoader.ExternalHotfixPath + "/" + _releasePath + "/" + rm.Path;

            Debug.Log("IsLoveDiaryNeedDown::" + storePath);
            FileInfo fileInfo =
                new FileInfo(storePath);

            if (fileInfo.Exists == false)
            {
                return(true);
            }
            return(false);
        }
Exemple #15
0
        private static void DownloadBackEndCache()
        {
            ResPack resPack = _backendPackQueue.Dequeue();

            _releasePath = resPack.releasePath;
            ResItem item = new ResItem()
            {
                Md5  = resPack.packageMd5,
                Path = AppConfig.Instance.assetsServer + "/" + AppConfig.Instance.version + "/" +
                       resPack.downloadPath,
                Size     = resPack.packageSize,
                FileType = resPack.packageType
            };

            Debug.LogError("StarDownloadBackEnd " + resPack.downloadPath);
            DownloadManager.Load(item, AssetLoader.ExternalDownloadPath + "/" + resPack.downloadPath,
                                 OnBackendStepEnd, OnError, OnProgressFullLoading);
            LoadingProgress.Instance.TotalSize = Math.Round(resPack.packageSize * 1f / 1048576f, 2);
        }
Exemple #16
0
        /// <summary>
        /// 获取到需要后台下载的包cachevo
        /// </summary>
        /// <returns></returns>
        public static long CheckCurBackEndCacheSize()
        {
            Stopwatch sw = Stopwatch.StartNew();

            ResIndex resIndex = GetIndexFile(ResPath.Backend);

            if (resIndex == null)
            {
                return(0);
            }

            if (resIndex.packageDict.Count == 0)
            {
                Debug.LogError("Download_IndexNoExist");
                return(0);
            }

            long allsize = 0;

            foreach (var v in resIndex.packageDict)
            {
                //要遍历几遍!
                CacheVo vo      = new CacheVo();
                ResPack resPack = v.Value;

                _releasePath = resPack.releasePath;
                vo.sizeList  = new List <long>()
                {
                    resPack.packageSize
                };

                FileMark fm = new FileMark(AssetLoader.ExternalHotfixPath, ResPath.Backend + "_" + v.Key);
                if (fm.IsMatch == false)
                {
                    allsize += resPack.packageSize;
                }
            }
            Debug.Log("CheckBackEnd===Size 时间:" + sw.ElapsedMilliseconds);

            return(allsize);
        }
        public static CacheVo CheckLoveStoryCache(int cardId)
        {
            Stopwatch sw = Stopwatch.StartNew();

            CacheVo vo = new CacheVo();

            ResIndex resIndex = GetIndexFile(ResPath.LoveStoryIndex);

            if (resIndex == null || resIndex.packageDict.ContainsKey(cardId.ToString()) == false)
            {
                return(vo);
            }

            ResPack resPack = resIndex.packageDict[cardId.ToString()];

            _releasePath = resPack.releasePath;
            foreach (var resItem in resPack.items)
            {
                FileInfo fileInfo =
                    new FileInfo(AssetLoader.ExternalHotfixPath + "/" + _releasePath + "/" + resItem.Path);

                if (fileInfo.Exists == false || fileInfo.Length != resItem.Size)
                {
                    vo.needDownload = true;
                    break;
                }
            }

            vo.sizeList = new List <long>()
            {
                resPack.packageSize
            };

            Debug.LogError("CheckLoveStoryCache 时间:" + sw.ElapsedMilliseconds);

            return(vo);
        }
        public static void DownloadEvoCard(int cardId, Action <string> onComplete = null, string tag = null)
        {
            _onComplete = onComplete;
            _tag        = tag;

            ResIndex resIndex = GetIndexFile(ResPath.EvoCardIndex);
            ResPack  resPack  = resIndex.packageDict["EvoCard"];

            string  id      = cardId + ".bytes";
            ResItem resItem = null;

            foreach (var item in resPack.items)
            {
                if (item.Path == id)
                {
                    resItem = item;
                    break;
                }
            }

            if (resItem == null)
            {
                FlowText.ShowMessage(I18NManager.Get("Download_IndexNoExist") + cardId);
            }
            else
            {
                resItem.Path = AppConfig.Instance.assetsServer + "/" + AppConfig.Instance.version + "/" +
                               resPack.downloadPath + "/" + id;

                _downloadingWindow          = PopupManager.ShowWindow <DownloadingWindow>(Constants.DownloadingWindowPath);
                _downloadingWindow.Content  = I18NManager.Get("Download_Downloading");
                _downloadingWindow.Progress = I18NManager.Get("Download_Progress", 0);
                DownloadManager.Load(resItem, AssetLoader.ExternalHotfixPath + "/" + resPack.releasePath + "/" + id,
                                     OnCompleteEvoCard, OnErrorEvoCard, OnProgress);
            }
        }
Exemple #19
0
        public static void DownloadAllAudio(Action <string> onComplete = null, string tag = null)
        {
            _onComplete = onComplete;
            _tag        = tag;

            ResIndex resIndex = GetIndexFile(ResPath.AllAudioIndex);
            ResPack  resPack  = resIndex.packageDict["AllAudio"];

            _releasePath = resPack.releasePath;
            if (resPack.packageType == FileType.Zip)
            {
                ResItem item = new ResItem()
                {
                    Md5  = resPack.packageMd5,
                    Path = AppConfig.Instance.assetsServer + "/" + AppConfig.Instance.version + "/" +
                           resPack.downloadPath,
                    Size     = resPack.packageSize,
                    FileType = resPack.packageType
                };

                _downloadingWindow          = PopupManager.ShowWindow <DownloadingWindow>(Constants.DownloadingWindowPath);
                _downloadingWindow.Content  = I18NManager.Get("Download_Downloading");
                _downloadingWindow.Progress = I18NManager.Get("Download_Progress", 0);
                var downItem = DownloadManager.Load(item, AssetLoader.ExternalDownloadPath + "/" + resPack.downloadPath,
                                                    OnComplete,
                                                    OnError, OnProgressAll);

                _downloadingWindow.WindowActionCallback = evt =>
                {
                    if (evt == WindowEvent.Cancel)
                    {
                        downItem.Cancel();
                    }
                };
            }
        }
Exemple #20
0
    private static void CreateSpecial(ExcelWorksheet worksheet, string resId)
    {
        ResIndex resIndex = new ResIndex();

        resIndex.packageDict = new Dictionary <string, ResPack>();

//        1内容	2筛选路径	3白名单	4黑名单 5ID
        var row = worksheet.Dimension.End.Row;

        List <BundleFilter> filterList = new List <BundleFilter>();
        BundleFilter        filter     = null;

        for (int i = 2; i < row; i++)
        {
            object date = worksheet.Cells[i, 2].Value;
            if (date != null)
            {
                filter = new BundleFilter();
                filterList.Add(filter);
                filter.DirPath = date.ToString().Replace("\\", "/");

                string rootFolder = filter.DirPath;

                rootFolder = PackageManager.GetAssetBundleDir() + "/" + rootFolder;

                filter.BlackList = new BlackList();
                filter.WhiteList = new WhiteList();

                filter.BlackList.RootFolder = rootFolder;
                filter.WhiteList.RootFolder = rootFolder;

                AddToNameList(filter.WhiteList, worksheet.Cells[i, 3].Value);
                AddToNameList(filter.BlackList, worksheet.Cells[i, 4].Value);

                filter.Id = worksheet.Cells[i, 5].Value.ToString();
            }
            else
            {
                AddToNameList(filter.WhiteList, worksheet.Cells[i, 3].Value);
                AddToNameList(filter.BlackList, worksheet.Cells[i, 4].Value);
            }
        }

        Dictionary <string, FileInfo> fileDict = new Dictionary <string, FileInfo>();

        foreach (var bundleFilter in filterList)
        {
            List <FileInfo> files = bundleFilter.SearchFile();
            foreach (var fileInfo in files)
            {
                string key = fileInfo.FullName.Replace("\\", "/");
                if (!fileDict.ContainsKey(key))
                {
                    fileDict.Add(key, fileInfo);
                }
            }
            string releasePath = "AssetBundles/" + PackageManager.SystemTag;

            ResPack resPack = new ResPack();
            resPack.id           = bundleFilter.Id;
            resPack.downloadPath = PackageManager.GetPackageStorePath() + "/" + resId;
            resPack.releasePath  = releasePath;
            resPack.items        = new List <ResItem>();
            resIndex.packageDict.Add(resPack.id, resPack);
            foreach (var fileInfo in fileDict)
            {
                ResItem resItem = new ResItem();
                resItem.Path        = GetRelatePath(fileInfo.Value.FullName);
                resItem.Md5         = MD5Util.Get(fileInfo.Key);
                resItem.Size        = fileInfo.Value.Length;
                resPack.packageType = FileType.Original;
                resPack.items.Add(resItem);

                CopyFile(fileInfo.Value.FullName, PackageManager.OutputPath + resId + "/" + resItem.Path);
            }
        }

        string json = JsonConvert.SerializeObject(resIndex, Formatting.Indented);

        FileUtil.SaveFileText(PackageManager.OutputPath, resId + ".json", json);
    }
Exemple #21
0
    public static void CreateSingleZipAndJson(ExcelWorksheet worksheet, string resId)
    {
        ResIndex resIndex = new ResIndex();

//        1内容	2筛选路径 3白名单 4黑名单
        var row = worksheet.Dimension.End.Row;

        List <BundleFilter> filterList = new List <BundleFilter>();
        BundleFilter        filter     = null;

        for (int i = 2; i < row; i++)
        {
            object date = worksheet.Cells[i, 2].Value;
            if (date != null)
            {
                filter = new BundleFilter();
                filterList.Add(filter);
                filter.DirPath = date.ToString();

                string rootFolder = filter.DirPath;

                rootFolder = PackageManager.GetAssetBundleDir() + "/" + rootFolder;

                filter.BlackList = new BlackList();
                filter.WhiteList = new WhiteList();

                filter.BlackList.RootFolder = rootFolder;
                filter.WhiteList.RootFolder = rootFolder;

                AddToNameList(filter.WhiteList, worksheet.Cells[i, 3].Value);
                AddToNameList(filter.BlackList, worksheet.Cells[i, 4].Value);
            }
            else
            {
                AddToNameList(filter.WhiteList, worksheet.Cells[i, 3].Value);
                AddToNameList(filter.BlackList, worksheet.Cells[i, 4].Value);
            }
        }

        resIndex.belong      = resId;
        resIndex.language    = PackageManager.Language;
        resIndex.packageDict = new Dictionary <string, ResPack>();

        Dictionary <string, FileInfo> fileDict = new Dictionary <string, FileInfo>();

        if (resId == ResPath.AppStart)
        {
            //把共享音频放到AppStart里面下载
            string root = PackageManager.GetAssetBundleDir();
            foreach (var id in PackageManager.sharedAudioDict)
            {
                FileInfo fileInfo = new FileInfo(root + "/story/dubbing/" + id.Key + ".bytes");
                string   key      = fileInfo.FullName.Replace("\\", "/");
                fileDict.Add(key, fileInfo);
            }
        }

        foreach (var bundleFilter in filterList)
        {
            List <FileInfo> files = bundleFilter.SearchFile();
            foreach (var fileInfo in files)
            {
                string key = fileInfo.FullName.Replace("\\", "/");
                if (!fileDict.ContainsKey(key))
                {
                    fileDict.Add(key, fileInfo);
                }
            }
        }

        ResPack resPack = new ResPack();

        resPack.id           = resIndex.belong;
        resPack.releasePath  = "AssetBundles/" + PackageManager.SystemTag;
        resPack.downloadPath = PackageManager.GetPackageStorePath() + "/" + resIndex.belong + "/" + resPack.id + ".zip";
        resPack.items        = new List <ResItem>();
        resPack.packageType  = FileType.Zip;
        resIndex.packageDict.Add(resPack.id, resPack);
        foreach (var fileInfo in fileDict)
        {
            ResItem resItem = new ResItem();
            resItem.Path = GetRelatePath(fileInfo.Value.FullName);
            resItem.Md5  = MD5Util.Get(fileInfo.Key);
            resItem.Size = fileInfo.Value.Length;
            resPack.items.Add(resItem);
        }

        DeleteFile(resIndex);
        CopyFile(resIndex);

        string packagePath = PackageManager.OutputPath + resPack.id;

        if (Directory.Exists(packagePath))
        {
            Directory.Delete(packagePath, true);
        }
        Directory.CreateDirectory(packagePath);

        string zipFileName = packagePath + "/" + resPack.id + ".zip";

        string destDir = PackageManager.GetPackageDir() + "/" + resPack.id;

        string[] fileList = Directory.GetFiles(destDir, "*", SearchOption.AllDirectories);

        EditorUtility.DisplayProgressBar("压缩", "正在压缩文件(" + Path.GetFileName(packagePath), 1);

        List <string> pathInZipList = new List <string>();

        for (int i = 0; i < fileList.Length; i++)
        {
            string str = Path.GetDirectoryName(fileList[i]);
            str = str.Replace("\\", "/");
            str = str.Replace(PackageManager.GetPackageDir().Replace("\\", "/") + "/" + resPack.id + "/", "");
            pathInZipList.Add(str + "/");
        }

        ZipUtil.CreateZip(fileList, zipFileName, pathInZipList.ToArray(), 0);

        EditorUtility.ClearProgressBar();

        resPack.packageMd5  = MD5Util.Get(zipFileName);
        resPack.packageSize = new FileInfo(zipFileName).Length;
        string json = JsonConvert.SerializeObject(resIndex, Formatting.Indented);

        FileUtil.SaveFileText(PackageManager.OutputPath, resId + ".json", json);
    }
Exemple #22
0
    public static void CreateMultiZipAndJson(ExcelWorksheet worksheet, string resId)
    {
        Stopwatch sw = Stopwatch.StartNew();

        ResIndex resIndex = new ResIndex();

//        1内容	2筛选路径	3白名单	4黑名单 5ID
        var row = worksheet.Dimension.End.Row;

        List <BundleFilter> filterList = new List <BundleFilter>();
        BundleFilter        filter     = null;

        for (int i = 2; i < row; i++)
        {
            object date = worksheet.Cells[i, 2].Value;
            if (date != null)
            {
                filter = new BundleFilter();
                filterList.Add(filter);
                filter.DirPath = date.ToString().Replace("\\", "/");

                string rootFolder = filter.DirPath;

                rootFolder = PackageManager.GetAssetBundleDir() + "/" + rootFolder;

                filter.BlackList = new BlackList();
                filter.WhiteList = new WhiteList();

                filter.BlackList.RootFolder = rootFolder;
                filter.WhiteList.RootFolder = rootFolder;

                AddToNameList(filter.WhiteList, worksheet.Cells[i, 3].Value);
                AddToNameList(filter.BlackList, worksheet.Cells[i, 4].Value);

                filter.Id = worksheet.Cells[i, 5].Value.ToString();
            }
            else
            {
                AddToNameList(filter.WhiteList, worksheet.Cells[i, 3].Value);
                AddToNameList(filter.BlackList, worksheet.Cells[i, 4].Value);
            }
        }

        resIndex.belong      = resId;
        resIndex.language    = PackageManager.Language;
        resIndex.packageDict = new Dictionary <string, ResPack>();

        Debug.Log("<color='#00ff00'>" + resId + "时间1->" + sw.ElapsedMilliseconds + "</color>");

        DeleteFile(resIndex);

        Debug.Log("<color='#00ff00'>" + resId + "时间2.1->" + sw.ElapsedMilliseconds + "</color>");

        string packagePath = PackageManager.OutputPath + resId;

        if (Directory.Exists(packagePath))
        {
            Directory.Delete(packagePath, true);
        }
        Directory.CreateDirectory(packagePath);

        string releasePath = "AssetBundles/" + PackageManager.SystemTag;

        foreach (var bundleFilter in filterList)
        {
            List <FileInfo> files = bundleFilter.SearchFile();

            ResPack resPack = new ResPack();
            resPack.id           = bundleFilter.Id;
            resPack.releasePath  = releasePath;
            resPack.packageType  = FileType.Zip;
            resPack.downloadPath =
                PackageManager.GetPackageStorePath() + "/" + resIndex.belong + "/" + resPack.id + ".zip";
            resPack.items = new List <ResItem>();
            resIndex.packageDict.Add(resPack.id, resPack);

            foreach (var fileInfo in files)
            {
                ResItem resItem = new ResItem();
                resItem.Path = GetRelatePath(fileInfo.FullName);
                resItem.Md5  = MD5Util.Get(fileInfo.FullName);
                resItem.Size = fileInfo.Length;
                resPack.items.Add(resItem);

                CopyFile(fileInfo.FullName, PackageManager.GetPackageDir() + "/" + resId + "/" + resItem.Path);
            }
        }

        Debug.Log("<color='#00ff00'>" + resId + "时间2.2->" + sw.ElapsedMilliseconds + "</color>");

        foreach (var resPack in resIndex.packageDict)
        {
            string zipFileName = packagePath + "/" + resPack.Value.id + ".zip";

            List <string> fileList = new List <string>();
            string        rootPath = PackageManager.GetPackageDir().Replace("\\", "/") + "/" + resId + "/";
            foreach (var item in resPack.Value.items)
            {
                fileList.Add(rootPath + item.Path);
            }

            EditorUtility.DisplayProgressBar("压缩", "正在压缩文件(" + Path.GetFileName(packagePath) + ")", 1);

            List <string> pathInZipList = new List <string>();
            for (int i = 0; i < fileList.Count; i++)
            {
                string str = Path.GetDirectoryName(fileList[i]);
                str = str.Replace("\\", "/");
                str = str.Replace(
                    PackageManager.GetPackageDir().Replace("\\", "/") + "/" + resId + "/", "");

                pathInZipList.Add(str + "/");
            }

            ZipUtil.CreateZip(fileList.ToArray(), zipFileName, pathInZipList.ToArray(), 0);

            EditorUtility.ClearProgressBar();

            resPack.Value.packageMd5  = MD5Util.Get(zipFileName);
            resPack.Value.packageSize = new FileInfo(zipFileName).Length;
        }

        Debug.Log("<color='#00ff00'>" + resId + "时间3->" + sw.ElapsedMilliseconds + "</color>");

        string json = JsonConvert.SerializeObject(resIndex, Formatting.Indented);

        FileUtil.SaveFileText(PackageManager.OutputPath, resId + ".json", json);
    }
Exemple #23
0
    /// <summary>
    /// 找出剧情第4章以后的音频
    /// </summary>
    static void CopyFile_StoryChapter(BlackList blackList)
    {
        Dictionary <string, List <string> > dict = FindAllStoryAudio();

        Dictionary <string, List <string> > fileDict = new Dictionary <string, List <string> >();

        int fileCount = 0;

        Dictionary <string, bool> includeDict = new Dictionary <string, bool>();

        foreach (var json in dict)
        {
            if (json.Key.Contains("-"))
            {
                int result = 0;
                if (Int32.TryParse(json.Key[0].ToString(), out result))
                {
                    int result2 = 0;
                    if (Int32.TryParse(json.Key.Substring(0, 2), out result2))
                    {
                        if (CheckChapter(result2, blackList))
                        {
                            if (!fileDict.ContainsKey(result2.ToString()))
                            {
                                fileDict.Add(result2.ToString(), new List <string>());
                            }

                            fileDict[result2.ToString()].AddRange(json.Value);
                            fileCount++;
                        }
                        else
                        {
                            AddToInclude(ref includeDict, json.Value);
                        }
                    }
                    else
                    {
                        if (CheckChapter(result, blackList))
                        {
                            if (!fileDict.ContainsKey(result.ToString()))
                            {
                                fileDict.Add(result.ToString(), new List <string>());
                            }

                            fileDict[result.ToString()].AddRange(json.Value);
                            fileCount++;
                        }
                        else
                        {
                            AddToInclude(ref includeDict, json.Value);
                        }
                    }
                }
            }
        }

        Debug.LogError("剧情json数量:" + fileCount);

        string destDir = GetPackageDir() + "/StoryAudio";

        foreach (var file in fileDict)
        {
            DirectoryInfo dir = new DirectoryInfo(destDir + "/" + file.Key);
            if (dir.Exists == false)
            {
                dir.Create();
            }

            int count = 0;
            foreach (var fileName in file.Value)
            {
                CopyDubbingFile(dir.FullName, fileName);

                EditorUtility.DisplayProgressBar("复制音频文件",
                                                 "(" + count + "/" + file.Value.Count + ")" + dir.FullName,
                                                 (float)count / file.Value.Count);
            }
        }

        EditorUtility.ClearProgressBar();

        string packagePath = OutputPath + ModuleConfig.MODULE_MAIN_LINE;

        CreateZip(destDir, packagePath);
        GenerateIndexFile(destDir, Language, ModuleConfig.MODULE_MAIN_LINE,
                          ResPath.MainStoryIndex, "story/dubbing", packagePath);

        //创建包含文件索引
        ResIndex resIndex = new ResIndex();

        resIndex.language    = Language;
        resIndex.packageDict = new Dictionary <string, ResPack>();

        resIndex.belong = "IncludeFiles";
        ResPack resPack = new ResPack();

        resPack.id          = "story0-story1";
        resPack.releasePath = "AssetBundles/" + SystemTag + "/story/dubbing";
        resPack.items       = new List <ResItem>();
        resIndex.packageDict.Add("IncludePack", resPack);

        foreach (var include in includeDict)
        {
            ResItem item = new ResItem();
            item.Path = include.Key + ".bytes";
            resPack.items.Add(item);
        }

        string str = JsonConvert.SerializeObject(resIndex, Formatting.Indented);

        FileUtil.SaveFileText(OutputPath, ResPath.IncludeIndex + ".json", str);
    }
Exemple #24
0
        private ResPack GetResPackFromDisk(string path)
        {
            ResPack pack = new ResPack()
            {
                Name = Path.GetFileName(path),
            };

            if (path.EndsWith(".zip"))
            {
                using (var archive = ZipFile.OpenRead(path))
                {
                    using (var sr = new StreamReader(archive.GetEntry("pack.mcmeta").Open(), Encoding.UTF8))
                    {
                        GetPackInfo(sr.ReadToEnd(), ref pack);
                    }

                    using (var stream = archive.GetEntry("pack.png").Open())
                    {
                        var ms = new MemoryStream();
                        stream.CopyTo(ms);

                        GetPackCover(ms, ref pack);
                        ms.Dispose();
                    }
                    archive.Dispose();
                }
            }
            else
            {
                if (File.Exists(path + @"/pack.mcmeta"))
                {
                    GetPackInfo(File.ReadAllText(path + @"/pack.mcmeta", Encoding.UTF8), ref pack);
                }

                if (File.Exists(path + @"/pack.png"))
                {
                    var fs = File.Open(path + @"/pack.png", FileMode.Open);
                    GetPackCover(fs, ref pack);
                    fs.Dispose();
                }
            }

            return(pack);

            void GetPackCover(Stream stream, ref ResPack _pack)
            {
                _pack.Cover = new BitmapImage();
                _pack.Cover.BeginInit();
                _pack.Cover.StreamSource      = stream;
                _pack.Cover.DecodePixelWidth  = 64;
                _pack.Cover.DecodePixelHeight = 64;
                _pack.Cover.CacheOption       = BitmapCacheOption.OnLoad;
                _pack.Cover.EndInit();
                _pack.Cover.Freeze();
            }

            void GetPackInfo(string str, ref ResPack _pack)
            {
                var PackInfo = JsonMapper.ToObject(str)[0];

                _pack.Format = (int)PackInfo["pack_format"];

                string MC_Version = "适用版本:";

                if (_pack.Format == 1)
                {
                    MC_Version += "1.8及以下\n";
                }
                else if (_pack.Format == 2)
                {
                    MC_Version += "1.9-1.10\n";
                }
                else if (_pack.Format == 3)
                {
                    MC_Version += "1.11及以上\n";
                }

                _pack.Description = MC_Version + PackInfo["description"].ToString();
            }
        }
Exemple #25
0
    static void CopyFile_AllAudio(BlackList blackList)
    {
        Stopwatch sw = Stopwatch.StartNew();

        string dir1 = GetPackageDir() + "/LoveStoryAudio";
        string dir2 = GetPackageDir() + "/StoryAudio";
        string dir3 = GetPackageDir() + "/PhoneAudio";

        string destDir = GetPackageDir() + "/AllAudio";

        if (Directory.Exists(destDir))
        {
            Directory.Delete(destDir, true);
        }

        Directory.CreateDirectory(destDir);

        string[] files = Directory.GetFiles(dir1, "*", SearchOption.AllDirectories);
        CopyFile(files, destDir + "/story/dubbing");

        files = Directory.GetFiles(dir2, "*", SearchOption.AllDirectories);
        CopyFile(files, destDir + "/story/dubbing");

        files = Directory.GetFiles(dir3, "*", SearchOption.AllDirectories);
        CopyFile(files, destDir + "/music/phonedialogs");

        //压缩文件
        string packagePath = OutputPath + "AllAudio";

        if (Directory.Exists(packagePath))
        {
            Directory.Delete(packagePath, true);
        }
        Directory.CreateDirectory(packagePath);

        string zipFileName = packagePath + "/AllAudio.zip";

        files = Directory.GetFiles(destDir, "*", SearchOption.AllDirectories);

        EditorUtility.DisplayProgressBar("压缩", "正在压缩文件(" + Path.GetFileName(packagePath), 1);

        List <string> pathInZipList = new List <string>();

        for (int i = 0; i < files.Length; i++)
        {
            string str = Path.GetDirectoryName(files[i]);
            str = str.Replace("\\", "/");
            str = str.Replace(GetPackageDir().Replace("\\", "/") + "/AllAudio/", "");
            pathInZipList.Add(str + "/");
        }

        ZipUtil.CreateZip(files, zipFileName, pathInZipList.ToArray(), 0);

        EditorUtility.ClearProgressBar();

        //生成Index文件
        string releasePath = "AssetBundles/" + SystemTag + "/";

        ResIndex resIndex = new ResIndex();

        resIndex.language    = Language;
        resIndex.belong      = "AllAudio";
        resIndex.packageDict = new Dictionary <string, ResPack>();

        files = Directory.GetFiles(destDir, "*", SearchOption.AllDirectories);
        ResPack resPack = new ResPack();

        resPack.id           = "AllAudio";
        resPack.items        = new List <ResItem>();
        resPack.packageType  = FileType.Zip;
        resPack.packageMd5   = MD5Util.Get(packagePath + "/" + resPack.id + ".zip");
        resPack.packageSize  = new FileInfo(packagePath + "/" + resPack.id + ".zip").Length;
        resPack.downloadPath = GetPackageStorePath() + "/" + resIndex.belong + "/" + resPack.id + ".zip";
        resPack.releasePath  = releasePath;
        resIndex.packageDict.Add(resPack.id, resPack);

        string json = JsonConvert.SerializeObject(resIndex, Formatting.Indented);

        FileUtil.SaveFileText(OutputPath, ResPath.AllAudioIndex + ".json", json);

        Debug.Log("<color='#00ff66'>CopyFile_AllAudio耗时:" + sw.ElapsedMilliseconds / 1000.0f + "</color>");
    }