Exemplo n.º 1
0
        private void OnMergePatchEnter(int eventID, FSMState preState, FSMState currentState)
        {
            PreloadingUIView.SetProgressName("正在解压安装文件...");
            PreloadingUIView.ResetProgress();
            Debug.Log("正在合并apk包");
            string current       = Application.get_dataPath();
            string newApk        = this.GetNewApkPath();
            string patch         = this.GetNewPatchPath();
            string directoryName = Path.GetDirectoryName(newApk);

            DirectoryUtil.CreateIfNotExist(directoryName);
            this.ApkMerging = false;
            Loom.Current.RunAsync(delegate
            {
                FileHelper.DeleteIfExist(newApk);
                this.ApkMerging = true;
                using (FileStream fileStream = File.Open(current, 3, 1, 1))
                {
                    using (FileStream fileStream2 = File.Open(newApk, 2, 2))
                    {
                        BinaryPatchUtility.Apply(fileStream, () => File.Open(patch, 3, 1, 1), fileStream2);
                    }
                }
                this.ReactSync(UpdateEvent2.Next);
            });
        }
Exemplo n.º 2
0
 public static void Copy(string src, string dst)
 {
     DirectoryUtil.CreateIfNotExist(dst);
     string[] files = Directory.GetFiles(src);
     string[] array = files;
     for (int i = 0; i < array.Length; i++)
     {
         string text     = array[i];
         string fileName = Path.GetFileName(text);
         string text2    = PathUtil.Combine(new string[]
         {
             dst,
             fileName
         });
         File.Copy(text, text2);
     }
     string[] directories = Directory.GetDirectories(src);
     for (int j = 0; j < directories.Length; j++)
     {
         string text3     = directories[j];
         string fileName2 = Path.GetFileName(text3);
         string dst2      = PathUtil.Combine(new string[]
         {
             dst,
             fileName2
         });
         DirectoryUtil.Copy(text3, dst2);
     }
 }
Exemplo n.º 3
0
 private void InitDownloader()
 {
     try
     {
         this.fileName     = this.URL.Substring(this.URL.LastIndexOf('/') + 1);
         this.fileFullName = this.LocalPath;
         if (this.fs != null)
         {
             this.fs.Dispose();
         }
         if (this.md5s == null || string.IsNullOrEmpty(this.md5s.get_Item(this.downloadFileIndex)))
         {
             this.CanCheck = false;
         }
         else
         {
             this.CanCheck = true;
         }
         bool flag = true;
         if (this.CanCheck)
         {
             string text        = this.md5s.get_Item(this.downloadFileIndex);
             string md5FilePath = Downloader.GetMd5FilePath(this.fileFullName);
             if (File.Exists(md5FilePath))
             {
                 string text2 = File.ReadAllText(md5FilePath);
                 flag = !text2.Equals(text);
             }
             else
             {
                 string directoryName = Path.GetDirectoryName(md5FilePath);
                 DirectoryUtil.CreateIfNotExist(directoryName);
                 File.WriteAllText(md5FilePath, text);
             }
         }
         if (flag)
         {
             string directoryName2 = Path.GetDirectoryName(this.fileFullName);
             DirectoryUtil.CreateIfNotExist(directoryName2);
             this.fs = new FileStream(this.fileFullName, 2, 2, 0, 524288, true);
         }
         else
         {
             this.fs = new FileStream(this.fileFullName, 6, 2, 0, 524288, true);
         }
         this.localFileSize = (int)this.fs.get_Length();
         this.from          = (int)this.fs.get_Length();
     }
     catch (Exception ex)
     {
         Debug.LogError("InitDownloader Exception has been thrown!");
         Debug.LogError(ex.ToString());
         if (!this.ManualHandle)
         {
             this.FinishCallback.Invoke(this.allIsFinish);
         }
     }
 }
