public MainForm(bool hidden) : base(formResizable: false) { #if RELEASE CheckForIllegalCrossThreadCalls = false; #endif CultureHelper.GloballySetCultureToGB(); MainFormInstance = this; InitializeComponent(); if (hidden) { ShowInTaskbar = false; CenterForm(); WindowState = FormWindowState.Minimized; Opacity = 0; StartHidden = true; } MusicDataFetcher = new MusicDataFetcher(); SetVersion("v" + Global.ApplicationVersion); lblIssues.GotFocus += LinkLabel_GotFocus; lblDiscoveredFiles.GotFocus += LinkLabel_GotFocus; if (!EdgeDependencyChecker.CheckEdgeCoreFilesArePresentAndCorrect()) { btnConnectToYoutube.Enabled = false; InstallEdge(); } else { ConnectToYTMusicForm = new ConnectToYTMusic(this); } FileScanner = new FileScanner(this); FileUploader = new FileUploader(this); PlaylistProcessor = new PlaylistProcessor(this); IdleProcessor = new IdleProcessor(this); QueueChecker = new QueueChecker(this); InitialiseTimers(); InitialiseTooltips(); InitialiseSystemTrayIconMenuButtons(); ConnectToYouTubeMusic(); StartMainProcess(); }
// Connect to TY Music private void BtnConnectToYouTube_Click(object sender, EventArgs e) { try { ConnectToYTMusicForm.Show(); ThreadPool.QueueUserWorkItem(delegate { SetConnectedToYouTubeMusic(Requests.IsAuthenticated(Settings.AuthenticationCookie)); }); } catch (Exception) { try { // HACK: Odd behaviour on 'reshow' form. This is a workaround. ConnectToYTMusicForm.BrowserControl.Dispose(); ConnectToYTMusicForm.Dispose(); ConnectToYTMusicForm = new ConnectToYTMusic(this); ConnectToYTMusicForm.Show(); ThreadPool.QueueUserWorkItem(delegate { SetConnectedToYouTubeMusic(Requests.IsAuthenticated(Settings.AuthenticationCookie)); }); } catch (Exception) { MetroMessageBox.Show( this, Environment.NewLine + "You must install the latest verion of Microsoft Edge from the Canary channel for this to work:" + Environment.NewLine + Environment.NewLine + "https://www.microsoftedgeinsider.com/en-us/download", "Dependency Required", MessageBoxButtons.OK, MessageBoxIcon.Stop, 200); } } }
public void InstallEdge() { InstallingEdge = true; _installingEdgeThread = new Thread((ThreadStart) delegate { SetConnectToYouTubeButtonEnabled(false); SetStatusMessage("Installing Canary Edge Core. This may take a couple of minutes...", "Preparing dependencies"); try { using (var archive = SevenZipArchive.Open(Path.Combine(Global.WorkingDirectory, $"AppData\\{Global.EdgeVersion}.7z"))) { using (var reader = archive.ExtractAllEntries()) { var options = new ExtractionOptions { ExtractFullPath = true, Overwrite = true }; reader.WriteAllToDirectory(Global.EdgeFolder, options); } } } catch (Exception e) { Console.Out.WriteLine(e.Message); } InstallingEdge = false; ConnectToYTMusicForm = new ConnectToYTMusic(this); SetConnectToYouTubeButtonEnabled(true); }) { IsBackground = true }; _installingEdgeThread.Start(); }
public MainForm(bool hidden) : base(formResizable: false) { #if RELEASE CheckForIllegalCrossThreadCalls = false; #endif CultureHelper.GloballySetCultureToGB(); MainFormInstance = this; InitializeComponent(); btnConnectToYoutube.Enabled = false; if (hidden) { ShowInTaskbar = false; CenterForm(); WindowState = FormWindowState.Minimized; Opacity = 0; StartHidden = true; } MusicDataFetcher = new MusicDataFetcher(); SetVersion("v" + Global.ApplicationVersion); lblIssues.GotFocus += LinkLabel_GotFocus; lblDiscoveredFiles.GotFocus += LinkLabel_GotFocus; ConnectToYTMusicForm = new ConnectToYTMusic(this); FileScanner = new FileScanner(this); FileUploader = new FileUploader(this); PlaylistProcessor = new PlaylistProcessor(this); IdleProcessor = new IdleProcessor(this); QueueChecker = new QueueChecker(this); InitialiseTimers(); InitialiseTooltips(); InitialiseSystemTrayIconMenuButtons(); ConnectToYouTubeMusic(); StartMainProcess(); // Restart everything after 24 hours (is the application is continually run) _restartThread = new Thread((ThreadStart) delegate { while (Settings == null) { ThreadHelper.SafeSleep(500); } while (true) { if (Settings.UploadPlaylists) { if (!Settings.LastPlaylistUpload.HasValue) { Settings.LastPlaylistUpload = DateTime.Now.AddHours(Global.SessionRestartHours * -1).AddHours(-2); } if (!_scanAndUploadThread.IsAlive && DateTime.Now > ((DateTime)Settings.LastPlaylistUpload).AddHours(Global.SessionRestartHours) && !PlaylistProcessor.ProcessingPlaylistsFinished) { StartMainProcess(); } } if (DateTime.Now.AddHours(Global.SessionRestartHours * -1) > SessionStart) { SessionStart = DateTime.Now; PlaylistProcessor.ProcessingPlaylistsFinished = false; StartMainProcess(); } ThreadHelper.SafeSleep(15000); } }) { IsBackground = true }; _restartThread.Start(); }