Ejemplo n.º 1
0
        private void ExtractEtl(string tempVspxPath, string tempEtlPath)
        {
            OnStatusUpdated(ProfilerState.Stopping, "Extracting ETL file from profiler output...");

            ZipStorer vspx = ZipStorer.Open(tempVspxPath, FileAccess.Read);

            List <ZipStorer.ZipFileEntry> entries = vspx.ReadCentralDir();

            // Look for the etl
            foreach (ZipStorer.ZipFileEntry entry in entries)
            {
                if (entry.FilenameInZip.EndsWith(".etl"))
                {
                    vspx.ExtractFile(entry, tempEtlPath);

                    vspx.Close();

                    return;
                }
            }

            vspx.Close();

            throw new FileNotFoundException("Couldn't find an etl file in the vspx that we retrieved from the device");
        }
Ejemplo n.º 2
0
    /// <summary>
    /// Method to open an existing storage from stream
    /// </summary>
    /// <param name="_stream">Already opened stream with zip contents</param>
    /// <param name="_access">File access mode for stream operations</param>
    /// <param name="_leaveOpen">true to leave the stream open after the ZipStorer object is disposed; otherwise, false (default).</param>
    /// <returns>A valid ZipStorer object</returns>
    public static ZipStorer Open(Stream _stream, FileAccess _access, bool _leaveOpen = false)
    {
        if (!_stream.CanSeek && _access != FileAccess.Read)
        {
            throw new InvalidOperationException("Stream cannot seek");
        }

        ZipStorer zip = new ZipStorer();

        //zip.FileName = _filename;
        zip.ZipFileStream = _stream;
        zip.Access        = _access;
        zip.leaveOpen     = _leaveOpen;

        if (zip.ReadFileInfo())
        {
            return(zip);
        }

        /* prevent files/streams to be opened unused*/
        if (!_leaveOpen)
        {
            zip.Close();
        }

        throw new System.IO.InvalidDataException();
    }
Ejemplo n.º 3
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            System.Threading.Thread.Sleep(5000);
            try
            {
                WebClient wc = new WebClient();
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
                wc.DownloadFile("https://sergi4ua.com/equine/EQUINEUpdate.zip", Application.StartupPath + "\\..\\equineupdate.zip");

                ZipStorer zip = ZipStorer.Open(Application.StartupPath + "\\..\\equineupdate.zip", FileAccess.Read);
                List <ZipStorer.ZipFileEntry> dir = zip.ReadCentralDir();

                foreach (ZipStorer.ZipFileEntry entry in dir)
                {
                    zip.ExtractFile(entry, Application.StartupPath + "\\..\\" + entry.FilenameInZip);
                }
                zip.Close();
                File.Delete(Application.StartupPath + "\\..\\equineupdate.zip");
                System.Threading.Thread.Sleep(2000);
                MessageBox.Show("EQUINE has been successfully updated!\nEQUINE will now restart.", "EQUINE", MessageBoxButtons.OK, MessageBoxIcon.Information);
                var SelfProc = new ProcessStartInfo
                {
                    UseShellExecute  = true,
                    WorkingDirectory = Application.StartupPath + "\\..\\",
                    FileName         = Application.StartupPath + "\\..\\EQUINE.exe",
                };
                Process.Start(SelfProc);
                Application.Exit();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Update failed!\nWindows reported the error: " + ex.Message + "\nEQUINE will now quit. Please contact EQUINE developers to report this issue.", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                Application.Exit();
            }
        }
Ejemplo n.º 4
0
 public Stream getIcon()
 {
     if (apk != null)
     {
         Stream memoryStream = new MemoryStream();
         using (ZipStorer zipStorer = ZipStorer.Open(pathApk, FileAccess.Read))
         {
             foreach (ZipStorer.ZipFileEntry zipFileEntry in zipStorer.ReadCentralDir())
             {
                 if (!zipFileEntry.FilenameInZip.Equals(apk.AppIcon))
                 {
                     continue;
                 }
                 zipStorer.ExtractFile(zipFileEntry, memoryStream);
                 break;
             }
             zipStorer.Close();
         }
         return(memoryStream);
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 5
0
    public void Begin(int p, string url)
    {
        mVersion = p;
        int v = PlayerPrefs.GetInt("UnPackVersion", 0);

        if (mVersion > v)
        {
            TextAsset ta = (TextAsset)Resources.Load("Game");

            using (MemoryStream ms = new MemoryStream(ta.bytes))
            {
                ZipStorer zip = ZipStorer.Open(ms, FileAccess.Read);
                List <ZipStorer.ZipFileEntry> dir = zip.ReadCentralDir();
                foreach (ZipStorer.ZipFileEntry entry in dir)
                {
                    string outPath = Application.persistentDataPath + "/" + entry.FilenameInZip;
                    zip.ExtractFile(entry, outPath);
                }
                zip.Close();
            }
            PlayerPrefs.SetInt("UnPackVersion", mVersion);
            GameObject dGo = new GameObject("Downloader");
            mDownloader = dGo.AddComponent <PatcherDownloader>();
            mDownloader.BeginDownload(url, delegate(PatcherElem e)
            {
                mCurElems = e;
                GameObject.Destroy(dGo);
                mDownloader = null;
            });
        }
    }
Ejemplo n.º 6
0
        //To delete or move to old files
        void MoveFolderToOld(string oldPath, string newPath)
        {
            if (File.Exists(oldPath + ".old"))
            {
                File.Delete(oldPath + ".old");
            }

            if (File.Exists(oldPath))
            {
                File.Move(oldPath, oldPath + ".old");
            }

            File.Move(newPath, oldPath);
            Console.WriteLine("移动文件:" + newPath + "到" + oldPath);
            Config config = Config.LoadConfig(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ConstFile.FILENAME));

            if (config.Type.ToUpper() == "ZIP")
            {
                Console.WriteLine("读取压缩文件:" + oldPath);
                ZipStorer zip = ZipStorer.Open(oldPath, FileAccess.Read);
                List <ZipStorer.ZipFileEntry> dir = zip.ReadCentralDir();
                foreach (ZipStorer.ZipFileEntry entry in dir)
                {
                    Console.WriteLine("解压文件:" + entry.FilenameInZip);
                    zip.ExtractFile(entry, Path.Combine(AppDomain.CurrentDomain.BaseDirectory, entry.FilenameInZip));
                }
                zip.Close();
            }
        }
Ejemplo n.º 7
0
    static void BuildZip(BuildTarget target)
    {
        string outPath = Application.dataPath + "/Patcher/Resources/game.bytes";
        if (File.Exists(outPath))
            File.Delete(outPath);
        ZipStorer zip = ZipStorer.Create(outPath, target.ToString());
        string path = GetPath(target);
        string di = "Assets/Patcher/ABs/" + path;
        string[] fs = Directory.GetFiles(di);
        foreach(var f in fs)
        {
            
            if (f.EndsWith(".meta")
                || f.EndsWith(".manifest")
                )
                continue;
            string szName = Path.GetFileNameWithoutExtension(f);
            if (path == szName)
                continue;
            zip.AddFile(ZipStorer.Compression.Store, f, szName, szName);

        }
        zip.Close();
        AssetDatabase.Refresh();
    }
Ejemplo n.º 8
0
        public static string FileToString(string fileName)
        {
            ZipStorer zip = ZipStorer.Open(fileName, System.IO.FileAccess.Read);

            // Read the central directory collection
            List <ZipStorer.ZipFileEntry> dir = zip.ReadCentralDir();

            if (dir.Count == 0)
            {
                throw new Exception("no files in " + fileName);
            }

            byte[] block = new byte[0];
            using (var ms = new MemoryStream())
            {
                zip.ExtractFile(dir[0], ms);
                block = ms.ToArray();
            }

            string recs = System.Text.Encoding.Default.GetString(block, 0, block.Length);

            zip.Close();

            return(recs);
        }
Ejemplo n.º 9
0
        public void Save(string file_name)
        {
            ZipStorer result = ZipStorer.Create(file_name, "");                                                                 // Create the output filename
            Stream    data;                                                                                                     // This will be out stream
            gStream   sst = null;

            foreach (gStream g in streams)                                                                                      // Loop all the streams in the template
            {
                string name = g.zfe.FilenameInZip;                                                                              // This is the stream name
                if (name != "xl/sharedStrings.xml")                                                                             // If this is not the shared strings stream
                {
                    if (!sources.TryGetValue(name, out data))
                    {
                        data = g.ReadAsMemory();                                                                                // Get data stream either from memory or from Sources
                    }
                    result.AddStream(ZipStorer.Compression.Deflate, name, data, DateTime.Now, "");                              // Add to our ZIP file
                }
                else
                {
                    sst = g;
                }
            }
            if (!sources.TryGetValue("xl/sharedStrings.xml", out data))
            {
                data = sst.ReadAsMemory();                                                                                      // Get data stream either from memory or from Sources
            }
            result.AddStream(ZipStorer.Compression.Deflate, "xl/sharedStrings.xml", data, DateTime.Now, "");                    // Add to our ZIP file
            result.Close();                                                                                                     // Close the ZIP file
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Open an existing storage from stream
        /// </summary>
        /// <param name="_stream">Already opened stream with zip contents</param>
        /// <param name="_access">File access mode for stream operations</param>
        /// <param name="_leaveOpen">true to leave the stream open after the ZipStorer object is disposed; otherwise, false (default).</param>
        /// <returns>A valid ZipStorer object</returns>
        public static ZipStorer Open(Stream _stream, FileAccess _access, bool _leaveOpen = false)
        {
            if (!_stream.CanSeek && _access != FileAccess.Read)
            {
                throw new InvalidOperationException("Stream cannot seek");
            }

            ZipStorer zip = new ZipStorer
            {
                ZipFileStream = _stream,
                Access        = _access,
                leaveOpen     = _leaveOpen
            };

            if (zip.ReadFileInfo())
            {
                foreach (var file in zip.ReadCentralDir())
                {
                    zip.Files[file.FilenameInZip] = file;
                }
                return(zip);
            }

            if (!_leaveOpen)
            {
                zip.Close();
            }

            throw new InvalidDataException();
        }
Ejemplo n.º 11
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                WebClient wc = new WebClient();
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
                wc.DownloadFile("https://sergi4ua.com/equine/EquineData.zip", Application.StartupPath + "\\equinedata.zip");

                ZipStorer zip = ZipStorer.Open(Application.StartupPath + "\\equinedata.zip", FileAccess.Read);
                List <ZipStorer.ZipFileEntry> dir = zip.ReadCentralDir();

                foreach (ZipStorer.ZipFileEntry entry in dir)
                {
                    zip.ExtractFile(entry, Application.StartupPath + "\\EquineData\\" + entry.FilenameInZip);
                }
                zip.Close();
                File.Delete("equinedata.zip");
                System.Threading.Thread.Sleep(2000);
                MessageBox.Show("EquineData updated successfully!\nEQUINE should now restart.", "EQUINE", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Initalization failed!\n" + ex.Message + "\nEQUINE will now quit.", "Critical error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                Application.Exit();
            }
        }
Ejemplo n.º 12
0
 public void Close()                                                                                                     // Close the excel file
 {
     if (zip != null)
     {
         zip.Close(); zip = null;
     }
 }
        public void downloadBinary()
        {
            Directory.CreateDirectory(this.basePath);

            using (var client = new WebClient())
            {
                Console.WriteLine("Downloading BrowserStackLocal Zip..");
                client.DownloadFile(downloadURL, this.zipAbsolute);
                Console.WriteLine("Opening Zip..");
                ZipStorer zip = ZipStorer.Open(this.zipAbsolute, FileAccess.Read);
                List <ZipStorer.ZipFileEntry> dir = zip.ReadCentralDir();
                foreach (ZipStorer.ZipFileEntry entry in dir)
                {
                    if (Path.GetFileName(entry.FilenameInZip) == binaryName)
                    {
                        zip.ExtractFile(entry, this.binaryAbsolute);
                        break;
                    }
                }
                zip.Close();

                File.Delete(this.zipAbsolute);

                Console.WriteLine("Binary Extracted");
            }
        }
Ejemplo n.º 14
0
    public void BeginUnPack(int p, System.Action onFinish, bool debug)
    {
        mVersion  = p;
        mOnFinish = onFinish;
        int v = UnPackBundle;

        if (mVersion > v && !debug)
        {
            TextAsset ta = (TextAsset)Resources.Load("Game");

            using (MemoryStream ms = new MemoryStream(ta.bytes))
            {
                ZipStorer zip = ZipStorer.Open(ms, FileAccess.Read);
                List <ZipStorer.ZipFileEntry> dir = zip.ReadCentralDir();
                foreach (ZipStorer.ZipFileEntry entry in dir)
                {
                    string outPath = Application.persistentDataPath + "/" + entry.FilenameInZip;
                    zip.ExtractFile(entry, outPath);
                }
                zip.Close();
            }
            UnPackBundle = mVersion;
        }
        if (null != onFinish)
        {
            onFinish();
        }
    }
Ejemplo n.º 15
0
    public void Decompress(string fileName)
    {
        try
        {
            string directoryPath = Server.MapPath("../QuizTests/").ToString();

            if (File.Exists(directoryPath + fileName))
            {
                ZipStorer zst = ZipStorer.Open(directoryPath + fileName, FileAccess.Read);
                List <ZipStorer.ZipFileEntry> dir = zst.ReadCentralDir();
                foreach (ZipStorer.ZipFileEntry entry in dir)
                {
                    if (Path.GetFileName(entry.FilenameInZip) == "index.html")
                    {
                        zst.ExtractFile(entry, directoryPath + "HtmlQuiz1\\" + "index.html");
                    }
                    else
                    {
                        zst.ExtractFile(entry, directoryPath + "HtmlQuiz1\\" + entry.FilenameInZip);
                    }
                }
                zst.Close();
            }
        }
        catch (Exception ex)
        {
            Response.Redirect(ex.Message);
        }
    }
Ejemplo n.º 16
0
        private void WC_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            if (File.Exists("latest_cats.zip.progress"))
            {
                if (File.Exists("latest_cats.zip"))
                {
                    File.Delete("latest_cats.zip");
                }

                File.Move("latest_cats.zip.progress", "latest_cats.zip");

                ZipStorer zip = ZipStorer.Open("latest_cats.zip", FileAccess.Read);
                List <ZipStorer.ZipFileEntry> dir = zip.ReadCentralDir();

                // Look for the desired file
                foreach (ZipStorer.ZipFileEntry entry in dir)
                {
                    zip.ExtractFile(entry, entry.FilenameInZip);
                }

                zip.Close();
                File.Delete("latest_cats.zip");
            }

            System.Diagnostics.Process.Start("CATSBot.exe");
            Application.Exit();
        }
Ejemplo n.º 17
0
 /// <summary>
 /// zip解压
 /// </summary>
 /// <param name="zipPath">zip文件路径</param>
 /// <param name="outPath">解压路径</param>
 /// <returns>是否解压成功</returns>
 public static bool UnZip(string zipPath, string outPath)
 {
     //Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
     if (!outPath.EndsWith("\\") && !outPath.EndsWith("/"))
     {
         outPath += "\\";
     }
     if (!Directory.Exists(outPath))
     {
         Directory.CreateDirectory(outPath);
     }
     using (ZipStorer zip = ZipStorer.Open(zipPath, FileAccess.Read))
     {
         List <ZipStorer.ZipFileEntry> dir = zip.ReadCentralDir(); //获取zip文件内所有文件路径
         foreach (ZipStorer.ZipFileEntry entry in dir)
         {
             if (!zip.ExtractFile(entry, outPath + entry.FilenameInZip))
             {
                 return(false);                                                        //存在没有解压成功的
             }
         }
         zip.Close();
     }
     return(true);
 }
Ejemplo n.º 18
0
        public void Save()
        {
            // Unsubscribe all instances:
            _groups.ToList().ForEach(x => Unsubscribe(x.Name));

            // Try to close the thread.
            _pendingWriteActive = false;

            int timeout = 120000;

            while (_pendingWriteBusy && timeout > 0)
            {
                Thread.Sleep(25);
                timeout -= 25;
            }

            _archive = ZipStorer.Create(FileName, "SimTelemetry log");
            foreach (var file in Directory.GetFiles("./" + TemporaryDirectory + "/", "*", SearchOption.AllDirectories))
            {
                var tmpIndex = file.LastIndexOf(TemporaryDirectory + "/", 0, 1);
                if (tmpIndex == -1)
                {
                    tmpIndex = file.IndexOf("" + TemporaryDirectory + "/");
                }
                var filenameInZip = file.Substring(tmpIndex + TemporaryDirectory.Length + 1);

                _archive.AddFile(ZipStorer.Compression.Deflate, file, filenameInZip, "");
            }

            // Close zip file.
            _archive.Close();

            Directory.Delete("./" + TemporaryDirectory + "/", true);
        }