Exemplo n.º 4
0
    private void InstallByApkPatch()
    {
        this.InstallUpdate = new Action(this.InstallByApkPatchUpdate);
        Debug.LogFormat("InstallByApkPatch", new object[0]);
        string newApk  = this.GetNewApkPath();
        string current = NativeCallManager.GetApkPath();
        string patch   = this.GetNewPatchPath();

        Loom.Current.RunAsync(delegate
        {
            FileInfo fileInfo = new FileInfo(newApk);
            if (fileInfo.get_Exists() && fileInfo.get_Length() >= (long)this.UpdateInfo.CurrentApkInfo.ApkFileInfo.FileSize)
            {
                string text = MD5Util.EncryptFile(newApk);
                if (this.UpdateInfo.CurrentApkInfo.ApkFileInfo.Md5.Equals(text))
                {
                    Loom.Current.QueueOnMainThread(delegate
                    {
                        NativeCallManager.InstallPackage(newApk);
                        this.InstallNext();
                    });
                }
                else
                {
                    this.ClearApk();
                    this.ClearApkPatch();
                    Action onClick = delegate
                    {
                        this.ReactSync(UpdateEvent.False);
                    };
                    Loom.Current.QueueOnMainThread(delegate
                    {
                        this.ShowDownloadFailed(onClick);
                    });
                }
            }
            else
            {
                string directoryName = Path.GetDirectoryName(newApk);
                DirectoryUtil.CreateIfNotExist(directoryName);
                FileHelper.DeleteIfExist(newApk);
                this.MergeFile = new FileInfo(newApk);
                using (FileStream fileStream = File.Open(current, 3, 1, 1))
                {
                    using (FileStream fileStream2 = File.Open(newApk, 2, 2))
                    {
                        BinaryPatchUtility.Apply(fileStream, () => File.Open(patch, 3, 1, 1), fileStream2);
                    }
                }
                Loom.Current.QueueOnMainThread(delegate
                {
                    this.InstallByApkPatch();
                });
            }
        });
    }
Exemplo n.º 5
0
    public void UnZip(object _zipFileArgs)
    {
        ZipFileArgs zipFileArgs = (ZipFileArgs)_zipFileArgs;
        string      zipFile     = zipFileArgs.zipFile;

        this.dataPath = zipFileArgs.TarDir;
        bool overWrite = zipFileArgs.OverWrite;

        this.UnZipFinish = zipFileArgs.unZipFinish;
        this.FilterDir   = zipFileArgs.FilterDir;
        if (string.IsNullOrEmpty(zipFile))
        {
            Debug.LogError("ZipFileName is null: " + zipFile);
            return;
        }
        if (!File.Exists(zipFile))
        {
            Debug.LogError("Cannot find file:" + zipFile);
            return;
        }
        this.zipFileName = zipFile;
        this.fileSize    = new FileInfo(zipFile).get_Length();
        Debug.Log(string.Concat(new object[]
        {
            "UnZip File: ",
            zipFile,
            " fileSize:",
            this.fileSize
        }));
        this.WaitUnZipFiles  = 0;
        this.nowUnZipFile    = 0;
        this.finishThreadNum = 0;
        this.unzipFileCount  = 0;
        using (ZipInputStream zipInputStream = new ZipInputStream(File.OpenRead(this.zipFileName)))
        {
            ZipEntry nextEntry;
            while ((nextEntry = zipInputStream.GetNextEntry()) != null)
            {
                this.WaitUnZipFiles++;
                string text    = Path.GetDirectoryName(nextEntry.get_Name());
                string relPath = this.GetRelPath(text);
                if (!string.IsNullOrEmpty(relPath))
                {
                    text = Path.Combine(this.dataPath, relPath);
                    DirectoryUtil.CreateIfNotExist(text);
                }
            }
        }
        Debug.Log("ThreadNum:" + this.ThreadNum);
        for (int i = 1; i <= this.ThreadNum; i++)
        {
            ThreadPool.QueueUserWorkItem(new WaitCallback(this.UnZipNextFile));
        }
    }
Exemplo n.º 6
0
    private void SetVersionFileText(string key, string value)
    {
        string text = PathUtil.Combine(new string[]
        {
            PathSystem.PersistentDataPath,
            key
        });
        string directoryName = Path.GetDirectoryName(text);

        DirectoryUtil.CreateIfNotExist(directoryName);
        File.WriteAllText(text, value);
    }