Пример #1
0
 // Update is called once per frame
 IEnumerator ZipUpdate()
 {
     while (true)
     {
         ZipProxy.checkoutZipProxy();
         yield return(new WaitForSeconds(0.33f));
     }
 }
Пример #2
0
		public static ZipProxy uncompless(string zipFile, string extralPath,
			System.Action<object> endCallback, System.Action<Exception> errorCallback)
		{
			ZipProxy proxy = new ZipProxy();
			proxy.m_zipPath = zipFile;
			proxy.m_extralPath = extralPath;
			proxy.m_isDone = false;
			proxy.m_isError = false;
			proxy.m_endCallback = endCallback;
			proxy.m_errorCallback = errorCallback;
			proxy.m_exception = null;
			proxy.m_totalCount = 0;
			proxy.m_decompressCount = 0;
			ThreadPool.QueueUserWorkItem(new WaitCallback(
				delegate(object t)
				{
					Exception exception = null;
					ZipProxy arg = (ZipProxy)t;
					byte[] buffer = new byte[1048576];

					//the count of files in zip
					int totalCount = 0;
					using(FileStream fs = new FileStream(arg.m_zipPath, FileMode.Open, FileAccess.Read))
					{
						using(ZipInputStream zis = new ZipInputStream(fs))
						{
							while(zis.GetNextEntry() != null)
							{
								totalCount++;
							}
						}
					}

					//begin to unzip
					arg.m_totalCount = totalCount;
					arg.m_decompressCount = 0;
					using(FileStream fs = new FileStream(arg.m_zipPath, FileMode.Open, FileAccess.Read))
					{
						using(ZipInputStream zis = new ZipInputStream(fs))
						{
							ZipEntry ze;
							while((ze = zis.GetNextEntry()) != null)
							{
								try
								{
									if (!ze.IsDirectory)	// create file and write content
									{
										string fileName = Path.GetFileName(ze.Name);
										string destDir = Path.Combine(arg.m_extralPath, Path.GetDirectoryName(ze.Name));
										Directory.CreateDirectory(destDir);
										string destPath = Path.Combine(destDir, fileName);
										
										using(FileStream writer = new FileStream(destPath, FileMode.Create, FileAccess.Write))
										{
											int len;
											while ((len = zis.Read(buffer, 0, buffer.Length)) > 0)
											{
												writer.Write(buffer, 0, len);
											}
											writer.Close();
										}
									}
									else	// create folder
									{
										string dirPath = Path.Combine(arg.m_extralPath, Path.GetDirectoryName(ze.Name));
										Directory.CreateDirectory(dirPath);
									}
								}
								catch (Exception e)
								{
									exception = e;
									break;
								}

								//recode decompless count
								arg.m_decompressCount++;
							}
						}
					}
				
					//complete unzip delete the zip file
					// File.Delete(arg.m_zipPath);

					lock (((ICollection)s_execProxy).SyncRoot)
					{
						if(exception != null)
						{
							arg.m_isError = true;
							arg.m_exception = exception;
						}
						arg.m_isDone = true;
					}
				}
			), proxy);
			
			lock (((ICollection)s_execProxy).SyncRoot)
			{
				s_execProxy.Add(proxy);
			}
			return proxy;
		}
