예제 #1
0
        private void wc_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            labelPleaseWait.Text = string.Empty;
            if (e.Error != null)
            {
                MessageBox.Show(Configuration.Settings.Language.GetTesseractDictionaries.DownloadFailed);
                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();
            zip.Dispose();
            // ms.Close();
            Cursor = Cursors.Default;
            labelPleaseWait.Text       = string.Empty;
            buttonOK.Enabled           = true;
            buttonDownload.Enabled     = true;
            listViewGetPlugins.Enabled = true;
            if (_updatingAllPlugins)
            {
                _updatingAllPluginsCount++;
                if (_updatingAllPluginsCount == _updateAllListUrls.Count)
                {
                    MessageBox.Show(string.Format(_language.XPluginsUpdated, _updatingAllPluginsCount));
                }
            }
            else
            {
                MessageBox.Show(string.Format(_language.PluginXDownloaded, _downloadedPluginName));
            }
            ShowInstalledPlugins();
        }