private void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e) { Cursor = Cursors.Default; if (e.Error != null && _xmlName == "Nikse.SubtitleEdit.Resources.HunspellDictionaries.xml.gz") { MessageBox.Show("Unable to download " + _downloadLink + Environment.NewLine + "Switching host - please re-try!"); LoadDictionaryList("Nikse.SubtitleEdit.Resources.HunspellBackupDictionaries.xml.gz"); labelPleaseWait.Text = string.Empty; buttonOK.Enabled = true; buttonDownload.Enabled = true; buttonDownloadAll.Enabled = true; comboBoxDictionaries.Enabled = true; Cursor = Cursors.Default; return; } if (e.Error != null) { MessageBox.Show(LanguageSettings.Current.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; using (var ms = new MemoryStream(e.Result)) using (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.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)) { using (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); } } } } } Cursor = Cursors.Default; labelPleaseWait.Text = string.Empty; buttonOK.Enabled = true; buttonDownload.Enabled = true; buttonDownloadAll.Enabled = true; comboBoxDictionaries.Enabled = true; if (_testAllIndex >= 0) { DownloadNext(); return; } MessageBox.Show(string.Format(LanguageSettings.Current.GetDictionaries.XDownloaded, comboBoxDictionaries.Items[index])); }
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])); }
private void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e) { labelPleaseWait.Text = string.Empty; if (e.Error != null) { MessageBox.Show(Configuration.Settings.Language.GetTesseractDictionaries.DownloadFailed); ChangeControlsState(true); Cursor = Cursors.Default; 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}"); ChangeControlsState(true); Cursor = Cursors.Default; return; } } var ms = new MemoryStream(e.Result); using (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($"{fullPath} already exists - unable to overwrite it"); Cursor = Cursors.Default; ChangeControlsState(true); return; } } zip.ExtractFile(entry, fullPath); } } Cursor = Cursors.Default; ChangeControlsState(true); if (_updatingAllPlugins) { _updatingAllPluginsCount++; if (_updatingAllPluginsCount == _updateAllListUrls.Count) { MessageBox.Show(string.Format(_language.XPluginsUpdated, _updatingAllPluginsCount)); } } else { MessageBox.Show(string.Format(_language.PluginXDownloaded, _downloadedPluginName)); } ShowInstalledPlugins(); }
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(); }