private async Task <AmazonDrive> Authenticate(CancellationToken cs, bool interactiveAuth = true) { var settings = Gui.Properties.Settings.Default; var amazon = new AmazonDrive(AmazonSecret.ClientId, AmazonSecret.ClientSecret); amazon.OnTokenUpdate = this; if (!string.IsNullOrWhiteSpace(settings.AuthRenewToken)) { if (await amazon.AuthenticationByTokens( settings.AuthToken, settings.AuthRenewToken, settings.AuthTokenExpiration)) { return(amazon); } } if (interactiveAuth) { if (await amazon.AuthenticationByExternalBrowser(CloudDriveScopes.ReadAll | CloudDriveScopes.Write, TimeSpan.FromMinutes(10), cs, "http://localhost:{0}/signin/")) { return(amazon); } } cs.ThrowIfCancellationRequested(); return(null); }
protected async Task <AmazonDrive> Authenticate() { var settings = Properties.Settings.Default; // AmazonSecret is in git ignore because Amazon App info should not be public. // So to run tests you need to create your own class with your App Id and Secret. var amazon = new AmazonDrive(AmazonSecret.ClientId, AmazonSecret.ClientSecret); amazon.OnTokenUpdate = this; if (!string.IsNullOrWhiteSpace(settings.AuthRenewToken)) { if (await amazon.AuthenticationByTokens( settings.AuthToken, settings.AuthRenewToken, settings.AuthTokenExpiration)) { return(amazon); } } if (await amazon.AuthenticationByExternalBrowser(CloudDriveScopes.ReadAll | CloudDriveScopes.Write | CloudDriveScopes.Profile, TimeSpan.FromMinutes(10))) { return(amazon); } return(null); }
protected async Task<AmazonDrive> Authenticate() { var settings = Properties.Settings.Default; // AmazonSecret is in git ignore because Amazon App info should not be public. // So to run tests you need to create your own class with your App Id and Secret. var amazon = new AmazonDrive(AmazonSecret.ClientId, AmazonSecret.ClientSecret); amazon.OnTokenUpdate = this; if (!string.IsNullOrWhiteSpace(settings.AuthRenewToken)) { if (await amazon.AuthenticationByTokens( settings.AuthToken, settings.AuthRenewToken, settings.AuthTokenExpiration)) { return amazon; } } if (await amazon.AuthenticationByExternalBrowser(CloudDriveScopes.ReadAll | CloudDriveScopes.Write | CloudDriveScopes.Profile, TimeSpan.FromMinutes(10))) { return amazon; } return null; }
public async void test() { string clientId = "amzn1.application-oa2-client.d5581ef181e7426a92dcbd1ccbb5e89c"; string secret = "8180ad1b1e6688f5247a94f4d7a58d4c08d1abd6df3dd4cd576990725281d91b"; var amazon = new AmazonDrive(clientId, secret); var result = await amazon.AuthenticationByExternalBrowser(CloudDriveScopes.ReadAll | CloudDriveScopes.Write, TimeSpan.FromMinutes(1)).ConfigureAwait(false); }
protected async Task <AmazonDrive> Authenticate() { var settings = Properties.Settings.Default; var amazon = new AmazonDrive(AmazonSecret.ClientId, AmazonSecret.ClientSecret); amazon.OnTokenUpdate = this; if (!string.IsNullOrWhiteSpace(settings.AuthRenewToken)) { if (await amazon.AuthenticationByTokens( settings.AuthToken, settings.AuthRenewToken, settings.AuthTokenExpiration)) { return(amazon); } } if (await amazon.AuthenticationByExternalBrowser(CloudDriveScopes.ReadAll | CloudDriveScopes.Write, TimeSpan.FromMinutes(10))) { return(amazon); } return(null); }
public async Task AuthenticationByExternalBrowserTest() { var amazon = new AmazonDrive(AmazonSecret.ClientId, AmazonSecret.ClientSecret); var result = await amazon.AuthenticationByExternalBrowser(CloudDriveScopes.ReadAll | CloudDriveScopes.Write, TimeSpan.FromMinutes(1)).ConfigureAwait(false); Assert.True(result); }
protected AmazonTestsBase() { Task.Run(async() => { Amazon = await Authenticate(); var rootId = (await Amazon.Nodes.GetRoot()).id; var testDir = TestDirBase + new Random().Next(); var node = await Amazon.Nodes.GetChild(rootId, testDir) ?? await Amazon.Nodes.CreateFolder(rootId, testDir); TestDirId = node.id; }).Wait(); }
protected AmazonTestsBase() { Amazon = Authenticate().Result; var rootId = Amazon.Nodes.GetRoot().Result.id; var TestDir = TestDirBase + new Random().Next(); var node = Amazon.Nodes.GetChild(rootId, TestDir).Result; if (node == null) { node = Amazon.Nodes.CreateFolder(rootId, TestDir).Result; } TestDirId = node.id; }
public AmazonDriveBaseStream(AmazonDrive Drive, FileMetadata_Info downitem, bool autodecrypt = true, JobControler.Job parentJob = null) : base() { this.Drive = Drive; targetItem = downitem; FileSize = targetItem.OrignalLength ?? 0; this.autodecrypt = autodecrypt; if (parentJob == null) { downloadJob = JobControler.CreateNewJob( type: JobControler.JobClass.Download, info: new JobControler.Job.SubInfo { type = JobControler.Job.SubInfo.SubType.DownloadFile, size = downitem.contentProperties?.size ?? 0, }); downloadJob.DisplayName = downitem.name; downloadJob.ProgressStr = "wait for download"; downloadJob.Progress = -1; ct = downloadJob.ct; } else { ct = parentJob.ct; } if (FileSize < 0) { return; } if (downitem.contentProperties?.size > ConfigAPI.FilenameChangeTrickSize && !Regex.IsMatch(downitem.name, "^[\x20-\x7e]*$")) { Interlocked.Increment(ref Config.AmazonDriveTempCount); OrgFilename = targetItem.name; Config.Log.LogOut("AmazonDriveBaseStream : <BIG FILE> temporary filename change"); Config.Log.LogOut("AmazonDriveBaseStream : orgnal name : " + OrgFilename); Drive.renameItem(targetItem.id, ConfigAPI.temporaryFilename + targetItem.id).Wait(); } InitStream(); if (parentJob == null) { JobControler.Run(downloadJob, (j) => { downloadJob.ProgressStr = "download..."; downloadJob.Wait(ct: ct); downloadJob.Progress = 1; downloadJob.ProgressStr = "done."; }); } }
/// <summary> /// TODO /// </summary> /// <param name="cs"></param> /// <param name="interactiveAuth"></param> /// <returns></returns> public async Task <AmazonDrive> Authenticate(CancellationToken cs, bool interactiveAuth = true) { var Settings = ACDSettings.Default; if (Settings.AuthToken != null) { Authenticated = true; var token = new AuthToken(); token.access_token = Settings.AuthToken; amazon = new AmazonDrive(Settings.ClientId, Settings.ClientSecret, token); return(amazon); } amazon = new AmazonDrive(Settings.ClientId, Settings.ClientSecret); amazon.OnTokenUpdate = this; if (await amazon.AuthenticationByExternalBrowser(TimeSpan.FromMinutes(2), cs, "http://localhost:{0}/signin/")) { Authenticated = true; return(amazon); } return(null); }
static void Main(string[] args) { Console.WriteLine("Application start"); try { LogUtils.Log("*********** APP STARTED **********"); LogUtils.Log("Step # 1 : Unmapping previous drive."); string UserLinks = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Links\\Cloud Drive.lnk"); MirrorUtils.UnmapDrive(ApplicationSettings.MappedDriveLetter); if (!Directory.Exists(ApplicationSettings.MappedFolder)) { Directory.CreateDirectory(ApplicationSettings.MappedFolder); } ResourceUtils.SetFolderIcon(ApplicationSettings.MappedFolder, "Cloude Plus Drive"); LogUtils.Log("Removing favoriates...."); if (File.Exists(UserLinks)) { File.Delete(UserLinks); } LogUtils.Log("Adding folder into favoriates"); try { MirrorUtils.CreateShortcut(ApplicationSettings.MappedFolder, UserLinks, "", "", "", Path.GetDirectoryName(UserLinks)); } catch { } // this is comment by masroor LogUtils.Log(string.Format("Mapping drive {0} at {1}", ApplicationSettings.MappedDriveLetter, ApplicationSettings.MappedFolder)); MirrorUtils.MapDrive(ApplicationSettings.MappedDriveLetter, ApplicationSettings.MappedFolder); MirrorUtils.SetDriveIcon(ApplicationSettings.MappedDriveLetter); LogUtils.Log("drive mapped"); MirrorUtils.DisplayDriveInfo(); ResourceUtils.RecreateAllExecutableResources(); ICloudService dropbox = new DropBox(); ICloudService googledrive = new GoogleDrive(); ICloudService copydrive = new CopyDrive(); ICloudService onedrive = new OneDrive(); ICloudService amazon = new AmazonDrive(); dropbox.AvaiableMemoryInBytes = DirectoryUtils.SizeInBytes(0, 2, 512, 0, 0); googledrive.AvaiableMemoryInBytes = DirectoryUtils.SizeInBytes(0, 15, 0, 0, 0); copydrive.AvaiableMemoryInBytes = DirectoryUtils.SizeInBytes(0, 15, 0, 0, 0); onedrive.AvaiableMemoryInBytes = DirectoryUtils.SizeInBytes(0, 7, 0, 0, 0); amazon.AvaiableMemoryInBytes = DirectoryUtils.SizeInBytes(0, 5, 0, 0, 0); LogUtils.Log("Unmapping drives..."); LogUtils.Log(string.Format("Unmapping Dropbox: {0}", MirrorUtils.UnmapFolder(dropbox.ApplicationName))); LogUtils.Log(string.Format("Unmapping Google Drive: {0}", MirrorUtils.UnmapFolder(googledrive.ApplicationName))); LogUtils.Log(string.Format("Unmapping Copy Drive: {0}", MirrorUtils.UnmapFolder(copydrive.ApplicationName))); LogUtils.Log(string.Format("Unmapping One Drive: {0}", MirrorUtils.UnmapFolder(onedrive.ApplicationName))); LogUtils.Log(string.Format("Unmapping Amazon: {0}", MirrorUtils.UnmapFolder(amazon.ApplicationName))); LogUtils.Log(string.Format("Dropbox installed status: {0}", dropbox.IsInstalled)); LogUtils.Log(string.Format("Dropbox client folder: {0}", dropbox.ClientFolder)); LogUtils.Log(string.Format("Dropbox folder status: {0}", dropbox.ClientFolderExists ? "Exists" : "Not Exists")); LogUtils.Log(string.Format("Dropbox Drive Available Space: {0}", DirectoryUtils.PretifyBytes(dropbox.AvaiableMemoryInBytes))); LogUtils.Log(string.Format("Dropbox Drive Used Space: {0}", DirectoryUtils.PretifyBytes(dropbox.UsedMemoryInBytes))); LogUtils.Log(string.Format("Dropbox Drive mapping : {0}", MirrorUtils.MapFolder(dropbox))); LogUtils.Log("---------------------------------------------------------------"); LogUtils.Log(string.Format("Amazon Drive installed status: {0}", amazon.IsInstalled)); LogUtils.Log(string.Format("Amazon client folder: {0}", amazon.ClientFolder)); LogUtils.Log(string.Format("Amazon folder status: {0}", amazon.ClientFolderExists ? "Exists" : "Not Exists")); LogUtils.Log(string.Format("Amazon Drive Available Space: {0}", DirectoryUtils.PretifyBytes(amazon.AvaiableMemoryInBytes))); LogUtils.Log(string.Format("Amazon Drive Used Space: {0}", DirectoryUtils.PretifyBytes(amazon.UsedMemoryInBytes))); LogUtils.Log(string.Format("Amazon Drive mapping : {0}", MirrorUtils.MapFolder(amazon))); LogUtils.Log("---------------------------------------------------------------"); LogUtils.Log(string.Format("One Drive installed status: {0}", onedrive.IsInstalled)); LogUtils.Log(string.Format("One Drive Client Folder: {0}", onedrive.ClientFolder)); LogUtils.Log(string.Format("One Drive folder status: {0}", onedrive.ClientFolderExists ? "Exists" : "Not Exists")); LogUtils.Log(string.Format("One Drive Available Size: {0}", DirectoryUtils.PretifyBytes(onedrive.AvaiableMemoryInBytes))); LogUtils.Log(string.Format("One Drive Used Size: {0}", DirectoryUtils.PretifyBytes(onedrive.UsedMemoryInBytes))); LogUtils.Log(string.Format("One Drive mapping : {0}", MirrorUtils.MapFolder(onedrive))); LogUtils.Log("---------------------------------------------------------------"); LogUtils.Log(string.Format("Copy Drive installed status: {0}", copydrive.IsInstalled)); LogUtils.Log(string.Format("Copy Drive Client Folder: {0}", copydrive.ClientFolder)); LogUtils.Log(string.Format("Copy Drive folder status: {0}", copydrive.ClientFolderExists ? "Exists" : "Not Exists")); LogUtils.Log(string.Format("Copy Drive Available Size: {0}", DirectoryUtils.PretifyBytes(copydrive.AvaiableMemoryInBytes))); LogUtils.Log(string.Format("Copy Drive Used Size: {0}", DirectoryUtils.PretifyBytes(copydrive.UsedMemoryInBytes))); LogUtils.Log(string.Format("Copy Drive mapping : {0}", MirrorUtils.MapFolder(copydrive))); LogUtils.Log("---------------------------------------------------------------"); LogUtils.Log(string.Format("Google Drive installed status: {0}", googledrive.IsInstalled)); LogUtils.Log(string.Format("Google Drive Client Folder: {0}", googledrive.ClientFolder)); LogUtils.Log(string.Format("Google Drive folder status: {0}", googledrive.ClientFolderExists ? "Exists" : "Not Exists")); LogUtils.Log(string.Format("Google Drive Available Size: {0}", DirectoryUtils.PretifyBytes(googledrive.AvaiableMemoryInBytes))); LogUtils.Log(string.Format("Google Drive Used Size: {0}", DirectoryUtils.PretifyBytes(googledrive.UsedMemoryInBytes))); LogUtils.Log(string.Format("Google Drive mapping : {0}", MirrorUtils.MapFolder(googledrive))); } catch (Exception ex) { LogUtils.LogE(ex); } Console.WriteLine("Press any key to end"); Console.Read(); }
public BufferedAmazonBlockReader(FSItem item, AmazonDrive amazon) { this.item = item; this.amazon = amazon; }
public UploadService(int limit, AmazonDrive amazon) { uploadLimit = limit; uploadLimitSemaphore = new SemaphoreSlim(limit); this.amazon = amazon; }
public FSProvider(AmazonDrive amazon) { this.amazon = amazon; SmallFilesCache = new SmallFilesCache(amazon); SmallFilesCache.OnDownloadStarted = (id) => { Interlocked.Increment(ref downloadingCount); OnStatisticsUpdated?.Invoke(downloadingCount, uploadingCount); }; SmallFilesCache.OnDownloaded = (id) => { Interlocked.Decrement(ref downloadingCount); OnStatisticsUpdated?.Invoke(downloadingCount, uploadingCount); }; SmallFilesCache.OnDownloadFailed = (id) => { Interlocked.Decrement(ref downloadingCount); OnStatisticsUpdated?.Invoke(downloadingCount, uploadingCount); }; UploadService = new UploadService(2, amazon); UploadService.OnUploadFailed = (uploaditem, reason) => { Interlocked.Decrement(ref uploadingCount); OnStatisticsUpdated?.Invoke(downloadingCount, uploadingCount); var olditemPath = Path.Combine(UploadService.CachePath, uploaditem.Id); File.Delete(olditemPath); switch (reason) { case FailReason.ZeroLength: var item = GetItem(uploaditem.Path); item?.MakeNotUploading(); return; case FailReason.Conflict: return; } itemsTreeCache.DeleteFile(uploaditem.Path); }; UploadService.OnUploadFinished = (item, node) => { Interlocked.Decrement(ref uploadingCount); OnStatisticsUpdated?.Invoke(downloadingCount, uploadingCount); var newitem = FSItem.FromNode(item.Path, node); var olditemPath = Path.Combine(UploadService.CachePath, item.Id); var newitemPath = Path.Combine(SmallFilesCache.CachePath, node.id); if (!File.Exists(newitemPath)) { File.Move(olditemPath, newitemPath); } else { File.Delete(olditemPath); } SmallFilesCache.AddExisting(newitem); itemsTreeCache.Update(newitem); }; UploadService.OnUploadResumed = item => { itemsTreeCache.Add(item); Interlocked.Increment(ref uploadingCount); OnStatisticsUpdated?.Invoke(downloadingCount, uploadingCount); }; UploadService.Start(); }
public SmallFilesCache(AmazonDrive a) { amazon = a; }
public AmazonCloud() { amazon = new AmazonDrive(AmazonSecret.ClientId, AmazonSecret.ClientSecret); tokenUpdateListener = new TokenUpdateListener(this); amazon.OnTokenUpdate = tokenUpdateListener; }
internal async Task <char?> Mount(char driveLetter, bool readOnly, CancellationToken cs, bool interactiveAuth = true) { if (Interlocked.CompareExchange(ref mounted, 1, 0) != 0) { return(null); } var mountedEvent = new TaskCompletionSource <char>(); mountTask = Task.Factory.StartNew( async() => { try { lock (mountLock) { if (mountedLetter != null) { return; } mountedLetter = driveLetter; } AmazonDrive amazon = await Authenticate(cs, interactiveAuth); if (amazon == null) { Log.Error("Authentication failed"); mountedEvent.SetException(new InvalidOperationException("Authentication failed")); return; } provider = new FSProvider(amazon); provider.CachePath = Environment.ExpandEnvironmentVariables(Gui.Properties.Settings.Default.CacheFolder); provider.SmallFilesCacheSize = Gui.Properties.Settings.Default.SmallFilesCacheLimit * (1 << 20); provider.SmallFileSizeLimit = Gui.Properties.Settings.Default.SmallFileSizeLimit * (1 << 20); provider.OnStatisticsUpdated = ProviderStatisticsUpdated; cloudDrive = new VirtualDriveWrapper(provider); cloudDrive.Mounted = () => { mountedEvent.SetResult((char)mountedLetter); }; OnMountChanged?.Invoke(); try { cloudDrive.Mount(mountedLetter + ":\\", readOnly); mountedLetter = null; } catch (InvalidOperationException) { Log.Warn($"Drive letter {mountedLetter} is already used"); Exception lastException = null; foreach (char letter in VirtualDriveWrapper.GetFreeDriveLettes()) { try { mountedLetter = letter; cloudDrive.Mount(mountedLetter + ":\\", readOnly); break; } catch (InvalidOperationException ex) { lastException = ex; Log.Warn($"Drive letter {letter} is already used"); } } if (mountedLetter != null) { var message = "Could not find free letter"; if (lastException != null && lastException.InnerException != null) { message = lastException.InnerException.Message; } mountedEvent.SetException(new InvalidOperationException(message)); } } } catch (Exception ex) { mountedEvent.SetException(ex); } finally { mountedLetter = null; mounted = 0; OnMountChanged?.Invoke(); } }, TaskCreationOptions.LongRunning).Unwrap(); return(await mountedEvent.Task); }