void dlItem_DownloadCompleted(object sender, AsyncCompletedEventArgs e) { IGameFileDownloadable dlItem = sender as IGameFileDownloadable; if (DownloadView != null && dlItem != null) { DownloadView.UpdateDownload(sender, string.Format("{0} ({1})", dlItem.FileName, e.Cancelled ? "Cancelled" : "Complete")); m_currentDownloads.Remove(dlItem); } }
void dlItem_DownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e) { IGameFileDownloadable dlItem = sender as IGameFileDownloadable; if (DownloadView != null && dlItem != null && (e.ProgressPercentage == 100 || DateTime.Now.Subtract(m_dtLastDowanloadUpdate).TotalMilliseconds > 400)) { m_dtLastDowanloadUpdate = DateTime.Now; DownloadView.UpdateDownload(sender, e.ProgressPercentage); DownloadView.UpdateDownload(sender, string.Format("{0} - {1}/{2}MB", dlItem.FileName, Math.Round(e.BytesReceived / 1024.0 / 1024.0, 1), Math.Round(e.TotalBytesToReceive / 1024.0 / 1024.0, 1))); } }
void view_DownloadCancelled(object sender, EventArgs e) { var cancelled = DownloadView.GetCancelledDownloads(); foreach (object obj in cancelled) { IGameFileDownloadable dlItem = obj as IGameFileDownloadable; if (dlItem != null) { dlItem.Cancel(); m_currentDownloads.Remove(dlItem); } } }
public void Download(IGameFileDataSourceAdapter adapter, IGameFileDownloadable dlItem) { if (dlItem != null && !IsDownloading(dlItem)) { try { m_currentDownloads.Add(dlItem); dlItem.DownloadProgressChanged += dlItem_DownloadProgressChanged; dlItem.DownloadCompleted += dlItem_DownloadCompleted; if (DownloadView != null) { DownloadView.AddDownload(dlItem, dlItem.FileName); } dlItem.Download(adapter, Path.Combine(DownloadDirectory.GetFullPath(), dlItem.FileName)); } catch { //failed, nothing to do } } }
private async void Initialize() { string dataSource = Path.Combine(Directory.GetCurrentDirectory(), DbDataSourceAdapter.GetDatabaseFileName()); DataAccess access = new DataAccess(new SqliteDatabaseAdapter(), DbDataSourceAdapter.CreateConnectionString(dataSource)); m_versionHandler = new VersionHandler(access, DataSourceAdapter, AppConfiguration); if (m_versionHandler.UpdateRequired()) { m_versionHandler.UpdateProgress += handler_UpdateProgress; m_progressBarUpdate = CreateProgressBar("Updating...", ProgressBarStyle.Continuous); ProgressBarStart(m_progressBarUpdate); await Task.Run(() => ExecuteVersionUpdate()); ProgressBarEnd(m_progressBarUpdate); AppConfiguration.Refresh(); //We have to refresh here because a column may have been added to the Configuration table } try { //Only set location and window state if the location is valid, either way we always set Width, Height, and splitter values if (ValidatePosition(AppConfiguration)) { StartPosition = FormStartPosition.Manual; Location = new Point(AppConfiguration.AppX, AppConfiguration.AppY); WindowState = AppConfiguration.WindowState; } Width = AppConfiguration.AppWidth; Height = AppConfiguration.AppHeight; splitTopBottom.SplitterDistance = AppConfiguration.SplitTopBottom; splitLeftRight.SplitterDistance = AppConfiguration.SplitLeftRight; } catch (DirectoryNotFoundException ex) { MessageBox.Show(this, string.Format("The directory specified in your settings was incorrect: '{0}'", ex.Message), "Configuration Error", MessageBoxButtons.OK, MessageBoxIcon.Error); tblMain.Enabled = false; return; } if (AppConfiguration.CleanTemp) { CleanTempDirectory(); } DirectoryDataSourceAdapter = new DirectoryDataSourceAdapter(AppConfiguration.GameFileDirectory); SetupTabs(); RebuildTagToolStrip(); RebuildUtilityToolStrip(); m_downloadView = new DownloadView(); m_downloadView.UserPlay += DownloadView_UserPlay; m_downloadHandler = new DownloadHandler(AppConfiguration.TempDirectory, m_downloadView); ctrlAssociationView.Initialize(DataSourceAdapter, AppConfiguration); ctrlAssociationView.FileDeleted += ctrlAssociationView_FileDeleted; ctrlAssociationView.FileOrderChanged += ctrlAssociationView_FileOrderChanged; ctrlAssociationView.RequestScreenshots += CtrlAssociationView_RequestScreenshots; m_splash.Close(); await CheckFirstInit(); UpdateLocal(); SetupSearchFilters(); HandleTabSelectionChange(); }
private void InitDownloadView() { m_downloadView = new DownloadView(); m_downloadView.UserPlay += DownloadView_UserPlay; m_downloadHandler = new DownloadHandler(AppConfiguration.TempDirectory, m_downloadView); }
public DownloadHandler(LauncherPath downloadDirectory, DownloadView view) { DownloadDirectory = downloadDirectory; DownloadView = view; view.DownloadCancelled += view_DownloadCancelled; }