Ejemplo n.º 1
0
        private void CopyToStreamingAssets(BuildVersion buildVersion)
        {
            m_outputPlatformPath = string.Format($"{FinalPatchConst.ROOT_PATH}/{buildVersion.name}");
            m_outputFullPath     = FinalPatchUtility.GetOutputFullPath(m_outputPlatformPath, buildVersion.version);
            // copy asset bundles
            foreach (var file in Directory.GetFiles(m_outputFullPath, "*", SearchOption.AllDirectories))
            {
                string fileName = Path.GetFileName(file);
                if (fileName == FinalPatchConst.PATCH_DATA_FILE_NAME)
                {
                    continue;
                }

                string toPath = $"Assets/StreamingAssets/{FinalPatchConst.ASSET_BUNDLE_SUBDIRECTORY_NAME}{file.Remove(0, m_outputFullPath.Length)}";
                string toDir  = Path.GetDirectoryName(toPath);
                if (!Directory.Exists(toDir))
                {
                    Directory.CreateDirectory(toDir);
                }

                File.Copy(file, toPath, true);
            }

            PatchData patchData = PatchData.LoadAtPath(FinalPatchUtility.GetFullPatchDataFilePath(m_outputPlatformPath, buildVersion.version));

            patchData.SaveToStreamingAssets();
            AssetDatabase.Refresh();
        }
Ejemplo n.º 2
0
        private bool Validate(int version)
        {
            bool validation = true;

            if (version > 1)
            {
                // check previous version file
                string previousVersionPath = $"{FinalPatchUtility.GetFullPatchDataFilePath(m_outputPlatformPath, version - 1)}";
                if (!File.Exists(previousVersionPath))
                {
                    Debug.LogError(Localization.GetString("msg_build_failure_no_previous_patch_data"));
                    validation = false;
                }
            }

            if (!validation)
            {
                m_managerWindow.ShowNotification(new GUIContent(Localization.GetString("msg_build_failure_notification")));
            }
            return(validation);
        }
Ejemplo n.º 3
0
        private void BuildIncrementalPackage(int version)
        {
            if (Directory.Exists(m_outputPackagePath))
            {
                Directory.Delete(m_outputPackagePath, true);
            }
            Directory.CreateDirectory(m_outputPackagePath);

            // copy current version bundle files
            foreach (var bundle in PatchData.LoadAtPath($"{FinalPatchUtility.GetFullPatchDataFilePath(m_outputPlatformPath, version)}").Bundles)
            {
                if (bundle.Version != version)
                {
                    continue;
                }

                string fromPath = $"{m_outputFullPath}/{bundle.Name}";
                string toPath   = $"{m_outputPackagePath}/{bundle.Name}";
                CopyBundle(fromPath, toPath);
            }

            // copy patch data
            File.Copy($"{m_outputFullPath}/{FinalPatchConst.PATCH_DATA_FILE_NAME}", $"{m_outputPackagePath}/{FinalPatchConst.PATCH_DATA_FILE_NAME}", true);
        }
Ejemplo n.º 4
0
        private PatchData SavePatchData(string build, int version)
        {
            var bundleFiles = Directory.GetFiles(m_outputFullPath, "*", SearchOption.AllDirectories);

            PatchData currentPatchData = new PatchData
            {
                Build   = build,
                Bundles = new List <BundleData>()
            };

            SHA1 hashAlgorithm = SHA1.Create();

            foreach (var file in bundleFiles)
            {
                string generalFile = file.Replace('\\', '/');
                string bundleName  = generalFile.Remove(0, m_outputFullPath.Length + 1);
                string hash        = null;
                long   size        = 0;
                try
                {
                    using (FileStream fs = File.Open(generalFile, FileMode.Open, FileAccess.Read))
                    {
                        hash = BitConverter.ToString(hashAlgorithm.ComputeHash(fs)).Replace("-", string.Empty);
                        size = fs.Length;
                    }
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                    continue;
                }

                BundleData bundleData = new BundleData()
                {
                    Name    = bundleName,
                    Hash    = hash.ToString(),
                    Size    = size,
                    Version = version,
                };
                currentPatchData.Bundles.Add(bundleData);
            }

            // calc bundle version
            PatchData prevPatchData = PatchData.LoadAtPath($"{FinalPatchUtility.GetFullPatchDataFilePath(m_outputPlatformPath, version - 1)}");

            if (prevPatchData != null)
            {
                foreach (var currentBundle in currentPatchData.Bundles)
                {
                    BundleData prevBundle = prevPatchData.Bundles.Find((bundle) => bundle.Name == currentBundle.Name);
                    if (prevBundle == null)
                    {
                        continue;
                    }

                    if (currentBundle.Hash == prevBundle.Hash)
                    {
                        currentBundle.Version = prevBundle.Version;
                    }
                }
            }

            using (MemoryStream ms = new MemoryStream())
            {
                BinaryFormatter binaryFormatter = new BinaryFormatter();
                binaryFormatter.Serialize(ms, currentPatchData);
                ms.Seek(0, SeekOrigin.Begin);
                currentPatchData.Hash = BitConverter.ToString(hashAlgorithm.ComputeHash(ms)).Replace("-", string.Empty);
            }
            currentPatchData.Save($"{FinalPatchUtility.GetFullPatchDataFilePath(m_outputPlatformPath, version)}");
            return(currentPatchData);
        }