Example #1
0
 /// <summary>
 /// Initializes a new main form
 /// </summary>
 /// <param name="S">Current settings</param>
 public FrmMain(Settings S)
 {
     this.S = S;
     InitializeComponent();
     TbFilter_Leave(null, null);
     //Program.Main already tries to authorize.
     //If the date is still in the past, the user has to do so manually.
     if (S.Token.Expires < DateTime.UtcNow)
     {
         using (frmAuth f = new frmAuth(S))
         {
             if (f.ShowDialog() == DialogResult.OK)
             {
                 Tools.SaveSettings(S, Program.SettingsFile);
             }
             else
             {
                 MessageBox.Show("Could not authorize this application. Will exit now.", "No Authorization", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 Environment.Exit(1);
                 return;
             }
         }
     }
     I = new Imgur(S);
     if (S.UI.MainWindowMaximized)
     {
         WindowState = FormWindowState.Maximized;
     }
     else
     {
         Size ConfigSize = S.UI.MainWindowSize;
         if (ConfigSize.Height >= MinimumSize.Height && ConfigSize.Width >= MinimumSize.Width)
         {
             Size = ConfigSize;
         }
     }
     InitPages();
 }
Example #2
0
 /// <summary>
 /// Authorizes the application using OAuth2
 /// </summary>
 /// <param name="sender">Event sender</param>
 /// <param name="e">Event arguments</param>
 private void AuthorizeToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (S.Token.Expires < DateTime.UtcNow || MessageBox.Show($"This app is already authorized until {S.Token.Expires.ToShortDateString()} and connected to your account. Reauthorization will erase the cache.\r\nContinue?", "Authorization", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
     {
         using (frmAuth fAuth = new frmAuth(S))
         {
             if (fAuth.ShowDialog() == DialogResult.OK)
             {
                 Cache.ClearThumbnails();
                 Cache.ClearImages();
                 using (frmCacheBuilder fCache = new frmCacheBuilder(S))
                 {
                     fCache.ShowDialog();
                 }
                 I = new Imgur(S);
                 InitPages();
             }
             else
             {
                 MessageBox.Show("Unable to authorize your client. Your current authorization will be kept. Please try again", "Authorization Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }