@@ -15,9 +15,6 @@ namespace SimpleTest
1515
1616 partial class Program
1717 {
18- // Add an ApiKey (from https://www.dropbox.com/developers/apps) here
19- private const string ApiKey = "XXXXXXXXXXXXXXX" ;
20-
2118 // This loopback host is for demo purpose. If this port is not
2219 // available on your machine you need to update this URL with an unused port.
2320 private const string LoopbackHost = "http://127.0.0.1:52475/" ;
@@ -225,31 +222,49 @@ private async Task<OAuth2Response> HandleJSRedirect(HttpListener http)
225222 /// <returns>A valid access token or null.</returns>
226223 private async Task < string > GetAccessToken ( )
227224 {
225+ Settings . Default . Upgrade ( ) ;
228226 Console . Write ( "Reset settings (Y/N) " ) ;
229227 if ( Console . ReadKey ( ) . Key == ConsoleKey . Y )
230228 {
231- // Settings.Default.Reset();
229+ Settings . Default . Reset ( ) ;
232230 }
233231 Console . WriteLine ( ) ;
234232
235-
236- var accessToken = "" ;
233+ string apiKey = Settings . Default . ApiKey ;
234+ while ( string . IsNullOrWhiteSpace ( apiKey ) )
235+ {
236+ Console . WriteLine ( "Create a Dropbox App at https://www.dropbox.com/developers/apps." ) ;
237+ Console . Write ( "Enter the API Key (or 'Quit' to exit): " ) ;
238+ apiKey = Console . ReadLine ( ) ;
239+ if ( apiKey . ToLower ( ) == "quit" )
240+ {
241+ Console . WriteLine ( "The API Key is required to connect to Dropbox." ) ;
242+ apiKey = "" ;
243+ break ;
244+ }
245+ else
246+ {
247+ Settings . Default . ApiKey = apiKey ;
248+ }
249+ }
237250
238- if ( string . IsNullOrEmpty ( accessToken ) )
251+ var accessToken = Settings . Default . AccessToken ;
252+
253+ if ( string . IsNullOrEmpty ( accessToken ) && ! string . IsNullOrWhiteSpace ( apiKey ) )
239254 {
240255 try
241256 {
242257 Console . WriteLine ( "Waiting for credentials." ) ;
243258 var state = Guid . NewGuid ( ) . ToString ( "N" ) ;
244- var authorizeUri = DropboxOAuth2Helper . GetAuthorizeUri ( OAuthResponseType . Token , ApiKey , RedirectUri , state : state ) ;
259+ var authorizeUri = DropboxOAuth2Helper . GetAuthorizeUri (
260+ OAuthResponseType . Token , apiKey , RedirectUri , state : state ) ;
245261 var http = new HttpListener ( ) ;
246262 http . Prefixes . Add ( LoopbackHost ) ;
247263
248264 http . Start ( ) ;
249265
250266 // Use StartInfo to ensure default browser launches.
251- System . Diagnostics . ProcessStartInfo startInfo =
252- new System . Diagnostics . ProcessStartInfo ( authorizeUri . ToString ( ) ) ;
267+ System . Diagnostics . ProcessStartInfo startInfo = new ( authorizeUri . ToString ( ) ) ;
253268 startInfo . UseShellExecute = true ;
254269
255270 System . Diagnostics . Process . Start ( startInfo ) ;
@@ -275,18 +290,17 @@ private async Task<string> GetAccessToken()
275290 var uid = result . Uid ;
276291 Console . WriteLine ( "Uid: {0}" , uid ) ;
277292
278- //Settings.Default.AccessToken = accessToken;
279- //Settings.Default.Uid = uid;
280-
281- //Settings.Default.Save();
293+ Settings . Default . AccessToken = accessToken ;
294+ Settings . Default . Uid = uid ;
282295 }
283296 catch ( Exception e )
284297 {
285298 Console . WriteLine ( "Error: {0}" , e . Message ) ;
286299 return null ;
287300 }
288301 }
289-
302+ Settings . Default . Save ( ) ;
303+ Settings . Default . Reload ( ) ;
290304 return accessToken ;
291305 }
292306
@@ -332,7 +346,7 @@ private async Task GetCurrentAccount(DropboxClient client)
332346 /// <param name="client">The dropbox client object.</param>
333347 /// <param name="path">The path to the target folder to delete.</param>
334348 /// <returns></returns>
335- private async Task < bool > PathExists ( DropboxClient client , string path )
349+ static private async Task < bool > PathExists ( DropboxClient client , string path )
336350 {
337351 try
338352 {
@@ -351,7 +365,7 @@ private async Task<bool> PathExists(DropboxClient client, string path)
351365 /// <param name="client">The dropbox client object.</param>
352366 /// <param name="path">The path to the target folder to delete.</param>
353367 /// <returns></returns>
354- private async Task < Metadata > DeleteFolder ( DropboxClient client , string path )
368+ static private async Task < Metadata > DeleteFolder ( DropboxClient client , string path )
355369 {
356370 if ( await PathExists ( client , path ) )
357371 {
0 commit comments