Ejemplo n.º 19
0
    public static void UpdateAndroidPlugin()
    {
        var pluginFolder = CombinePaths(Application.dataPath, "Plugins",
                                        "NativeFileSO", "Android");
        var aarPath = CombinePaths(pluginFolder, "NativeFileSO.aar");

        var manifestName = "AndroidManifest.xml";
        var manifestPath = CombinePaths(pluginFolder, manifestName);

        ZipStorer zip = ZipStorer.Open(aarPath, FileAccess.ReadWrite);

        var centralDir = zip.ReadCentralDir();
        var manifest   = centralDir.Find(x => Path.GetFileName(x.FilenameInZip)
                                         == manifestName);

        zip.ExtractFile(manifest, manifestPath);
        UpdateManifestAssociations(manifestPath);

        ZipStorer.RemoveEntries(ref zip, new List <ZipStorer.ZipFileEntry>()
        {
            manifest
        });
        zip.AddFile(ZipStorer.Compression.Deflate, manifestPath, manifest.FilenameInZip, "");

        zip.Close();

        File.Delete(manifestPath);

        Debug.Log("NativeFileSO: Finished updating the Android plugin");
    }
Ejemplo n.º 20
0
        private Stream GetFileStreamFromXap(string file)
        {
            MemoryStream rv = null;

            ZipStorer zip = ZipStorer.Open(FilePath, FileAccess.Read);

            List <ZipStorer.ZipFileEntry> entries = zip.ReadCentralDir();

            // Look for the desired file
            foreach (ZipStorer.ZipFileEntry entry in entries)
            {
                if (Path.GetFileName(entry.FilenameInZip) == file)
                {
                    rv = new MemoryStream(2048);

                    zip.ExtractFile(entry, rv);

                    rv.Seek(0, SeekOrigin.Begin);

                    break;
                }
            }

            zip.Close();

            return(rv);
        }
