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."; }); } }
protected override void Dispose(bool disposing) { if (disposing) { downloadJob?.Cancel(); innerStream?.Dispose(); } if (OrgFilename != null) { Config.Log.LogOut("AmazonDriveBaseStream : rename to orignal"); Drive.renameItem(targetItem.id, OrgFilename).Wait(); OrgFilename = null; Interlocked.Decrement(ref Config.AmazonDriveTempCount); } base.Dispose(disposing); }