Exemplo n.º 1
0
 private void toolStripMenuItemHelpVisitApplicationHomeRepository_Click(object sender, EventArgs e)
 {
     if (UpdateAndDownload.NetworkIsAvailable())
     {
         Process.Start("https://github.com/arsirantala/PodFilterDownloader");
     }
 }
Exemplo n.º 2
0
        private void RefreshContent()
        {
            if (lvFilters.Items.Count == 0 || !rbInstalled.Checked)
            {
                btnRefresh.Enabled = true;
                return;
            }

            Utils.PersistInstalledFiltersSha256AndContentLength(txtPodInstallationLoc.Text, _data, _parser,
                                                                _configFile);

            if (UpdateAndDownload.NetworkIsAvailable())
            {
                PersistServerETagAndContentLengthOfInstalledFilters();
                btnDownloadUpdatedFilters.Enabled = Utils.CheckIfInstalledFiltersHasUpdates(lvFilters, _data);
                btnRefresh.Enabled = true;
            }
            else
            {
                rbInstalled.Enabled = false;
                rbAvailable.Enabled = false;
                btnRefresh.Enabled  = false;
                btnMoreInfoOnSelectedFilter.Enabled = false;
                btnDownloadUpdatedFilters.Enabled   = false;
                xpProgressBar.Text = "";
            }
        }
