/// <summary>
        /// Unzips the snippets using the zip library, in a new thread.
        /// </summary>
        /// <returns></returns>
        private bool UnzipSnippetsMySelf()
        {
            string zipfile = System.IO.Path.Combine(Helper.GetAppDir(), Consts.cSnippetThumbsZipfile);
            string tgt = Helper.GetAppdataPath() + Path.DirectorySeparatorChar;

            if (!File.Exists(zipfile))
                return false;

            GlobalUI.UI.AddStatusLine(this, "Unzipping snippet thumbnails from file " + zipfile + "....");

            ZipWorker = new TESharedComponents.MyBackgroundWorker();
            ZipWorker.DoWork += (se,e)=>
                {
                    string _zipfile = (e.Argument as Pair<string, string>).First;
                    string _tgt = (e.Argument as Pair<string, string>).Second;
                    try
                    {
                        /* Ionic.Zip code... not working in linux (works fine in windows)
                         * //Console.WriteLine("Unzipping...");
                        using (var z = ZipFile.Read(_zipfile))
                        {
                            z.ExtractAll(_tgt, ExtractExistingFileAction.OverwriteSilently);
                        }
                        */
                        using (ZipInputStream s = new ZipInputStream(File.OpenRead(_zipfile)))
                        {

                            ZipEntry theEntry;
                            while ((theEntry = s.GetNextEntry()) != null)
                            {

                                Console.WriteLine(theEntry.Name);

                                string directoryName = Path.GetDirectoryName(theEntry.Name);
                                string directoryFullPath = Path.Combine(_tgt, directoryName); 
                                string fileName = Path.GetFileName(theEntry.Name);
                                string filePath = Path.Combine(_tgt, theEntry.Name);

                                // create directory
                                if (!Directory.Exists(directoryFullPath))
                                {
                                    Directory.CreateDirectory(directoryFullPath);
                                }

                                if (fileName != String.Empty)
                                {
                                    using (FileStream streamWriter = File.Create(filePath))
                                    {

                                        int size = 2048;
                                        byte[] data = new byte[2048];
                                        while (true)
                                        {
                                            size = s.Read(data, 0, data.Length);
                                            if (size > 0)
                                            {
                                                streamWriter.Write(data, 0, size);
                                            }
                                            else
                                            {
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        GlobalUI.UI.AddStatusLine(null, "Snippet Thimbnails unzipped successfully.");
                    }
                    catch (Exception ex)
                    {
                        //Console.WriteLine("Couldn't unzip: " + ex.Message);
                        GlobalUI.UI.AddStatusLine(null, "Couldn't unzip snippets thumbnails: " + ex.Message, true);
                    }
                };

            ZipWorker.RunWorkerAsync(new Pair<string,string>(zipfile, tgt));

            return true;
        }
Beispiel #2
0
        /// <summary>
        /// Unzips the snippets using the zip library, in a new thread.
        /// </summary>
        /// <returns></returns>
        private bool UnzipSnippetsMySelf()
        {
            string zipfile = System.IO.Path.Combine(Helper.GetAppDir(), Consts.cSnippetThumbsZipfile);
            string tgt     = Helper.GetAppdataPath() + Path.DirectorySeparatorChar;

            if (!File.Exists(zipfile))
            {
                return(false);
            }

            GlobalUI.UI.AddStatusLine(this, "Unzipping snippet thumbnails from file " + zipfile + "....");

            ZipWorker         = new TESharedComponents.MyBackgroundWorker();
            ZipWorker.DoWork += (se, e) =>
            {
                string _zipfile = (e.Argument as Pair <string, string>).First;
                string _tgt     = (e.Argument as Pair <string, string>).Second;
                try
                {
                    /* Ionic.Zip code... not working in linux (works fine in windows)
                     * //Console.WriteLine("Unzipping...");
                     * using (var z = ZipFile.Read(_zipfile))
                     * {
                     *  z.ExtractAll(_tgt, ExtractExistingFileAction.OverwriteSilently);
                     * }
                     */
                    using (ZipInputStream s = new ZipInputStream(File.OpenRead(_zipfile)))
                    {
                        ZipEntry theEntry;
                        while ((theEntry = s.GetNextEntry()) != null)
                        {
                            Console.WriteLine(theEntry.Name);

                            string directoryName     = Path.GetDirectoryName(theEntry.Name);
                            string directoryFullPath = Path.Combine(_tgt, directoryName);
                            string fileName          = Path.GetFileName(theEntry.Name);
                            string filePath          = Path.Combine(_tgt, theEntry.Name);

                            // create directory
                            if (!Directory.Exists(directoryFullPath))
                            {
                                Directory.CreateDirectory(directoryFullPath);
                            }

                            if (fileName != String.Empty)
                            {
                                using (FileStream streamWriter = File.Create(filePath))
                                {
                                    int    size = 2048;
                                    byte[] data = new byte[2048];
                                    while (true)
                                    {
                                        size = s.Read(data, 0, data.Length);
                                        if (size > 0)
                                        {
                                            streamWriter.Write(data, 0, size);
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    GlobalUI.UI.AddStatusLine(null, "Snippet Thimbnails unzipped successfully.");
                }
                catch (Exception ex)
                {
                    //Console.WriteLine("Couldn't unzip: " + ex.Message);
                    GlobalUI.UI.AddStatusLine(null, "Couldn't unzip snippets thumbnails: " + ex.Message, true);
                }
            };

            ZipWorker.RunWorkerAsync(new Pair <string, string>(zipfile, tgt));

            return(true);
        }