private void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e) { if (e.Error != null && _xmlName == "Nikse.SubtitleEdit.Resources.OpenOfficeDictionaries.xml.zip") { MessageBox.Show("Unable to connect to extensions.services.openoffice.org... Switching host - please re-try!"); LoadDictionaryList("Nikse.SubtitleEdit.Resources.HunspellDictionaries.xml.gz"); labelPleaseWait.Text = string.Empty; buttonOK.Enabled = true; buttonDownload.Enabled = true; comboBoxDictionaries.Enabled = true; Cursor = Cursors.Default; return; } else if (e.Error != null) { MessageBox.Show(Configuration.Settings.Language.GetTesseractDictionaries.DownloadFailed + Environment.NewLine + Environment.NewLine + e.Error.Message); DialogResult = DialogResult.Cancel; return; } string dictionaryFolder = Utilities.DictionaryFolder; if (!Directory.Exists(dictionaryFolder)) { Directory.CreateDirectory(dictionaryFolder); } int index = comboBoxDictionaries.SelectedIndex; var ms = new MemoryStream(e.Result); ZipExtractor zip = ZipExtractor.Open(ms); List <ZipExtractor.ZipFileEntry> dir = zip.ReadCentralDir(); // Extract dic/aff files in dictionary folder bool found = false; ExtractDic(dictionaryFolder, zip, dir, ref found); if (!found) // check zip inside zip { foreach (ZipExtractor.ZipFileEntry entry in dir) { if (entry.FilenameInZip.ToLower().EndsWith(".zip", StringComparison.Ordinal)) { var innerMs = new MemoryStream(); zip.ExtractFile(entry, innerMs); ZipExtractor innerZip = ZipExtractor.Open(innerMs); List <ZipExtractor.ZipFileEntry> innerDir = innerZip.ReadCentralDir(); ExtractDic(dictionaryFolder, innerZip, innerDir, ref found); innerZip.Close(); } } } zip.Close(); Cursor = Cursors.Default; labelPleaseWait.Text = string.Empty; buttonOK.Enabled = true; buttonDownload.Enabled = true; comboBoxDictionaries.Enabled = true; MessageBox.Show(string.Format(Configuration.Settings.Language.GetDictionaries.XDownloaded, comboBoxDictionaries.Items[index])); }
void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e) { labelPleaseWait.Text = string.Empty; if (e.Error != null) { MessageBox.Show("Download failed!"); DialogResult = DialogResult.Cancel; return; } string pluginsFolder = Configuration.PluginsDirectory; if (!Directory.Exists(pluginsFolder)) { try { Directory.CreateDirectory(pluginsFolder); } catch (Exception exception) { MessageBox.Show("Unable to create plugin folder " + pluginsFolder + ": " + exception.Message); return; } } var ms = new MemoryStream(e.Result); ZipExtractor zip = ZipExtractor.Open(ms); List <ZipExtractor.ZipFileEntry> dir = zip.ReadCentralDir(); // Extract dic/aff files in dictionary folder foreach (ZipExtractor.ZipFileEntry entry in dir) { string fileName = Path.GetFileName(entry.FilenameInZip); string fullPath = Path.Combine(pluginsFolder, fileName); if (File.Exists(fullPath)) { try { File.Delete(fullPath); } catch { MessageBox.Show(string.Format("{0} already exists - unable to overwrite it", fullPath)); Cursor = Cursors.Default; labelPleaseWait.Text = string.Empty; buttonOK.Enabled = true; buttonDownload.Enabled = true; listViewGetPlugins.Enabled = true; return; } } zip.ExtractFile(entry, fullPath); } zip.Close(); ms.Close(); Cursor = Cursors.Default; labelPleaseWait.Text = string.Empty; buttonOK.Enabled = true; buttonDownload.Enabled = true; listViewGetPlugins.Enabled = true; MessageBox.Show(string.Format(_language.PluginXDownloaded, _downloadedPluginName)); ShowInstalledPlugins(); }