Esempio n. 1
0
        async Task ScatterUpdate()
        {
            byte[] data = await Download(PathRouter.FileManifest);

            data            = FileLoader.RemoveBOM(data);
            newFileManifest = JsonUtility.FromJson <FileManifest>(Encoding.UTF8.GetString(data));
            newFileManifest.BuildQuery();
            HotfixLog.LogFormat("Manifest(new), files: {0}", newFileManifest.files.Count);

            var updateFiles = fileManager.CalculateUpdateFiles(newFileManifest);

            foreach (string name in updateFiles)
            {
                HotfixLog.Log("Update file: " + name);
                string file         = PathRouter.SandboxPath + name;
                string downloadFile = file + ".download";
                Directory.CreateDirectory(Path.GetDirectoryName(file));

                try
                {
                    await DownloadToFile(name, downloadFile);

                    File.Delete(file);
                    File.Move(downloadFile, file);
                    fileManager.AddFile(name);
                }
                catch (Exception e)
                {
                    File.Delete(downloadFile);
                    throw e;
                }
            }
        }
Esempio n. 2
0
        void SandboxExpireCheck()
        {
            if (!Directory.Exists(PathRouter.SandboxPath))
            {
                Directory.CreateDirectory(PathRouter.SandboxPath);
                return;
            }

            string sanboxVersionFile = PathRouter.SandboxPath + PathRouter.Version;
            bool   exists            = File.Exists(sanboxVersionFile);

            if (exists)
            {
                Version sandboxVersion   = Version.Create(File.ReadAllBytes(sanboxVersionFile));
                string  inAppVersionFile = PathRouter.StreamingPath + PathRouter.Version;
                Version inAppVersion;
                if (Application.platform == RuntimePlatform.Android)
                {
                    inAppVersion = Version.Create(AndroidPlugin.GetAssetBytes(inAppVersionFile));
                }
                else
                {
                    inAppVersion = Version.Create(File.ReadAllBytes(inAppVersionFile));
                }

                if (inAppVersion > sandboxVersion)
                {
                    Directory.Delete(PathRouter.SandboxPath, true);
                    HotfixLog.LogFormat(
                        "Clear sandbox files, version(inApp:{0}) > version(sandbox:{1})",
                        inAppVersion, sandboxVersion);
                }
            }
        }
Esempio n. 3
0
        public void ClearUnusedFiles()
        {
            List <string> filesToRemove = new List <string>();

            foreach (string dir in Directory.EnumerateDirectories(PathRouter.SandboxPath))
            {
                foreach (string file in Directory.EnumerateFiles(dir, "*.*", SearchOption.AllDirectories))
                {
                    string path = PathRouter.NormalizePath(file);
                    string name = path.Remove(0, PathRouter.SandboxPath.Length);
                    if (!manifest.query.ContainsKey(name))
                    {
                        filesToRemove.Add(path);
                    }
                }
            }

            foreach (string file in filesToRemove)
            {
                File.Delete(file);
                string name = file.Remove(0, PathRouter.SandboxPath.Length);
                sandboxFiles.Remove(name);
                HotfixLog.Log("Remove unused file: " + name);
            }
        }
Esempio n. 4
0
        void InitVersion()
        {
            version = Version.Create();
            HotfixLog.LogFormat("Version(local): {0} cdn: {1}", version.Name, version.Cdn);

            fileManager = FileManager.Create();
            HotfixLog.LogFormat(
                "Manifest(local), files: {0}, sandbox files: {1}",
                fileManager.manifest.files.Count,
                fileManager.sandboxFiles.Count);
        }
Esempio n. 5
0
        protected override async Task AsyncInit()
        {
            if (ResourceSystem.ResMode == ResourceSystem.Mode.Dev)
            {
                HotfixLog.Log("Skip hotfix process in Dev mode");
                return;
            }

            HotfixLog.Log("SandboxExpireCheck");
            SandboxExpireCheck();
            HotfixLog.Log("InitVersion");
            InitVersion();

            if (version.Cdn.Contains("skip-update"))
            {
                HotfixLog.Log("Skip hotfix since this package is marked as 'skip-update'");
                return;
            }

            HotfixLog.Log("NewVersionCheck");
            var verCheckRet = await NewVersionCheck();

            HotfixLog.Log("NewVersionCheck result: " + verCheckRet);
            if (verCheckRet == VersionCheckResult.AppUpdate)
            {
                // TODO: notify user and direct to app store
                // IMPORTANT: In most cases termination of application under iOS should be left at the user discretion. Consult Apple Technical Page qa1561 for further details.
                HotfixLog.LogFormat(
                    "App update required, {0} -> {1}",
                    version,
                    newVersion);

                if (Application.isEditor)
                {
                    throw new Exception();
                }
                else
                {
                    Application.Quit();
                }
            }

            HotfixLog.Log("ScatterUpdate");
            await ScatterUpdate();

            HotfixLog.Log("ApplyNewVersion");
            ApplyNewVersion();

            HotfixLog.Log("ClearUnusedFiles");
            Instance.fileManager.ClearUnusedFiles();

            HotfixLog.Log("Done");
        }
Esempio n. 6
0
        public HotfixSystem()
        {
            var p = Application.platform;

            if (p == RuntimePlatform.WindowsEditor || p == RuntimePlatform.Android)
            {
                platform = "Android";
            }
            else if (p == RuntimePlatform.OSXEditor || p == RuntimePlatform.IPhonePlayer)
            {
                platform = "iOS";
            }
            HotfixLog.Log("Platform: " + platform);
        }
Esempio n. 7
0
        async Task <VersionCheckResult> NewVersionCheck()
        {
            byte[] data = await Download(PathRouter.Version);

            newVersion = Version.Create(data);
            HotfixLog.LogFormat("Version(new): {0} cdn: {1}", newVersion.Name, newVersion.Cdn);

            var result = VersionCheckResult.Latest;

            if (version > newVersion)
            {
                throw new ApplicationException(string.Format(
                                                   "version({0}) > new version({1})",
                                                   version, newVersion));
            }
            else if (version < newVersion)
            {
                result = version.Major < newVersion.Major
                    ? VersionCheckResult.AppUpdate
                    : VersionCheckResult.ResUpdate;
            }

            return(result);
        }
Esempio n. 8
0
 public static void Start()
 {
     HotfixLog.Log("Hello ILRuntime World");
     Demo.Instance.Start();
 }