Exemple #1
0
        private void btnOpenZip_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title  = Resources.FileDialog_OpenAppZipCaption;
            ofd.Filter = Resources.FileDialog_OpenAppZipFilter;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                tbZipFile.Text = ofd.FileName;
                if (Directory.Exists(LocalFolder))
                {
                    Directory.Delete(LocalFolder, true);
                }

                Directory.CreateDirectory(LocalFolder);
                File.Copy(ofd.FileName, LocalFolder + Path.GetFileName(ofd.FileName));

                String LocalFile = LocalFolder + Path.GetFileName(ofd.FileName);
                SimpleUnZipper.UnZipTo(LocalFile, LocalFolder);

                File.Delete(LocalFile);

                AutoDetectContent();
            }
        }
Exemple #2
0
        public static string DownloadHTTPFileAndExtract(string completeURL, string LocalFolder, bool ClearTemp, Functions.UpdateProgressInfo OnProgressChanged)
        {
            if (ClearTemp)
            {
                if (Directory.Exists(LocalFolder))
                {
                    Directory.Delete(LocalFolder, true);
                }
            }

            if (!Directory.Exists(LocalFolder))
            {
                Directory.CreateDirectory(LocalFolder);
            }

            DownloadHTTPFile(completeURL, LocalFolder, OnProgressChanged);

            if (completeURL.EndsWith("zip", StringComparison.CurrentCultureIgnoreCase))
            {
                string LocalFile = LocalFolder + completeURL.Substring(completeURL.LastIndexOf('/') + 1);
                SimpleUnZipper.UnZipTo(LocalFile, LocalFolder);
                File.Delete(LocalFile);
            }

            if ((Directory.GetFiles(LocalFolder).Length == 0) && (Directory.GetDirectories(LocalFolder).Length == 1))
            {
                LocalFolder = Directory.GetDirectories(LocalFolder)[0] + Path.DirectorySeparatorChar;
            }

            return(LocalFolder);
        }
        private void installFirmwareToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show(Resources.MessageBox_InstallFirmwareWarning, Resources.MessageBox_InstallFirmwareCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                OpenFileDialog odf = new OpenFileDialog();
                odf.Title  = Resources.FileDialog_SelectFirmwareFileCaption;
                odf.Filter = Resources.FileDialog_SelectFirmwareFileFilter;
                if (odf.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        string LocalFolder = Constants.TemporaryFolder;
                        if (Directory.Exists(LocalFolder))
                        {
                            Directory.Delete(LocalFolder, true);
                        }
                        Directory.CreateDirectory(LocalFolder);

                        File.Copy(odf.FileName, LocalFolder + "firmware.zip");
                        SimpleUnZipper.UnZipTo(LocalFolder + "firmware.zip", LocalFolder);

                        File.Delete(LocalFolder + "firmware.zip");

                        if ((Directory.GetFiles(LocalFolder).Length == 0) && (Directory.GetDirectories(LocalFolder).Length == 1))
                        {
                            LocalFolder = Directory.GetDirectories(LocalFolder)[0] + Path.DirectorySeparatorChar;
                        }
                        HttpCommands.DownloadHTTPFileAndExtract(Settings.Default.CommandsScriptURL, LocalFolder, false, ProgressChanges);

                        btnPrev.Enabled = btnNext.Enabled = btnExit.Enabled = menuStrip1.Enabled = false;
                        Application.DoEvents();
                        RepositoryApplicationInfo app    = new RepositoryApplicationInfo(string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, new string[0], "commands.cgi?firmwareinstall", string.Empty, string.Empty);
                        UploadInstaller           ulinst = new UploadInstaller(app, ProgressChanges, OnInstallComplete);
                        ulinst.Install();
                    }
                    catch (Exception ex)
                    {
                        menuStrip1.Enabled = true;
                        UpdateButtonState();
                        Logger.GetInstance().AddLogLine(LogLevel.Error, "Installing firmware failed", ex);
                        MessageBox.Show(Resources.MessageBox_InstallFirmwareFailed, Resources.MessageBox_InstallFirmwareCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }