Esempio n. 1
0
        private void bwExtract_DoWork(object sender, DoWorkEventArgs e)
        {
            var archive = string.Empty;
            var file    = string.Empty;

            try
            {
                if (bwExtract.CancellationPending)
                {
                    e.Cancel = true;
                    bwExtract.ReportProgress(0);
                    return;
                }

                var lst = (List <FileDownload>)e.Argument;
                foreach (var item in lst)
                {
                    if (bwExtract.CancellationPending)
                    {
                        e.Cancel = true;
                        bwExtract.ReportProgress(0);
                        return;
                    }

                    archive = item.Tmp;
                    file    = item.Local;
                    bwExtract.ReportProgress(0, item.Name);

                    var dir = Path.GetDirectoryName(file);
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }

                    //todo roca sheicvleba saxeli da daerqmeba AppStart.exe mashin ra unda qnas???
                    if (_selfUpdate && file.EndsWith(_xmlUpdate.AppExeName, StringComparison.InvariantCultureIgnoreCase))
                    {
                        file = Ext.GetNewVersionExeFileName();
                    }

                    if (File.Exists(file))
                    {
                        File.Delete(file);
                    }
                    switch (_xmlUpdate.Compress.ToLowerInvariant())
                    {
                    case "":
                        File.Copy(archive, file);
                        break;

                    case "gzip":
                        GZipHelper.DecompressFile(archive, file);
                        break;

                    //case "zip":
                    //    SharpZLibHelper.DecompressFile(item.Tmp, item.Local);
                    //    break;

                    case "7zip":
                        SevenZipHelper.DecompressFileLZMA(archive, file);
                        //File.WriteAllBytes(item.Local, SevenZipHelper.Decompress(File.ReadAllBytes(item.Tmp)));
                        break;

                    default:
                        throw new ArgumentException("Invalid compress type (use: gzip, 7zip).");
                    }


                    //Don't delete file becouse we downloaded same hashed file one time.
                    //We'll delete all files after extract completes.
                    //try
                    //{
                    //    File.Delete(archive);
                    //}
                    //catch { }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message + "\n\nTmp Archive: " + archive + "\n\nFile: " + file, ex);
            }
        }