Пример #3
0
        public static ZipProxy uncompless(string zipFile, string extralPath, System.Action <object> endCallback, System.Action <Exception> errorCallback)
        {
            ZipProxy proxy = new ZipProxy();

            proxy.m_zipPath         = zipFile;
            proxy.m_extralPath      = extralPath;
            proxy.m_isDone          = false;
            proxy.m_isError         = false;
            proxy.m_endCallback     = endCallback;
            proxy.m_errorCallback   = errorCallback;
            proxy.m_exception       = null;
            proxy.m_totalCount      = 0;
            proxy.m_decomplessCount = 0;
            ThreadPool.QueueUserWorkItem(new WaitCallback(
                                             delegate(object t) {
                Exception exception = null;
                ZipProxy arg        = (ZipProxy)t;
                // Zip

                byte[] buffer  = new byte[1048576];
                int totalCount = 0;
                using (FileStream fs = new FileStream(arg.m_zipPath, FileMode.Open, FileAccess.Read)) {
                    using (ZipInputStream zis = new ZipInputStream(fs)) {
                        while (zis.GetNextEntry() != null)
                        {
                            totalCount++;
                        }
                    }
                }

                arg.m_totalCount      = totalCount;
                arg.m_decomplessCount = 0;
                using (FileStream fs = new FileStream(arg.m_zipPath, FileMode.Open, FileAccess.Read)) {
                    using (ZipInputStream zis = new ZipInputStream(fs)) {
                        ZipEntry ze;
                        while ((ze = zis.GetNextEntry()) != null)
                        {
                            try {
                                if (!ze.IsDirectory)
                                {
                                    //展開先のファイル名を決定
                                    string fileName = Path.GetFileName(ze.Name);
                                    //展開先のフォルダを決定
                                    string destDir = Path.Combine(arg.m_extralPath, Path.GetDirectoryName(ze.Name));
                                    Directory.CreateDirectory(destDir);
                                    //展開先のファイルのフルパスを決定
                                    string destPath = Path.Combine(destDir, fileName);

                                    //書き込み先のファイルを開く
                                    using (FileStream writer = new FileStream(destPath, FileMode.Create, FileAccess.Write)) {
                                        //展開するファイルを読み込む
                                        int len;
                                        while ((len = zis.Read(buffer, 0, buffer.Length)) > 0)
                                        {
                                            //ファイルに書き込む
                                            writer.Write(buffer, 0, len);
                                        }
                                        //閉じる
                                        writer.Close();
                                    }
                                }
                                else
                                {
                                    //フォルダのとき
                                    //作成するフォルダのフルパスを決定
                                    string dirPath = Path.Combine(arg.m_extralPath, Path.GetDirectoryName(ze.Name));
                                    //フォルダを作成
                                    Directory.CreateDirectory(dirPath);
                                }
                            }
                            catch (Exception e) {
                                exception = e;
                                break;
                            }

                            arg.m_decomplessCount++;
                        }
                    }
                }

                File.Delete(arg.m_zipPath);
                lock (((ICollection)s_execProxy).SyncRoot) {
                    if (exception != null)
                    {
                        arg.m_isError   = true;
                        arg.m_exception = exception;
                    }
                    arg.m_isDone = true;
                }
            }), proxy);

            lock (((ICollection)s_execProxy).SyncRoot) {
                s_execProxy.Add(proxy);
            }
            return(proxy);
        }
Пример #4
0
        public static ZipProxy uncompless(string zipFile, string extralPath, System.Action<object> endCallback, System.Action<Exception> errorCallback)
        {
            ZipProxy proxy = new ZipProxy();
            proxy.m_zipPath = zipFile;
            proxy.m_extralPath = extralPath;
            proxy.m_isDone = false;
            proxy.m_isError = false;
            proxy.m_endCallback = endCallback;
            proxy.m_errorCallback = errorCallback;
            proxy.m_exception = null;
            proxy.m_totalCount = 0;
            proxy.m_decomplessCount = 0;
            ThreadPool.QueueUserWorkItem(new WaitCallback(
                delegate(object t) {
                    Exception exception = null;
                    ZipProxy arg = (ZipProxy)t;
                    // Zip

                    byte[] buffer = new byte[1048576];
                    int totalCount = 0;
                    using(FileStream fs = new FileStream(arg.m_zipPath, FileMode.Open, FileAccess.Read)) {
                        using(ZipInputStream zis = new ZipInputStream(fs)) {
                            while(zis.GetNextEntry() != null) {
                                totalCount++;
                            }
                        }
                    }

                    arg.m_totalCount = totalCount;
                    arg.m_decomplessCount = 0;
                    using(FileStream fs = new FileStream(arg.m_zipPath, FileMode.Open, FileAccess.Read)) {
                        using(ZipInputStream zis = new ZipInputStream(fs)) {
                            ZipEntry ze;
                            while((ze = zis.GetNextEntry()) != null) {
                                try {
                                    if (!ze.IsDirectory) {
                                        //展開先のファイル名を決定
                                        string fileName = Path.GetFileName(ze.Name);
                                        //展開先のフォルダを決定
                                        string destDir = Path.Combine(arg.m_extralPath, Path.GetDirectoryName(ze.Name));
                                        Directory.CreateDirectory(destDir);
                                        //展開先のファイルのフルパスを決定
                                        string destPath = Path.Combine(destDir, fileName);

                                        //書き込み先のファイルを開く
                                        using(FileStream writer = new FileStream(destPath, FileMode.Create, FileAccess.Write)) {
                                            //展開するファイルを読み込む
                                            int len;
                                            while ((len = zis.Read(buffer, 0, buffer.Length)) > 0)
                                            {
                                                //ファイルに書き込む
                                                writer.Write(buffer, 0, len);
                                            }
                                            //閉じる
                                            writer.Close();
                                        }
                                    }
                                    else {
                                        //フォルダのとき
                                        //作成するフォルダのフルパスを決定
                                        string dirPath = Path.Combine(arg.m_extralPath, Path.GetDirectoryName(ze.Name));
                                        //フォルダを作成
                                        Directory.CreateDirectory(dirPath);
                                    }
                                }
                                catch (Exception e) {
                                    exception = e;
                                    break;
                                }

                                arg.m_decomplessCount++;
                            }
                        }
                    }

                    File.Delete(arg.m_zipPath);
                    lock (((ICollection)s_execProxy).SyncRoot) {
                        if(exception != null) {
                            arg.m_isError = true;
                            arg.m_exception = exception;
                        }
                        arg.m_isDone = true;
                    }
                }), proxy);

            lock (((ICollection)s_execProxy).SyncRoot) {
                s_execProxy.Add(proxy);
            }
            return proxy;
        }
