IEnumerator BackupConfig(AttachmentsConfig config, string type) { var url = string.Format("http://gate-static.97kid.com/{0}", config.attachments.uri); UnityWebRequest webRequest = UnityWebRequest.Get(url); yield return(webRequest.SendWebRequest()); if (webRequest.isNetworkError) { Debug.Log(": Error: " + webRequest.error); } else { DateTime date = DateTime.Now; var dateStr = date.ToString("yyyyMMdd-HH时mm分ss秒"); var zipPath = DirTools.GetBackupDir() + "/" + dateStr + "." + config.attachments.ext_name; Debug.Log(zipPath); var data = webRequest.downloadHandler.data; File.WriteAllBytes(zipPath, data); if (type == "replace") { StartCoroutine(UploadConfig(config)); } else if (type == "restore") { DirTools.DeleteFolder(DirTools.GetUnZipDir()); ZipUtil.UnZipFile(zipPath, DirTools.GetUnZipDir()); StartCoroutine(Unpacker(DirTools.GetUnZipDir() + "/default.plist", DirTools.GetUnZipDir() + "/default.png")); } } }
IEnumerator Unpacker(string plistFilePath, string pngFilePath) { DirTools.DeleteFolder(DirTools.GetRestoredPNGDir()); var loader = NRatel.TextureUnpacker.Loader.LookingForLoader(plistFilePath); if (loader != null) { var plist = loader.LoadPlist(plistFilePath); var bigTexture = loader.LoadTexture(pngFilePath, plist.metadata); int total = plist.frames.Count; int count = 0; foreach (var frame in plist.frames) { try { Core.Restore(bigTexture, frame); count += 1; } catch { } } } DirectoryInfo dir = new DirectoryInfo(DirTools.GetUnZipDir()); FileInfo[] finfo = dir.GetFiles(); for (int i = 0; i < finfo.Length; i++) { var file = finfo[i]; if (file.Name.IndexOf("plist") > -1 || file.Name.IndexOf("png") > -1) { } else { File.Copy(file.FullName, DirTools.GetRestoredPNGDir() + "/" + file.Name, true); } } ImportToResPanel(); yield return(null); }