Example #1
0
 /*
  * Opens the custom sound editor window. Make sure the currently selected filter is installed
  * before opening the window, and if it isn't ask the user if they want to install it.
  */
 private void btnCustomSoundsOpen_Click(object sender, EventArgs e)
 {
     if (txtCurrentVersion.Text != "Not Installed via FilterBro")
     {
         if (Directory.GetFiles(frmFilterBro.strPathOfExilePath, "*.*")
             .Where(s => frmCustomSounds.strSupportedExtensions.Contains(Path.GetExtension(s).ToLower())).Count() > 0)
         {
             frmCustomSounds csForm = new frmCustomSounds(this);
             csForm.FormClosed += new FormClosedEventHandler(CustomSoundsClosed);
             csForm.ShowDialog();
         }
         else
         {
             MessageBox.Show("You don't have any supported sound files in your Path of Exile directory. Supported extensions: " + frmCustomSounds.strSupportedExtensions);
         }
     }
     else if (MessageBox.Show("The currently selected filter is not installed. Do you want to install it?",
                              "Filter Not Installed", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         CheckUpdateSelectedFilter(false);
     }
 }
Example #2
0
        /*
         * Downloads the selected filter, extracts it, and processes it depending on which filter is selected.
         */
        private async void UpdateSelectedFilter(string downloadURL, string project)
        {
            lblStatus.Text = "Downloading " + project + ".zip....";
            lblStatus.Refresh();
            string strExtractDirectory = "";
            // Download the file
            WebClient wbDownloader = new WebClient();

            wbDownloader.Headers.Add("user-agent", "FilterBro");
            System.IO.Directory.CreateDirectory(strFilterBroPath);
            wbDownloader.DownloadFile(downloadURL, Path.Combine(strFilterBroPath, project + ".zip"));
            // Extract the file
            lblStatus.Text = "Extracting" + project + ".zip....";
            lblStatus.Refresh();
            using (ZipArchive zip = ZipFile.OpenRead(Path.Combine(strFilterBroPath, project + ".zip")))
            {
                strExtractDirectory = Path.Combine(strFilterBroPath, zip.Entries.First().FullName.TrimEnd('/'));
                // Remove the extracted directory if it exists
                try
                {
                    Directory.Delete(strExtractDirectory, true);
                }
                catch (DirectoryNotFoundException) { }
                zip.ExtractToDirectory(strFilterBroPath);
            }

            lblStatus.Text = "Copying files....";
            lblStatus.Refresh();
            // Get the files to copy based on the filter we are installing
            string[] filtersToCopy;
            switch (cboFilterSelector.SelectedItem.ToString())
            {
            case "NeverSink's Item Filter - Regular":
            case "One Filter to Rule Them All":
                filtersToCopy = Directory.GetFiles(strExtractDirectory, "*.filter");
                break;

            case "NeverSink's Item Filter - Blue":
                filtersToCopy = Directory.GetFiles(Path.Combine(strExtractDirectory, "(STYLE) BLUE"), "*.filter");
                break;

            case "NeverSink's Item Filter - Gaia":
                filtersToCopy = Directory.GetFiles(Path.Combine(strExtractDirectory, "(STYLE) GAIA"), "*.filter");
                break;

            case "NeverSink's Item Filter - Purple":
                filtersToCopy = Directory.GetFiles(Path.Combine(strExtractDirectory, "(STYLE) PURPLE"), "*.filter");
                break;

            case "NeverSink's Item Filter - Slick":
                filtersToCopy = Directory.GetFiles(Path.Combine(strExtractDirectory, "(STYLE) SLICK"), "*.filter");
                break;

            case "NeverSink's Item Filter - Vaal":
                filtersToCopy = Directory.GetFiles(Path.Combine(strExtractDirectory, "(STYLE) VAAL"), "*.filter");
                break;

            case "NeverSink's Item Filter - Velvet":
                filtersToCopy = Directory.GetFiles(Path.Combine(strExtractDirectory, "(STYLE) VELVET"), "*.filter");
                break;

            default:
                filtersToCopy = new string[0];
                break;
            }
            if (filtersToCopy.Count() == 0)
            {
                lblStatus.Text = "No filters found.";
            }
            else
            {
                // Delete old filters pertaining to the currently selected filter
                try {
                    foreach (string filter in dictLocalFiles[cboFilterSelector.SelectedItem.ToString()])
                    {
                        File.Delete(filter);
                    }
                } catch (KeyNotFoundException) { } // Ignore KeyNotFoundExceptions since that will occur if this is a new filter install, not an update

                // Copy filters to Path of Exile directory
                foreach (string filter in filtersToCopy)
                {
                    // Copy the file
                    File.Copy(filter, Path.Combine(strPathOfExilePath, Path.GetFileName(filter)), true);
                    // Tack on a FilterBro tag to the filter for future ease of use
                    // This allows us to add version numbers and such to filters that otherwise would not have them
                    string strFilterHeader = "#==========================================================================\n"
                                             + "# Filter downloaded with FilterBro\n"
                                             + "# FilterBro-X-Filter:\t" + cboFilterSelector.SelectedItem.ToString() + "\n"
                                             + "# FilterBro-X-Version:\t" + txtLatestVersion.Text + "\n"
                                             + "#\n";
                    string strFilterContents = File.ReadAllText(Path.Combine(strPathOfExilePath, Path.GetFileName(filter)));
                    File.WriteAllText(Path.Combine(strPathOfExilePath, Path.GetFileName(filter)), strFilterHeader + strFilterContents);
                }
            }

            lblStatus.Text = "Refreshing filters....";
            lblStatus.Refresh();
            // Refresh installed filters
            CheckFilterVersionLocal();

            // Update the text box
            UpdateVersionTextBoxes();

            lblStatus.Text = "";
            lblStatus.Refresh();
            txtLatestVersion.Text = txtCurrentVersion.Text;

            // Prompt the user if they would like to apply custom sounds if any exist
            if (dictFilterSounds[GetSelectedFilter()].Count > 0)
            {
                if (MessageBox.Show("Apply saved custom sounds?", "Custom Sounds", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    frmCustomSounds csForm = new frmCustomSounds(this);
                    csForm.bAutoApply = true;
                    csForm.ShowDialog();
                }
            }

            cboFilterSelector.Enabled = true;
        }