Exemplo n.º 1
0
        public AmazonDriveSeekableStream(AmazonDrive Drive, FileMetadata_Info downitem) : base()
        {
            this.Drive = Drive;
            targetItem = downitem;
            FileSize   = targetItem.OrignalLength ?? 0;

            if (FileSize <= 0)
            {
                return;
            }

            slots = new SlotMaster(Drive, downitem, cts.Token);

            _Position = 0;

            if (downitem.contentProperties?.size > ConfigAPI.FilenameChangeTrickSize && !Regex.IsMatch(downitem.name, "^[\x20-\x7e]*$"))
            {
                OrgFilename = downitem.name;
                Config.Log.LogOut("AmazonDriveSeekableStream : <BIG FILE> temporary filename change");
                Config.Log.LogOut("AmazonDriveSeekableStream : orgnal name : " + OrgFilename);
                Drive.renameItem(downitem.id, ConfigAPI.temporaryFilename + downitem.id).Wait();
            }

            lastslot  = ((downitem.OrignalLength ?? 0) - 1) / AmazonDriveStreamConfig.slotsize;
            lockslot1 = AmazonDriveStreamConfig.lockslotfirstnum;
            lockslot2 = lastslot - AmazonDriveStreamConfig.lockslotlastnum;
            if (lockslot2 < lockslot1)
            {
                lockslot2 = lockslot1;
            }
            slots.CreateTask(0);
            slots.CreateTask(lockslot2);
            slots.CreateTask(lockslot1);
            slots.CreateTask(lockslot1 + AmazonDriveStreamConfig.preforwardnum);
        }
Exemplo n.º 2
0
        public static async Task <bool> EncryptFilename(string uploadfilename, string enckey, string checkpoint, CancellationToken ct = default(CancellationToken))
        {
            int retry = 30;

            while (--retry > 0)
            {
                var child = (await GetChanges(checkpoint, ct).ConfigureAwait(false)).Where(x => x.name.Contains(uploadfilename)).LastOrDefault();
                if (child?.status == "AVAILABLE")
                {
                    Config.Log.LogOut("EncryptFilename");
                    using (var ms = new MemoryStream())
                    {
                        byte[] plain = Encoding.UTF8.GetBytes(enckey);
                        ms.Write(plain, 0, plain.Length);
                        ms.Position = 0;
                        using (var enc = new CryptCTR.AES256CTR_CryptStream(ms, child.id))
                        {
                            byte[] buf = new byte[ms.Length];
                            enc.Read(buf, 0, buf.Length);
                            string cryptname = "";
                            foreach (var c in buf)
                            {
                                cryptname += (char)('\u2800' + c);
                            }
                            int retry2 = 30;
                            FileMetadata_Info reItem = null;
                            while (--retry2 > 0)
                            {
                                try
                                {
                                    if (reItem == null)
                                    {
                                        reItem = await Drive.renameItem(id : child.id, newname : cryptname, ct : ct).ConfigureAwait(false);
                                    }
                                }
                                catch { }
                                var child2 = (await GetChanges(checkpoint: ChangeCheckpoint, ct: ct).ConfigureAwait(false)).Where(x => x.name.Contains(cryptname)).LastOrDefault();
                                if (reItem != null && child2?.status == "AVAILABLE")
                                {
                                    AmazonDriveTree[reItem.id].IsEncrypted = CryptMethods.Method1_CTR;
                                    AmazonDriveTree[reItem.id].ReloadCryptedMethod1();
                                    break;
                                }
                                await Task.Delay(2000).ConfigureAwait(false);
                            }
                            return(true);
                        }
                    }
                }
                await Task.Delay(2000).ConfigureAwait(false);
            }
            return(false);
        }
Exemplo n.º 3
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                slots?.Dispose();
            }

            if (OrgFilename != null)
            {
                Config.Log.LogOut("AmazonDriveSeekableStream : rename to orignal");
                Drive.renameItem(targetItem.id, OrgFilename).Wait();
                OrgFilename = null;
            }

            base.Dispose(disposing);
        }