Exemple #1
0
        public GenerateJsonDone SerializeToJson(List <ResourceInfo> TotalResInfo, List <string> plistName)
        {
            var count = 0;
            var dict  = TotalResInfo.ToDictionary(key => key.FileName, value =>
            {
                var item = new ConfigItem()
                {
                    Name      = value.FileName,
                    Time      = value.Time,
                    Tag       = ResourceTag.TagsMap[value.Tag],
                    Md5       = value.MD5,
                    Extension = value.Extension
                };
                if (item.Tag == ResourceTag.TagsMap[ResourceTag.TexturePackage])
                {
                    count = count + 1;
                }
                return(item);
            });
            var json = JsonConvert.SerializeObject(new ConfigTemplate()
            {
                resource = dict,
                plist    = count != 0 ? plistName : null
            }, Formatting.Indented);
            var path = DirTools.GetTempConfigPath() + "/ResConfig.json";

            File.WriteAllText(path, json);
            if (dict.Count == 0)
            {
                return(new GenerateJsonDone()
                {
                    Ret = false,
                    Reason = "没资源生成个毛线啊",
                    Files = new List <string>()
                    {
                        path
                    }
                });
            }
            return(new GenerateJsonDone()
            {
                Ret = true,
                Reason = "生成配置成功",
                Files = new List <string>()
                {
                    path
                }
            });
        }
Exemple #2
0
        IEnumerator UploadZip(int itemId)
        {
            yield return(StartCoroutine(UploadZipToCloud(itemId)));

            var filePath = DirTools.GetBasePath() + "/res.zip";

            if (!File.Exists(filePath))
            {
                Debug.LogError("未发现资源!!!");
                yield return(null);
            }
            else
            {
                FileStream fs    = new FileStream(filePath, FileMode.Open, FileAccess.Read);
                byte[]     bytes = new byte[fs.Length];
                fs.Read(bytes, 0, (int)fs.Length);
                fs.Close();
                WWWForm form = new WWWForm();
                form.AddBinaryData("file", bytes, "res.zip");
                var webRequest = UnityWebRequest.Post(AppConfig.JiuquUrl + "/admin-course/asset/uploadSingle", form);
                webRequest.SetRequestHeader("Authorization", GetAuthCode());
                webRequest.SendWebRequest();
                var httpProgress = Instantiate(HttpProgress, transform);
                yield return(StartCoroutine(httpProgress.GetComponent <WebRequest>().Process(webRequest, "正在上传到后台...")));

                if (webRequest.isNetworkError)
                {
                    Debug.Log(": Error: " + webRequest.error);
                }
                else
                {
                    Debug.Log(webRequest.downloadHandler.text);
                    var dict          = JsonConvert.DeserializeObject <Dictionary <string, string> >(webRequest.downloadHandler.text);
                    var attachment_id = dict["id"];
                    _attachmentId = attachment_id;
                }
            }
        }
Exemple #3
0
 // Start is called before the first frame update
 void Start()
 {
     DirTools.ClearTempPath();
     TypeEventSystem.Register <FileDragIn>((fileDragIn) => {
         var path = fileDragIn.Path;
         System.IO.FileInfo file = new System.IO.FileInfo(path);
         if (file.Extension == ".zip")
         {
             ImportZip(path);
             return;
         }
         else if (file.Extension == ".csb")
         {
             // var csbInspector = transform.GetComponent<CsbInspector>();
             // var totalInfo = transform.GetComponent<QFramework.Example.UIPanel>().GetTotalInfo();
             // totalInfo = totalInfo.Where((info) => { return info.Extension == ".csb"; }).ToList();
             // var paths = totalInfo.Select((info) => { return info.FileFullName; }).ToList();
             // paths.Add(path);
             // var totalPaths = new List<string>();
             // paths.ForEach((name) =>
             // {
             //     totalPaths.AddRange(csbInspector.GetCsbImagePath(name));
             // });
             // totalPaths = totalPaths.Select((t) => { return Path.GetFileName(t); }).ToList();
             // totalPaths = totalPaths.Distinct().ToList();
             // transform.GetComponent<AppData>().CsbImagePaths = totalPaths;
         }
         else if (file.Extension == ".png")
         {
             // var ret = isCocosStudioImage(path);
             // if (ret)
             // {
             //     fileDragIn.Tag = ResourceTag.CocosStudio;
             // }
         }
         var tempPath = DirTools.GetTempPath();
         File.Copy(file.FullName, tempPath + "/" + file.Name, true);
         var md5Code = GetMD5HashFromFile(path);
         if (md5Code == null)
         {
             SimplePopupManager.Instance.CreatePopup(string.Format("{0}可能被占用", fileDragIn.Path));
             SimplePopupManager.Instance.AddButton("朕知道了", delegate {  });
             SimplePopupManager.Instance.ShowPopup();
             return;
         }
         TypeEventSystem.Send(new FileInfo()
         {
             FileName     = file.Name,
             FileFullName = tempPath + "/" + file.Name,
             Extension    = file.Extension,
             Time         = DateTime.Now,
             MD5          = md5Code,
             Tag          = fileDragIn.Tag,
             DropType     = fileDragIn.Point.x < 860 ? DragDropType.Add : DragDropType.Replace,
         });
     });
     if (Application.platform == RuntimePlatform.WindowsEditor)
     {
         var path = @"C:\Users\yzqlw\Desktop\png";
         Directory.GetFiles(path, "*").ForEach((file) =>
         {
             TypeEventSystem.Send(new FileDragIn()
             {
                 Path = file,
                 Tag  = ResourceTag.Default
             });
         });
         // TypeEventSystem.Send(new FileDragIn()
         // {
         //     Path = path,
         //     Tag = ResourceTag.Default
         // });
         Invoke("test", 3.0f);
     }
     else if (Application.platform == RuntimePlatform.OSXEditor || Application.platform == RuntimePlatform.OSXPlayer)
     {
         var path = @"/Users/yzqlwt/Desktop/image";
         Directory.GetFiles(path, "*").ForEach((file) => {
             TypeEventSystem.Send(new FileDragIn()
             {
                 Path  = file,
                 Tag   = ResourceTag.Default,
                 Point = new POINT(900, 100)
             });
         });
     }
 }
