Exemplo n.º 1
0
 private void webBrowser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
 {
     try
     {
         string           path;
         BackgroundWorker worker;
         string           uri = e.Url.ToString();
         if (uri.ToLowerInvariant().EndsWith(".lpx"))
         {
             e.Cancel = true;
             DCDriverLoader.UnloadDomains(true);
             path   = Path.Combine(this._tempDir, "TempDriver" + _random.Next(0xf4240) + ".lpx");
             worker = new BackgroundWorker {
                 WorkerSupportsCancellation = true,
                 WorkerReportsProgress      = true
             };
             worker.DoWork += delegate(object sender, DoWorkEventArgs e) {
                 WebClient webClient = WebHelper.GetWebClient();
                 webClient.DownloadProgressChanged += delegate(object sender, DownloadProgressChangedEventArgs e) {
                     if (worker.IsBusy)
                     {
                         worker.ReportProgress(e.ProgressPercentage);
                     }
                 };
                 webClient.DownloadFileAsync(new Uri(uri), path);
                 while (webClient.IsBusy)
                 {
                     if (worker.CancellationPending)
                     {
                         webClient.CancelAsync();
                         break;
                     }
                     Thread.Sleep(100);
                 }
             };
             using (WorkerForm form = new WorkerForm(worker, "Downloading...", true))
             {
                 if (form.ShowDialog() != DialogResult.OK)
                 {
                     return;
                 }
             }
             if (!this.TryImportFile(path))
             {
                 e.Cancel = true;
             }
         }
     }
     catch (Exception exception)
     {
         e.Cancel = true;
         Program.ProcessException(exception);
     }
 }
Exemplo n.º 2
0
        private void DriverDeleted(object sender, EventArgs e)
        {
            DCDriverLoader.UnloadDomains(true);
            DCDriverLoader selectedDriverLoader = this.SelectedDriverLoader;

            if (selectedDriverLoader != null)
            {
                string directoryName = Path.GetDirectoryName(selectedDriverLoader.GetAssemblyPath());
                try
                {
                    Directory.Delete(directoryName, true);
                }
                catch (Exception exception)
                {
                    Log.Write(exception, "Delete driver");
                    MessageBox.Show("Driver is in use - cannot delete.", "LINQPad");
                    return;
                }
                this.PopulateDrivers();
            }
        }
Exemplo n.º 3
0
 private void ImportFile(string path)
 {
     using (ZipFile file = new ZipFile(path))
     {
         string   targetFolderName;
         ZipEntry entry = file.get_Item("header.xml");
         if (entry == null)
         {
             MessageBox.Show("Driver is missing header.xml metadata file.", "LINQPad", MessageBoxButtons.OK, MessageBoxIcon.Hand);
         }
         else
         {
             MemoryStream stream = new MemoryStream();
             entry.Extract(stream);
             stream.Position = 0L;
             string str = (string)XElement.Load(new StreamReader(stream)).Element("MainAssembly");
             if (string.IsNullOrEmpty(str))
             {
                 MessageBox.Show("Driver metadata file header.xml is missing the MainAssembly element.", "LINQPad", MessageBoxButtons.OK, MessageBoxIcon.Hand);
             }
             else
             {
                 str = str.Trim();
                 if (Path.GetExtension(str) == "")
                 {
                     str = str + ".dll";
                 }
                 if (file.get_Item(str) == null)
                 {
                     MessageBox.Show("Invalid driver: file '" + str + "' does not exist.", "LINQPad", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                 }
                 else
                 {
                     AssemblyName assemblyName;
                     Exception    exception;
                     bool         flag;
                     file.get_Item(str).Extract(this._tempDir, true);
                     try
                     {
                         assemblyName = AssemblyName.GetAssemblyName(Path.Combine(this._tempDir, str));
                     }
                     catch (Exception exception1)
                     {
                         exception = exception1;
                         MessageBox.Show("Driver contains invalid assembly '" + str + "' - " + exception.Message, "LINQPad", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                         return;
                     }
                     targetFolderName = assemblyName.Name + " (" + DCDriverLoader.GetPublicKeyToken(assemblyName) + ")";
                     string str2 = Path.Combine(DCDriverLoader.ThirdPartyDriverFolder, targetFolderName);
                     DCDriverLoader.UnloadDomains(true);
                     Thread.Sleep(200);
                     if (!Directory.Exists(DCDriverLoader.ThirdPartyDriverFolder))
                     {
                         Directory.CreateDirectory(DCDriverLoader.ThirdPartyDriverFolder);
                     }
                     FileUtil.AssignUserPermissionsToFolder(DCDriverLoader.ThirdPartyDriverFolder);
                     if (!(flag = Directory.Exists(str2)))
                     {
                         try
                         {
                             Directory.CreateDirectory(str2);
                         }
                         catch (Exception exception3)
                         {
                             exception = exception3;
                             MessageBox.Show("Unable to create directory '" + str2 + "' - " + exception.Message, "LINQPad", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                             return;
                         }
                     }
                     FileUtil.AssignUserPermissionsToFolder(str2);
                     new Thread(delegate {
                         try
                         {
                             WebHelper.GetWebClient().DownloadString("http://www.linqpad.net/RichClient/GetDataContextDriver.aspx?lib=" + targetFolderName);
                         }
                         catch
                         {
                         }
                     }).Start();
                     Exception       exception2 = null;
                     ZipEntry        entry2     = null;
                     List <ZipEntry> list       = (from e in file.get_Entries()
                                                   where !e.get_IsDirectory()
                                                   select e).ToList <ZipEntry>();
                     ZipEntry[] entryArray = list.ToArray();
                     int        index      = 0;
                     while (true)
                     {
                         if (index >= entryArray.Length)
                         {
                             break;
                         }
                         ZipEntry item = entryArray[index];
                         try
                         {
                             string str3 = Path.Combine(str2, item.get_FileName());
                             if (File.Exists(str3))
                             {
                                 MemoryStream stream2 = new MemoryStream();
                                 item.Extract(stream2);
                                 if (File.ReadAllBytes(str3).SequenceEqual <byte>(stream2.ToArray()))
                                 {
                                     list.Remove(item);
                                 }
                             }
                         }
                         catch
                         {
                         }
                         index++;
                     }
                     foreach (ZipEntry entry3 in list)
                     {
                         if (!entry3.get_IsDirectory())
                         {
                             try
                             {
                                 entry3.Extract(str2, true);
                             }
                             catch (Exception exception4)
                             {
                                 exception = exception4;
                                 if (exception2 == null)
                                 {
                                     exception2 = exception;
                                     entry2     = entry3;
                                 }
                             }
                         }
                     }
                     if (exception2 != null)
                     {
                         MessageBox.Show("Unable to write file '" + entry2.get_FileName() + "' - " + exception2.Message, "LINQPad", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                     }
                     else
                     {
                         string text = "Driver successfully " + (flag ? "updated." : "loaded.");
                         MainForm.Instance.RepopulateSchemaTree();
                         if (this._suggestRestart)
                         {
                             text           = text + "\r\n\r\nRestart LINQPad?";
                             this.DoRestart = MessageBox.Show(text, "LINQPad", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes;
                         }
                         else
                         {
                             MessageBox.Show(text, "LINQPad", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                         }
                         base.Close();
                     }
                 }
             }
         }
     }
 }