コード例 #1
0
        public static async void Export(string str, PatchInfo info, string PatchPath, string path_NewStandAlone,
                                        string path_OldStandAlone, string path_OutputPatchFiles, string NameOfCompressionZip,
                                        Func <string, float> OnInitialize,
                                        Func <float, int, float> OnUpdate, Action <string> OnComplete)
        {
            float counter = OnInitialize("Exporting...");

            info = JsonConvert.DeserializeObject <PatchInfo>(File.ReadAllText(PatchPath + "/patch.txt"));
            string tmpPath     = "";
            string currentPath = "";
            int    total       = info.filesToAdd.Count + info.filesToReplace.Count;

            try
            {
                foreach (var item in info.filesToReplace)
                {
                    currentPath = str + item.Key.Substring(path_NewStandAlone.Length);
                    using (FileStream reader = new FileStream(item.Key, FileMode.OpenOrCreate, FileAccess.Read))
                    {
                        if (!Directory.Exists(tmpPath = Path.GetDirectoryName(currentPath)))
                        {
                            Directory.CreateDirectory(tmpPath);
                        }

                        using (FileStream writer = new FileStream(currentPath, FileMode.OpenOrCreate, FileAccess.Write))
                        {
                            await reader.CopyToAsync(writer);
                        }
                    }
                    counter = OnUpdate(counter, total);
                }
            }
            catch (Exception ex)
            {
                UnityEngine.Debug.Log(ex.HelpLink + " " + ex.Message);
            }

            //OnComplete("Exporting");
            GenerateClientPatch(str, PatchPath, info, path_NewStandAlone, path_OldStandAlone, path_OutputPatchFiles, NameOfCompressionZip, OnInitialize, OnComplete);
        }
コード例 #2
0
        private static async void GenerateClientPatch(string str, string PatchPath, PatchInfo info, string path_NewStandAlone,
                                                      string path_OldStandAlone, string path_OutputPatchFiles, string Name_ZipPatchForCompression, Func <string, float> OnUpdate = null, Action <string> OnComplete = null)
        {
            try
            {
                info = JsonConvert.DeserializeObject <PatchInfo>(File.ReadAllText(PatchPath + "/patch.txt"));
                PatchInfo clientInfo = new PatchInfo();

                foreach (KeyValuePair <string, string> item in info.filesToAdd)
                {
                    clientInfo.filesToAdd.Add(item.Key.Substring(path_NewStandAlone.Length), item.Value.Substring(path_OldStandAlone.Length));
                }

                foreach (KeyValuePair <string, string> item in info.filesToDelete)
                {
                    clientInfo.filesToDelete.Add(item.Key.Substring(path_OldStandAlone.Length), "");
                }

                foreach (KeyValuePair <string, string> item in info.filesToReplace)
                {
                    clientInfo.filesToReplace.Add(item.Key.Substring(path_NewStandAlone.Length), item.Value.Substring(path_OldStandAlone.Length));
                }

                using (StreamWriter PatchWriter = new StreamWriter(path_OutputPatchFiles + "/patch.txt"))
                {
                    await PatchWriter.WriteLineAsync(JsonConvert.SerializeObject(clientInfo));
                }
            }
            catch (Exception ex)
            {
                UnityEngine.Debug.Log(ex.Message);
            }

            // TODO: Need to track progress of Compressing Patch
            OnUpdate?.Invoke("Cant track Compression progress, just wait.");
            CompressPatchFolder(str, path_OutputPatchFiles, Name_ZipPatchForCompression);
            OnComplete?.Invoke("Done Compression");
        }