Exemple #4
0
        void ImportZip(string path)
        {
            var tempPath  = DirTools.GetTempPath();
            var unzipPath = tempPath + "/unzip";

            if (Directory.Exists(unzipPath))
            {
                DirTools.DeleteFilesAndFolders(unzipPath);
            }
            ZipUtil.UnZipFile(path, unzipPath);
            var isExist = File.Exists(unzipPath + "/ResConfig.json");
            var ret     = false;

            if (isExist)
            {
                StreamReader sr = new StreamReader(unzipPath + "/ResConfig.json");
                if (sr == null)
                {
                    return;
                }
                string json = sr.ReadToEnd();
                sr.Close();
                var configTemplate = JsonConvert.DeserializeObject <ConfigTemplate>(json);
                if (configTemplate.resource != null)
                {
                    ret = true;
                }
            }
            if (ret)
            {
                StreamReader sr = new StreamReader(unzipPath + "/ResConfig.json");
                if (sr == null)
                {
                    return;
                }
                string json = sr.ReadToEnd();
                sr.Close();
                var configTemplate = JsonConvert.DeserializeObject <ConfigTemplate>(json);
                configTemplate.resource.Where((item) =>
                {
                    return(item.Value.Tag != ResourceTag.TagsMap[ResourceTag.TexturePackage]);
                }).ForEach((item) =>
                {
                    var tag = ResourceTag.TagsMap.Where((tagItem) => { return(tagItem.Value == item.Value.Tag); })
                              .First().Key;
                    string filepath = "";
                    if (tag == ResourceTag.None)
                    {
                        filepath = unzipPath + "/none/" + item.Value.Name;
                    }
                    else if (tag == ResourceTag.CocosStudio)
                    {
                        filepath = unzipPath + "/" + item.Value.Name;
                    }
                    Debug.Log(string.Format("从zip导入文件路径{0} 文件Tag{1}", filepath, tag));
                    TypeEventSystem.Send(new FileDragIn()
                    {
                        Path = filepath,
                        Tag  = tag
                    });
                });
                if (configTemplate.plist != null)
                {
                    configTemplate.plist.ForEach((name) =>
                    {
                        var plistPath = unzipPath + "/plist/" + name + ".plist";
                        var pngPath   = unzipPath + "/plist/" + name + ".png";
                        Unpacker(plistPath, pngPath);
                    });
                    configTemplate.resource.Where((item) =>
                    {
                        return(item.Value.Tag == ResourceTag.TagsMap[ResourceTag.TexturePackage]);
                    }).ForEach((item) =>
                    {
                        var md5          = item.Value.Md5;
                        string imagePath = DirTools.GetRestoredPNGDir() + "/" + md5 + item.Value.Extension;
                        Debug.Log(imagePath);
                        if (File.Exists(imagePath))
                        {
                            File.Move(imagePath, DirTools.GetRestoredPNGDir() + "/" + item.Value.Name);
                            TypeEventSystem.Send(new FileDragIn()
                            {
                                Path = DirTools.GetRestoredPNGDir() + "/" + item.Value.Name,
                                Tag  = ResourceTag.TexturePackage
                            });
                        }
                        else
                        {
                            Debug.Log("bububu");
                        }
                    });
                }
            }
            else
            {
                Directory.GetFiles(unzipPath, "*").ForEach((file) =>
                {
                    var extension = System.IO.Path.GetExtension(file);
                    if (extension != ".plist")
                    {
                        TypeEventSystem.Send(new FileDragIn()
                        {
                            Path = file,
                            Tag  = ResourceTag.Default
                        });
                    }
                    else
                    {
                        var pathName  = System.IO.Path.GetDirectoryName(file);
                        var fileName  = System.IO.Path.GetFileNameWithoutExtension(file);
                        var plistPath = file;
                        var pngPath   = pathName + '/' + fileName + ".png";
                        Unpacker(plistPath, pngPath);
                        var RestoredPath = DirTools.GetRestoredPNGDir();
                        Directory.GetFiles(RestoredPath, "*").ForEach((filePath) =>
                        {
                            TypeEventSystem.Send(new FileDragIn()
                            {
                                Path = filePath,
                                Tag  = ResourceTag.Default
                            });
                        });
                    }
                });
            }
        }