Ejemplo n.º 21
0
 void CleanUp()
 {
     label1.Text = "Cleaning up";
     updatePackage.Close();
     File.Delete(updateLocation);
     UpdateRegistry();
 }
Ejemplo n.º 22
0
        public void Update()
        {
            if (!Check())
            {
                return;
            }

            try
            {
                string zipFileName = Path.Combine(Application.StartupPath, "update.zip");
                // Opens existing zip file
                ZipStorer zip = ZipStorer.Open(zipFileName, FileAccess.Read);

                // Read all directory contents
                List <ZipStorer.ZipFileEntry> zipFiles = zip.ReadCentralDir();

                // Extract all files in target directory
                foreach (ZipStorer.ZipFileEntry entry in zipFiles)
                {
                    if (zip.ExtractFile(entry, Path.Combine(Application.StartupPath, Path.GetFileName(entry.FilenameInZip))))
                    {
                        MainLogger.Append("Extracted: " + entry.FilenameInZip, LogMessageType.Info);
                    }
                    else
                    {
                        MainLogger.Append("Extract failed: " + entry.FilenameInZip, LogMessageType.Info);
                    }
                }

                zip.Close();

                File.Delete(zipFileName);
            }
            catch (Exception) { }
        }
Ejemplo n.º 23
0
        private static void ExtractMediaFiles(string zipFullPath, string tempPath)
        {
            try
            {
                ZipStorer zip = ZipStorer.Open(zipFullPath, FileAccess.Read);
                List <ZipStorer.ZipFileEntry> dir = zip.ReadCentralDir();

                Regex regex = new Regex(SlideXmlSearchPattern);

                foreach (ZipStorer.ZipFileEntry entry in dir)
                {
                    string name = Path.GetFileName(entry.FilenameInZip);

                    if (name?.Contains(".wav") ?? false ||
                        regex.IsMatch(name))
                    {
                        zip.ExtractFile(entry, tempPath + name);
                    }
                }

                zip.Close();

                FileDir.DeleteFile(zipFullPath);
            }
            catch (Exception e)
            {
                ErrorDialogBox.ShowDialog(CommonText.ErrorExtract, "Archived files cannot be retrieved.", e);
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Loads an XMind workbook file from disk.
        /// </summary>
        private void Load()
        {
            if (_fileName == null)
            {
                throw new InvalidOperationException("No XMind file to load!");
            }

            if (File.Exists(_fileName) == false)
            {
                throw new InvalidOperationException("XMind file does not exist!");
            }

            FileInfo xMindFileInfo = new FileInfo(_fileName);

            if (xMindFileInfo.Extension.ToLower() != ".xmind")
            {
                throw new InvalidOperationException("XMind file extension expected!");
            }

            String tempPath = Path.GetTempPath() + Guid.NewGuid() + "\\";

            Directory.CreateDirectory(tempPath);

            string[] fileNameStrings = xMindFileInfo.Name.Split('.');
            fileNameStrings[fileNameStrings.Count() - 1] = "zip";

            StringBuilder zipFileNameBuilder = new StringBuilder(string.Empty, 64);

            foreach (string str in fileNameStrings)
            {
                zipFileNameBuilder.Append(str + ".");
            }
            string zipFileName = zipFileNameBuilder.ToString().TrimEnd('.');

            // Make a temporary copy of the XMind file with a .zip extention for J# zip libraries:
            File.Copy(_fileName, tempPath + zipFileName);
            File.SetAttributes(tempPath + zipFileName, FileAttributes.Normal);  // Make sure the .zip temporary file is not read only - we want to delete it later...

            using (ZipStorer zip = ZipStorer.Open(tempPath + zipFileName, FileAccess.Read))
            {
                // Read the central directory collection
                List <ZipStorer.ZipFileEntry> dir = zip.ReadCentralDir();

                foreach (ZipStorer.ZipFileEntry entry in dir)
                {
                    zip.ExtractFile(entry, tempPath +
                                    (entry.FilenameInZip == "manifest.xml" ? "META-INF\\" : "") +
                                    entry.FilenameInZip);
                }
                zip.Close();
            }

            _metaData     = XDocument.Parse(File.ReadAllText(tempPath + "meta.xml"));
            _manifestData = XDocument.Parse(File.ReadAllText(tempPath + "META-INF\\manifest.xml"));
            _contentData  = XDocument.Parse(File.ReadAllText(tempPath + "content.xml"));

            Directory.Delete(tempPath, true);
        }
Ejemplo n.º 25
0
        private void StoreMessage(IMessage m)
        {
            if (_boxType != MailboxType.Physical)
            {
                return;
            }

            MailMessage mmsg = new MailMessage();

            mmsg.Body         = m.HTMLData ?? m.TextData;
            mmsg.BodyEncoding = String.IsNullOrEmpty(m.ContentTransferEncoding) ? System.Text.Encoding.Unicode : System.Text.Encoding.GetEncoding(m.ContentTransferEncoding);
            mmsg.From         = new MailAddress(m.FromContacts[0].EMail, m.FromContacts[0].FullName);
            mmsg.IsBodyHtml   = m.HTMLData != null;
            mmsg.ReplyToList.Add(String.IsNullOrEmpty(m.InReplyTo) ? new MailAddress(m.FromContacts[0].EMail) : new MailAddress(m.InReplyTo));
            mmsg.Subject = m.Subject;
            foreach (IContact c in m.ToContacts)
            {
                mmsg.To.Add(new MailAddress(c.EMail, c.FullName));
            }


            foreach (IMessageContent content in m.MessageContent)
            {
                if (!content.IsAttachment)
                {
                    continue;
                }
                ContentType ctype  = new ContentType(content.ContentType);
                Attachment  attach = new Attachment(new MemoryStream(content.BinaryData), ctype);
                mmsg.Attachments.Add(attach);
            }

            SmtpClient client = new SmtpClient();

            client.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
            string saveDir = @"i:\";

            client.PickupDirectoryLocation = saveDir;
            client.Send(mmsg);
            DirectoryInfo dinfo = new DirectoryInfo(saveDir);

            FileInfo[] files = dinfo.GetFiles("*.eml");
            if (files.Length == 0)
            {
                throw new FileNotFoundException("No .eml files were found in specified location");
            }
            string    pathToEml   = files[0].FullName;
            string    messagePath = String.Format(@"{0}\{1}\{2}", m.Folder.FullPath, m.UID, Path.GetFileName(pathToEml));
            ZipStorer zip         = ZipStorer.Open(_mailboxFile, FileAccess.ReadWrite);

            zip.AddFile(pathToEml, messagePath, messagePath);
            zip.Close();

            // TODO: add folder and filename info to some kind of xml file stored inside the zip
        }
Ejemplo n.º 26
0
        public static void StoreSqlText(string text)
        {
            byte[]       ba  = Encoding.UTF8.GetBytes(text);
            MemoryStream ms1 = new MemoryStream(ba);
            MemoryStream ms2 = new MemoryStream();
            ZipStorer    zip = ZipStorer.Create(ms2, "MySQL Backup");

            zip.AddStream(ZipStorer.Compression.Deflate, "Backup.sql", ms1, DateTime.Now, "MySQL Backup");
            zip.Close();
            StoreZipFile(ms2.ToArray());
        }
Ejemplo n.º 27
0
        public void Clear()
        {
            // We don't want this log file.
            if (_archive != null)
            {
                _archive.Close();
            }

            File.Delete(FileName);
            Directory.Delete("./" + TemporaryDirectory + "/", true);
        }
Ejemplo n.º 28
0
        /// <summary>
        /// 压缩多个文件
        /// </summary>
        /// <param name="zipPath">压缩文件路径</param>
        /// <param name="filePaths">待压缩的文件路径</param>
        public static void ZipFiles(string zipPath, params string[] filePaths)
        {
            ZipStorer zip = ZipStorer.Create(zipPath, string.Empty);

            zip.EncodeUTF8 = true;
            foreach (var path in filePaths)
            {
                zip.AddFile(ZipStorer.Compression.Deflate, path, Path.GetFileName(path), string.Empty);
            }
            zip.Close();
        }
Ejemplo n.º 29
0
    /// <summary>
    /// Removes one of many files in storage. It creates a new Zip file.
    /// </summary>
    /// <param name="_zip">Reference to the current Zip object</param>
    /// <param name="_zfes">List of Entries to remove from storage</param>
    /// <returns>True if success, false if not</returns>
    /// <remarks>This method only works for storage of type FileStream</remarks>
    public static bool RemoveEntries(ref ZipStorer _zip, List <ZipFileEntry> _zfes)
    {
        if (!(_zip.ZipFileStream is FileStream))
        {
            throw new InvalidOperationException("RemoveEntries is allowed just over streams of type FileStream");
        }


        //Get full list of entries
        var fullList = _zip.ReadCentralDir();

        //In order to delete we need to create a copy of the zip file excluding the selected items
        var tempZipName   = Path.GetTempFileName();
        var tempEntryName = Path.GetTempFileName();

        try
        {
            var tempZip = ZipStorer.Create(tempZipName, string.Empty);

            foreach (ZipFileEntry zfe in fullList)
            {
                if (!_zfes.Contains(zfe))
                {
                    if (_zip.ExtractFile(zfe, tempEntryName))
                    {
                        tempZip.AddFile(zfe.Method, tempEntryName, zfe.FilenameInZip, zfe.Comment);
                    }
                }
            }
            _zip.Close();
            tempZip.Close();

            File.Delete(_zip.FileName);
            File.Move(tempZipName, _zip.FileName);

            _zip = ZipStorer.Open(_zip.FileName, _zip.Access);
        }
        catch
        {
            return(false);
        }
        finally
        {
            if (File.Exists(tempZipName))
            {
                File.Delete(tempZipName);
            }
            if (File.Exists(tempEntryName))
            {
                File.Delete(tempEntryName);
            }
        }
        return(true);
    }
        private void ExtractFilesAndCopy()
        {
            logTextBox.AppendText("Extracting Files\n");
            ZipStorer zip = ZipStorer.Open(@"" + pathText.Text + "\\Bazar\\Liveries\\Temp.zip", FileAccess.Read);
            List <ZipStorer.ZipFileEntry> dir = zip.ReadCentralDir();
            // Look for the desired file
            int fileNumber = 0;

            progressBar1.Value = 0;
            foreach (ZipStorer.ZipFileEntry entry in dir)
            {
                //Deleting the first folder for extraction
                string fileName = entry.FilenameInZip.Substring(10, entry.FilenameInZip.Length - 10);
                logTextBox.AppendText("Extracting: " + fileName + "\n");
                zip.ExtractFile(entry, pathText.Text + "\\Bazar\\Liveries\\" + fileName);
                progressBar1.Value = ((fileNumber++ / dir.Count()) * 100);
            }
            zip.Close();
            logTextBox.AppendText("All Files Extracted\n");
            logTextBox.AppendText("Deleting Temporal Files...\n");
            File.Delete("" + pathText.Text + "\\Bazar\\Liveries\\Temp.zip");

            foreach (OptionalDownload optionalPackage in optionaldownloads)
            {
                //Extrat A-10C Files
                string path = "C:\\Users\\" + Environment.UserName + "\\Saved Games\\DCS\\Kneeboard\\" + optionalPackage.folderName;
                if (!Directory.Exists(path))
                {
                    // Try to create the directory.
                    DirectoryInfo di = Directory.CreateDirectory(path);
                }
                ZipStorer zipA10 = ZipStorer.Open("C:\\Users\\" + Environment.UserName + "\\Saved Games\\DCS\\Kneeboard\\" + optionalPackage.folderName + "\\Temp.zip", FileAccess.Read);
                List <ZipStorer.ZipFileEntry> dirA10 = zipA10.ReadCentralDir();
                // Look for the desired file
                int fileNumberA10 = 0;
                progressBar1.Value = 0;
                foreach (ZipStorer.ZipFileEntry entry in dirA10)
                {
                    //Deleting the first folder for extraction
                    string fileName = entry.FilenameInZip;
                    logTextBox.AppendText("Extracting: " + fileName + "\n");
                    zipA10.ExtractFile(entry, "C:\\Users\\" + Environment.UserName + "\\Saved Games\\DCS\\Kneeboard\\" + optionalPackage.folderName + "\\" + fileName);
                    progressBar1.Value = ((fileNumberA10++ / dirA10.Count()) * 100);
                }
                zipA10.Close();
                logTextBox.AppendText(optionalPackage.packageName + " Optional Files Extracted\n");
                logTextBox.AppendText("Deleting " + optionalPackage.packageName + " Optional Temporal Files...\n");
                File.Delete("C:\\Users\\" + Environment.UserName + "\\Saved Games\\DCS\\Kneeboard\\" + optionalPackage.folderName + "\\Temp.zip");
            }
            logTextBox.AppendText("Update/Install Proccess COMPLETED\n");
            pathText.ReadOnly = false;
            System.Media.SystemSounds.Hand.Play();
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Removes one of many files in storage. It creates a new Zip file.
        /// </summary>
        /// <param name="_zip">
        /// Reference to the current Zip object
        /// </param>
        /// <param name="_zfes">
        /// List of Entries to remove from storage
        /// </param>
        /// <returns>
        /// True if success, false if not
        /// </returns>
        /// <remarks>
        /// This method only works for storage of type FileStream
        /// </remarks>
        public static bool RemoveEntries(ref ZipStorer _zip, List<ZipFileEntry> _zfes)
        {
            if (!(_zip.ZipFileStream is FileStream))
            {
                throw new InvalidOperationException("RemoveEntries is allowed just over streams of type FileStream");
            }

            // Get full list of entries
            List<ZipFileEntry> fullList = _zip.ReadCentralDir();

            // In order to delete we need to create a copy of the zip file excluding the selected items
            string tempZipName = Path.GetTempFileName();
            string tempEntryName = Path.GetTempFileName();

            try
            {
                ZipStorer tempZip = Create(tempZipName, string.Empty);

                foreach (ZipFileEntry zfe in fullList)
                {
                    if (!_zfes.Contains(zfe))
                    {
                        if (_zip.ExtractFile(zfe, tempEntryName))
                        {
                            tempZip.AddFile(zfe.Method, tempEntryName, zfe.FilenameInZip, zfe.Comment);
                        }
                    }
                }

                _zip.Close();
                tempZip.Close();

                File.Delete(_zip.FileName);
                File.Move(tempZipName, _zip.FileName);

                _zip = Open(_zip.FileName, _zip.Access);
            }
            catch
            {
                return false;
            }
            finally
            {
                if (File.Exists(tempZipName))
                {
                    File.Delete(tempZipName);
                }

                if (File.Exists(tempEntryName))
                {
                    File.Delete(tempEntryName);
                }
            }

            return true;
        }