Пример #5
0
 public ZipProxy uncompless(string zipFile, string extralPath,
                            System.Action <object> endCallback, System.Action <Exception> errorCallback = null)
 {
     this.m_ZipProxy = ZipProxy.uncompless(zipFile, extralPath, endCallback, errorCallback);
     return(this.m_ZipProxy);
 }
Пример #6
0
        public static ZipProxy uncompless(string zipFile, string extralPath,
                                          System.Action <object> endCallback, System.Action <Exception> errorCallback)
        {
            ZipProxy proxy = new ZipProxy();

            proxy.m_zipPath         = zipFile;
            proxy.m_extralPath      = extralPath;
            proxy.m_isDone          = false;
            proxy.m_isError         = false;
            proxy.m_endCallback     = endCallback;
            proxy.m_errorCallback   = errorCallback;
            proxy.m_exception       = null;
            proxy.m_totalCount      = 0;
            proxy.m_decompressCount = 0;
            ThreadPool.QueueUserWorkItem(new WaitCallback(
                                             delegate(object t)
            {
                Exception exception = null;
                ZipProxy arg        = (ZipProxy)t;
                byte[] buffer       = new byte[1048576];

                //the count of files in zip
                int totalCount = 0;
                using (FileStream fs = new FileStream(arg.m_zipPath, FileMode.Open, FileAccess.Read))
                {
                    using (ZipInputStream zis = new ZipInputStream(fs))
                    {
                        while (zis.GetNextEntry() != null)
                        {
                            totalCount++;
                        }
                    }
                }

                //begin to unzip
                arg.m_totalCount      = totalCount;
                arg.m_decompressCount = 0;
                using (FileStream fs = new FileStream(arg.m_zipPath, FileMode.Open, FileAccess.Read))
                {
                    using (ZipInputStream zis = new ZipInputStream(fs))
                    {
                        ZipEntry ze;
                        while ((ze = zis.GetNextEntry()) != null)
                        {
                            try
                            {
                                if (!ze.IsDirectory)                                            // create file and write content
                                {
                                    string fileName = Path.GetFileName(ze.Name);
                                    string destDir  = Path.Combine(arg.m_extralPath, Path.GetDirectoryName(ze.Name));
                                    Directory.CreateDirectory(destDir);
                                    string destPath = Path.Combine(destDir, fileName);

                                    using (FileStream writer = new FileStream(destPath, FileMode.Create, FileAccess.Write))
                                    {
                                        int len;
                                        while ((len = zis.Read(buffer, 0, buffer.Length)) > 0)
                                        {
                                            writer.Write(buffer, 0, len);
                                        }
                                        writer.Close();
                                    }
                                }
                                else                                            // create folder
                                {
                                    string dirPath = Path.Combine(arg.m_extralPath, Path.GetDirectoryName(ze.Name));
                                    Directory.CreateDirectory(dirPath);
                                }
                            }
                            catch (Exception e)
                            {
                                exception = e;
                                break;
                            }

                            //recode decompless count
                            arg.m_decompressCount++;
                        }
                    }
                }

                //complete unzip delete the zip file
                // File.Delete(arg.m_zipPath);

                lock (((ICollection)s_execProxy).SyncRoot)
                {
                    if (exception != null)
                    {
                        arg.m_isError   = true;
                        arg.m_exception = exception;
                    }
                    arg.m_isDone = true;
                }
            }
                                             ), proxy);

            lock (((ICollection)s_execProxy).SyncRoot)
            {
                s_execProxy.Add(proxy);
            }
            return(proxy);
        }