Exemplo n.º 3
0
        private async void PersistServerETagAndContentLengthOfInstalledFilters()
        {
            btnCancel.Enabled = true;

            Progress <ProgressReportModel> progress = new Progress <ProgressReportModel>();

            progress.ProgressChanged += ReportProgress;

            var results =
                await UpdateAndDownload.RunGetFilterHttpHeadersInParallelAsync(progress, _data,
                                                                               txtPodInstallationLoc.Text);

            foreach (var result in results)
            {
                if (result.HttpStatusCode == HttpStatusCode.OK)
                {
                    var test = _data[result.FilterName].GetKeyData("server_etag");
                    test.Value = result.ETag;
                    _data[result.FilterName].SetKeyData(test);

                    test       = _data[result.FilterName].GetKeyData("server_content_length");
                    test.Value = result.ContentLength;
                    _data[result.FilterName].SetKeyData(test);

                    _parser.WriteFile(_configFile, _data);
                }
                else
                {
                    lvFilters.FindItemWithText(result.FilterName).SubItems[1].Text = Utils.GetLocalizedString("frmMain_File_unavailable_in_server");
                    lvFilters.Columns[1].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
                }
            }

            btnCancel.Enabled = false;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Install selected filter to PoD filter directory
        /// </summary>
        /// <param name="filters">List of filters to be installed</param>
        private async void InstallSelected(List <string> filters)
        {
            bool dontRemove = false;

            btnCancel.Enabled = true;

            Progress <ProgressReportModel> progress = new Progress <ProgressReportModel>();

            progress.ProgressChanged += ReportProgress;

            var results =
                await UpdateAndDownload.RunGetFilterContentInParallelAsync(progress, _data,
                                                                           txtPodInstallationLoc.Text, filters);

            foreach (var result in results)
            {
                if (result.HttpStatusCode == HttpStatusCode.OK)
                {
                    File.WriteAllText($"{txtPodInstallationLoc.Text}\\{FilterDirectoryName}\\{result.FilterName}.filter", result.Content);
                    var test = _data[result.FilterName].GetKeyData("downloaded_etag");
                    test.Value = result.ETag;
                    _data[result.FilterName].SetKeyData(test);

                    test       = _data[result.FilterName].GetKeyData("installed_content_length");
                    test.Value = result.ContentLength;
                    _data[result.FilterName].SetKeyData(test);

                    test       = _data[result.FilterName].GetKeyData("downloaded_sha256");
                    test.Value = Utils.BytesToString(Utils.GetHashSha256($"{txtPodInstallationLoc.Text}\\{FilterDirectoryName}\\{result.FilterName}.filter"));
                    _data[result.FilterName].SetKeyData(test);

                    _parser.WriteFile(_configFile, _data);
                }
                else
                {
                    dontRemove = true;

                    // Restore the install selected button back to enabled, so user can retry the download of selected filter in case of error
                    if (rbAvailable.Checked)
                    {
                        btnInstallSelected.Enabled = true;
                    }
                    MessageBox.Show(string.Format(Utils.GetLocalizedString("frmMain_Error_downloading_0_Error_was_1"),
                                                  result.FilterName, result.HttpStatusCode), Utils.GetLocalizedString("frmMain_Error"),
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }

            if (rbAvailable.Checked && !dontRemove)
            {
                var temp = lvFilters.FindItemWithText(lvFilters.SelectedItems[0].Text);
                lvFilters.Items.Remove(temp);
            }

            btnCancel.Enabled = false;

            RefreshContent();
        }
Exemplo n.º 5
0
 private void toolStripMenuItemHelpUpdateApp_Click(object sender, EventArgs e)
 {
     if (UpdateAndDownload.NetworkIsAvailable())
     {
         toolStripMenuItemHelpUpdateApp.Enabled = false;
         string updateChecker = Path.Combine(
             Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location) ??
             throw new InvalidOperationException(), @"twux64.exe");
         var process = Process.Start(updateChecker, $"/f {UpdateUrl} /p:IxothPodFilterDownloader.exe,IxothPodFilterDownloader_Setup.exe");
         toolStripMenuItemHelpUpdateApp.Enabled = true;
     }
 }
Exemplo n.º 6
0
        private void frmAdmin_Shown(object sender, EventArgs e)
        {
            _configFile = Path.Combine(
                Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location) ??
                throw new InvalidOperationException(), @"Configuration.ini");

            RefreshLB();

            if (!UpdateAndDownload.NetworkIsAvailable())
            {
                btnRestoreDefaultsFromInternet.Enabled = false;
            }
        }
Exemplo n.º 7
0
        private void btnMoreInfoOnSelectedFilter_Click(object sender, EventArgs e)
        {
            if (lvFilters.SelectedItems.Count == 0)
            {
                MessageBox.Show(Utils.GetLocalizedString("frmMain_No_Filter_Selected_In_LV"), Utils.GetLocalizedString("frmMain_Error"), MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                return;
            }

            if (UpdateAndDownload.NetworkIsAvailable())
            {
                Process.Start(_data[lvFilters.SelectedItems[0].Text].GetKeyData("home_repo_url").Value);
            }
        }
Exemplo n.º 8
0
        private static UpdateAndDownload.BoolEnum CheckFilterHasUpdateHelper(IniData data, string filter)
        {
            UpdateAndDownload.BoolEnum updatesFound;

            if (UpdateAndDownload.HasEtags(filter, data))
            {
                updatesFound = UpdateAndDownload.ETagCheck(filter, data);
            }
            else
            {
                updatesFound = UpdateAndDownload.HasSha256Tags(filter, data) ?
                               UpdateAndDownload.Sha256Check(filter, data) :
                               UpdateAndDownload.ContentLengthCheck(filter, data);
            }

            return(updatesFound);
        }
Exemplo n.º 9
0
        private void btnRestoreDefaultsFromInternet_Click(object sender, EventArgs e)
        {
            btnRestoreDefaultsFromInternet.Enabled = false;

            if (MessageBox.Show(Utils.GetLocalizedString("frmAdmin_Are_you_sure_you_want_to_restore_default_filters__This_will_override_every_filters_you_have_defined_in_this_application"),
                                Utils.GetLocalizedString("frmMain_Confirmation"), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                string content = UpdateAndDownload.DownloadFileContent("https://raw.githubusercontent.com/arsirantala/PodFilterDownloader/main/Configuration.ini");
                if (!string.IsNullOrEmpty(content))
                {
                    File.WriteAllText(_configFile, content);
                    RefreshLB();
                }
                else
                {
                    MessageBox.Show(Utils.GetLocalizedString("frmAdmin_There_was_an_error_when_attempted_to_download_the_default_Configuration_ini_file_from_the_applications_home_repo_in_the_internet__Please_try_again_later"),
                                    Utils.GetLocalizedString("frmMain_Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            btnRestoreDefaultsFromInternet.Enabled = true;
        }
Exemplo n.º 10
0
        private void frmMain_Shown(object sender, EventArgs e)
        {
            _configFile = Path.Combine(
                Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location) ??
                throw new InvalidOperationException(), @"Configuration.ini");

            _data = _parser.ReadFile(_configFile);

            txtPodInstallationLoc.Text =
                Directory.Exists(_data.Global.GetKeyData("PodInstallLocation").Value.Trim()) ?
                _data.Global.GetKeyData("PodInstallLocation").Value.Trim() : "";

            if (txtPodInstallationLoc.Text.Length == 0)
            {
                txtPodInstallationLoc.Text = $@"{Utils.GetD2InstallLocationFromRegistry()}\Path of Diablo";
            }

            // Use file system watcher to monitor if filter files are added to the filter directory, so we can persist
            // a) the sha256 value of new installed filter file and b) content length of it.
            // Can also get the server's etag and content length of the filter and persist those as well.
            // Have to keep mind of parallel downloading tasks as they are using inifile's write method, so that persisting of above info
            // is still thread safe
            if (Directory.Exists($"{txtPodInstallationLoc.Text}\\{FilterDirectoryName}"))
            {
                _fsw = new FileSystemWatcher($"{txtPodInstallationLoc.Text}\\{FilterDirectoryName}", "*.filter")
                {
                    IncludeSubdirectories = false,
                    NotifyFilter          = NotifyFilters.CreationTime | NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Size,
                    EnableRaisingEvents   = true
                };
                _fsw.Changed += fsw_Changed;
                _fsw.Deleted += fsw_Deleted;
            }

            // Populate listview with installed filters
            Utils.UpdateListview(lvFilters, rbInstalled, txtPodInstallationLoc.Text, _data, rbAvailable, btnInstallSelected,
                                 btnDownloadUpdatedFilters, btnRemoveSelected, btnMoreInfoOnSelectedFilter);

            // Localize the form
            rbAvailable.Text           = Utils.GetLocalizedString("frmMain_Available");
            rbInstalled.Text           = Utils.GetLocalizedString("frmMain_Installed");
            gbPoDInstallLocation.Text  = Utils.GetLocalizedString("frmMain_gbPoD_Install_Location");
            gbInstalled_Available.Text = Utils.GetLocalizedString("frmMain_gbInstalled_Available");
            gbOuter.Text                          = Utils.GetLocalizedString("frmMain_gbOuter");
            btnRefresh.Text                       = Utils.GetLocalizedString("frmMain_btnRefresh");
            btnRemoveSelected.Text                = Utils.GetLocalizedString("frmMain_btnRemove_Selected");
            btnMoreInfoOnSelectedFilter.Text      = Utils.GetLocalizedString("frmMain_btnMore_Info_On_Selected_Filter");
            btnInstallSelected.Text               = Utils.GetLocalizedString("frmMain_btnInstall_Selected");
            lblToolUpdateAvailable.Text           = Utils.GetLocalizedString("frmMain_Tool_update_available");
            btnDownloadUpdatedFilters.Text        = Utils.GetLocalizedString("frmMain_btnDownload_updates");
            toolStripMenuItemFile.Text            = Utils.GetLocalizedString("frmMain_File_Menu");
            toolStripMenuItemHelp.Text            = Utils.GetLocalizedString("frmMain_Help_Menu");
            toolStripMenuItemFileFilterAdmin.Text = Utils.GetLocalizedString("frmMain_Filter_admin");
            toolStripMenuItemFileExit.Text        = Utils.GetLocalizedString("frmMain_File_Exit_Menuitem");
            toolStripMenuItemHelpAbout.Text       = Utils.GetLocalizedString("frmMain_About");
            toolStripMenuItemHelpUpdateApp.Text   = Utils.GetLocalizedString("frmMain_Update_app");
            toolStripMenuItemHelpVisitApplicationHomeWiki.Text       = Utils.GetLocalizedString("frmMain_Visit_application_home_repository_wiki_page");
            toolStripMenuItemHelpVisitApplicationHomeRepository.Text = Utils.GetLocalizedString("frmMain_Visit_application_home_repository_page");

            btnCancel.Text     = Utils.GetLocalizedString("frmMain_Cancel");
            xpProgressBar.Text = Utils.GetLocalizedString("frmMain_Checking_updates_from_servers");


            if (!UpdateAndDownload.NetworkIsAvailable())
            {
                MessageBox.Show(Utils.GetLocalizedString("frmMain_This_application_requires_internet_connection_in_order_to_work"),
                                Utils.GetLocalizedString("frmMain_Error"), MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                // Check if to the application itself is updates available
                string updateChecker = Path.Combine(
                    Path.GetDirectoryName(Assembly.GetEntryAssembly()?.Location) ??
                    throw new InvalidOperationException(), @"twux64.exe");

                if (File.Exists(updateChecker))
                {
                    var process = Process.Start(updateChecker, $"/n /qb {UpdateUrl}");
                    if (process != null)
                    {
                        process.WaitForExit(MaxTimeInMSToWaitForUpdateCheck);

                        if (process.HasExited)
                        {
                            if (process.ExitCode == 1604)
                            {
                                lblToolUpdateAvailable.Visible = true;
                            }
                            else if (process.ExitCode == 1634)
                            {
                                lblToolUpdateAvailable.Visible = false;
                            }
                        }
                        else
                        {
                            lblToolUpdateAvailable.Visible = false;
                        }
                    }
                }
                else
                {
                    lblToolUpdateAvailable.Visible = false;
                }
            }

            RefreshContent();
        }