/// <summary> /// Main form closing - saves the settings to a file. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void frmMain_FormClosing(object sender, FormClosingEventArgs e) { var settings = new Settings { UserAgent = txtUserAgent.Text, RequestTimeout = txtRequestTimeout.Text, Proxy = txtProxy.Text, Threads = txtThreads.Text, DownloadFolder = txtDownloadFolder.Text, CreateNewFolder = cbCreateNewFolder.Checked, SaveStats = cbSaveStats.Checked, Delimiter = txtDelimiter.Text, SkipDescription = cbSkipMediaDescription.Checked, SkipPhotos = cbSkipPhotos.Checked, SkipVideos = cbSkipVideos.Checked, SkipLikes = cbSkipMediaLikes.Checked, SkipLikesMoreLess = cbSkipMediaLikesMoreLess.Text, SkipLikesCount = txtSkipMediaLikesCount.Text, SkipComments = cbSkipMediaComments.Checked, SkipCommentsMoreLess = cbSkipMediaCommentsMoreLess.Text, SkipCommentsCount = txtSkipMediaCommentsCount.Text, SkipUploadDate = cbSkipMediaUploadDate.Checked, TotalDownloadsEnabled = cbTotalDownloads.Checked, TotalDownloads = txtTotalDownloads.Text, SkipTopPosts = cbSkipTopPosts.Checked, AccountUsername = _isLogged == false ? string.Empty : txtAccountUsername.Text, AccountPassword = _isLogged == false ? string.Empty : txtAccountPassword.Text, HidePassword = cbHidePassword.Checked, StateData = _instaApi?.GetStateDataAsStream() }; SettingsSerialization.Save(settings); }
public ZkooHostAppWithTutorialApplication() : base() { // TODO: Check the correct way to catch all exceptions and show it "We're sorry" dialog. But the next way is still meaningless now, and sometimes this code can cause a problem that application cannot exit. //AppDomain.CurrentDomain.UnhandledException += (sender, e) => { ShutdownApplicationByException((Exception)e.ExceptionObject); }; try { Egs.BindableResources.Current.CultureChanged += delegate { ApplicationCommonSettings.HostApplicationName = Egs.EgsDeviceControlCore.Properties.Resources.CommonStrings_Zkoo; Egs.ZkooTutorial.BindableResources.Current.ChangeCulture(Egs.EgsDeviceControlCore.Properties.Resources.Culture.Name); }; Egs.BindableResources.Current.ChangeCulture(ApplicationCommonSettings.DefaultCultureInfoName); if (DuplicatedProcessStartBlocking.TryGetMutexOnTheBeginningOfApplicationConstructor() == false) { var msg = string.Format(System.Globalization.CultureInfo.InvariantCulture, Egs.EgsDeviceControlCore.Properties.Resources.CommonStrings_Application0IsAlreadyRunning, ApplicationCommonSettings.HostApplicationName); MessageBox.Show(msg, ApplicationCommonSettings.HostApplicationName); if (Application.Current != null) { Application.Current.Shutdown(); } return; } hostAppComponents = new EgsHostAppBaseComponents(); hostAppComponents.InitializeOnceAtStartup(); hostAppComponents.HasResetSettings += delegate { // You can modify the application default settings here. hostAppComponents.Device.Settings.FaceDetectionMethod.Value = Egs.PropertyTypes.FaceDetectionMethods.DefaultProcessOnEgsHostApplication; hostAppComponents.IsToStartTutorialWhenHostApplicationStart = true; }; if (SettingsSerialization.LoadSettingsJsonFile(hostAppComponents) == false) { hostAppComponents.Reset(); } hostAppComponents.CameraViewWindow.Closed += delegate { hostAppComponents.Dispose(); }; hostAppComponents.Disposing += delegate { // NOTE: Save settings before Dispose(). Target event is not Disposed but Disposing. if (hostAppComponents.CanSaveSettingsJsonFileSafely) { SettingsSerialization.SaveSettingsJsonFile(hostAppComponents); } if (navigator != null) { // detach static event Microsoft.Win32.SystemEvents.DisplaySettingsChanged -= SystemEvents_DisplaySettingsChanged; } // NOTE: IMPORTANT! if (navigator != null) { navigator.Close(); navigator = null; } zkooTutorialModel = null; }; base.Exit += delegate { if (hostAppComponents != null) { hostAppComponents.Dispose(); hostAppComponents = null; } DuplicatedProcessStartBlocking.ReleaseMutex(); }; hostAppComponents.CheckIfDeviceFirmwareIsLatestOrNotAndExitApplicationIfFailed(); // NOTE: If users exit the application by the button on Camera View while "Firmware Update" dialog, exception occurs. // MUSTDO: We will fix this. if (hostAppComponents.SettingsWindow == null) { return; } // NOTE: Codes about "Tutorial" application. // TODO: Tutorial application should be independent from this host application, so I wrote it as an event handler. var hasZkooTutorialLaunched = false; var zkooTutorialLaunchAction = new Action(() => { if (hasZkooTutorialLaunched == false) { zkooTutorialModel = new ZkooTutorialModel(hostAppComponents); navigator = new MainNavigationWindow(); // attach static event Microsoft.Win32.SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged; // NOTE: TODO: When exceptions occur in Initialize, we have to distinguish whether from Settings files or from source code. zkooTutorialModel.TutorialAppHeaderMenu.InitializeOnceAtStartup(navigator, zkooTutorialModel); zkooTutorialModel.InitializeOnceAtStartup(hostAppComponents); navigator.InitializeOnceAtStartup(zkooTutorialModel); hasZkooTutorialLaunched = true; } navigator.StartTutorial(); }); hostAppComponents.SettingsWindow.SettingsUserControl.TutorialAppSettingsGroupBoxVisibility = Visibility.Visible; hostAppComponents.StartTutorialCommand.PerformEventHandler += delegate { zkooTutorialLaunchAction.Invoke(); }; hostAppComponents.IsStartingDeviceFirmwareUpdate += delegate { if (navigator != null) { navigator.ExitTutorial(); } }; hostAppComponents.IsStartingHostApplicationUpdate += delegate { if (navigator != null) { navigator.ExitTutorial(); } }; if (ApplicationCommonSettings.IsInternalRelease || ApplicationCommonSettings.IsDebuggingInternal) { var exvisionInternalSettingsTabItem = new System.Windows.Controls.TabItem() { Header = "Exvision" }; exvisionInternalSettingsTabItem.Content = new Egs.Views.ExvisionSettingsUserControl(); hostAppComponents.SettingsWindow.SettingsUserControl.SettingsTabControl.Items.Add(exvisionInternalSettingsTabItem); } if (hostAppComponents.IsToStartTutorialWhenHostApplicationStart) { zkooTutorialLaunchAction.Invoke(); } } catch (Exception ex) { ShutdownApplicationByException(ex); } }
public ZkooHostAppApplication() : base() { hostAppComponents = null; try { Egs.BindableResources.Current.CultureChanged += delegate { ApplicationCommonSettings.HostApplicationName = Egs.EgsDeviceControlCore.Properties.Resources.CommonStrings_GestureCamera; }; Egs.BindableResources.Current.ChangeCulture(ApplicationCommonSettings.DefaultCultureInfoName); if (DuplicatedProcessStartBlocking.TryGetMutexOnTheBeginningOfApplicationConstructor() == false) { var msg = string.Format(System.Globalization.CultureInfo.InvariantCulture, Egs.EgsDeviceControlCore.Properties.Resources.CommonStrings_Application0IsAlreadyRunning, ApplicationCommonSettings.HostApplicationName); MessageBox.Show(msg, ApplicationCommonSettings.HostApplicationName); if (Application.Current != null) { Application.Current.Shutdown(); } return; } hostAppComponents = new EgsHostAppBaseComponents(); hostAppComponents.InitializeOnceAtStartup(); hostAppComponents.HasResetSettings += delegate { // You can modify the application default settings here. hostAppComponents.Device.Settings.CursorSpeedAndPrecisionMode.Value = Egs.PropertyTypes.CursorSpeedAndPrecisionModes.Standard; hostAppComponents.Device.Settings.FaceDetectionMethod.Value = Egs.PropertyTypes.FaceDetectionMethods.DefaultProcessOnEgsHostApplication; }; if (SettingsSerialization.LoadSettingsJsonFile(hostAppComponents) == false) { hostAppComponents.Reset(); } hostAppComponents.CameraViewWindow.Closed += delegate { hostAppComponents.Dispose(); }; hostAppComponents.Disposing += delegate { // NOTE: Save settings before Dispose(). Target event is not Disposed but Disposing. if (hostAppComponents.CanSaveSettingsJsonFileSafely) { SettingsSerialization.SaveSettingsJsonFile(hostAppComponents); } }; base.Exit += delegate { if (hostAppComponents != null) { hostAppComponents.Dispose(); hostAppComponents = null; } DuplicatedProcessStartBlocking.ReleaseMutex(); }; hostAppComponents.CheckIfDeviceFirmwareIsLatestOrNotAndExitApplicationIfFailed(); // NOTE: If users exit the application by the button on Camera View while "Firmware Update" dialog, exception occurs. // MUSTDO: We will fix this. if (hostAppComponents.SettingsWindow == null) { return; } // TODO: The tutorial program will be separated into an independent application. hostAppComponents.SettingsWindow.SettingsUserControl.TutorialAppSettingsGroupBoxVisibility = Visibility.Collapsed; hostAppComponents.StartTutorialCommand.CanPerform = false; } catch (Exception ex) { ShutdownApplicationByException(ex); } }
/// <summary> /// Main form load method - loads the settings from a file. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void frmMain_Load(object sender, EventArgs e) { Log(@"Successfully initialized form components and loaded software.", nameof(LogType.Success)); try { Log(@"Attempting to load application settings...", nameof(LogType.Info)); var settings = SettingsSerialization.Load(); txtUserAgent.Text = !String.IsNullOrEmpty(settings.UserAgent) ? settings.UserAgent : UserAgentGenerator.Generate(); txtRequestTimeout.Text = !String.IsNullOrEmpty(settings.RequestTimeout) ? settings.RequestTimeout : "150"; txtThreads.Text = !String.IsNullOrEmpty(settings.Threads) ? settings.Threads : "1"; txtProxy.Text = settings.Proxy; txtDownloadFolder.Text = !String.IsNullOrEmpty(settings.DownloadFolder) ? settings.DownloadFolder : Application.StartupPath; cbCreateNewFolder.Checked = settings.CreateNewFolder; cbSaveStats.Checked = settings.SaveStats; txtDelimiter.Text = settings.Delimiter; cbSkipMediaDescription.Checked = settings.SkipDescription; cbSkipPhotos.Checked = settings.SkipPhotos; cbSkipVideos.Checked = settings.SkipVideos; cbSkipMediaLikes.Checked = settings.SkipLikes; cbSkipMediaLikesMoreLess.Text = settings.SkipLikesMoreLess; txtSkipMediaLikesCount.Text = settings.SkipLikesCount; cbSkipMediaComments.Checked = settings.SkipComments; cbSkipMediaCommentsMoreLess.Text = settings.SkipCommentsMoreLess; txtSkipMediaCommentsCount.Text = settings.SkipCommentsCount; cbSkipMediaUploadDate.Checked = settings.SkipUploadDate; cbTotalDownloads.Checked = settings.TotalDownloadsEnabled; txtTotalDownloads.Text = settings.TotalDownloads; cbSkipTopPosts.Checked = settings.SkipTopPosts; //txtAccountUsername.Text = settings.AccountUsername; //txtAccountPassword.Text = settings.AccountPassword; cbHidePassword.Checked = settings.HidePassword; if (!string.IsNullOrEmpty(settings.AccountPassword) || !string.IsNullOrEmpty(settings.AccountPassword)) { _instaApi = InstaApiBuilder.CreateBuilder() .UseHttpClientHandler(_httpClientHandler) .SetUser(new UserSessionData { UserName = settings.AccountUsername, Password = settings.AccountPassword }) .Build(); txtAccountUsername.Text = settings.AccountUsername; txtAccountPassword.Text = settings.AccountPassword; if (settings.StateData != null) { _instaApi.LoadStateDataFromStream(settings.StateData); } } if (_instaApi != null) { gbDownload.Enabled = true; _isLogged = true; lblAccountLoginStatus.Text = @"Status: Successfully restored session."; lblAccountLoginStatus.ForeColor = Color.Green; Log($@"Successfully restored session as {settings.AccountUsername}.", nameof(LogType.Success)); btnAccountLogin.Enabled = false; btnAccountLogout.Enabled = true; } else { lblAccountLoginStatus.Text = @"Status: Failed to restore session."; lblAccountLoginStatus.ForeColor = Color.Red; Log($@"Failed to restore session.", nameof(LogType.Fail)); btnAccountLogin.Enabled = true; btnAccountLogout.Enabled = false; } Log(@"Successfully loaded application settings.", nameof(LogType.Success)); } catch (Exception ex) { txtUserAgent.Text = UserAgentGenerator.Generate(); txtRequestTimeout.Text = @"150"; txtThreads.Text = @"1"; txtDownloadFolder.Text = Application.StartupPath; Log(ex.Message, nameof(LogType.Error)); } try { using (var request = new Request(txtUserAgent.Text, null, double.Parse(txtRequestTimeout.Text))) { var response = await request.GetRequestResponseAsync("http://imristo.com/download/igdownloader/changelog.txt"); if (response.IsSuccessStatusCode) { txtChangelog.Text = await response.Content.ReadAsStringAsync(); } response = await request.GetRequestResponseAsync( "http://imristo.com/download/igdownloader/version.txt"); if (response.IsSuccessStatusCode) { lblLatestVersion.Text += await response.Content.ReadAsStringAsync(); } lblCurrentVersion.Text += Application.ProductVersion; } } catch (HttpRequestException) { Log(@"Failed to obtain changelog and latest version. Please check your Internet connection.", nameof(LogType.Error)); } }