Ejemplo n.º 1
0
        public static async Task <string> WriteToCacheAsync(this IDiskIOHelper ioHelper, IEntryModel entry, CancellationToken ct, bool force = false)
        {
            var mapping = ioHelper.Mapper[entry];

            if (!mapping.IsCached || force)
            {
                if (entry.IsDirectory)
                {
                    System.IO.Directory.CreateDirectory(mapping.IOPath);
                    var listing = await entry.Profile.ListAsync(entry, ct).ConfigureAwait(false);

                    foreach (var subEntry in listing)
                    {
                        await WriteToCacheAsync(ioHelper, subEntry, ct, force).ConfigureAwait(false);
                    }
                }
                else
                {
                    using (var srcStream = await ioHelper.OpenStreamAsync(entry.FullPath,
                                                                          FileExplorer.Defines.FileAccess.Read, ct))
                        using (var outputStream = System.IO.File.OpenWrite(mapping.IOPath))
                            await StreamUtils.CopyStreamAsync(srcStream, outputStream).ConfigureAwait(false);
                }
            }

            return(mapping.IOPath);
        }
Ejemplo n.º 2
0
        public async Task <Stream> ExtractSongAsync(TrackInfo trackInfo, Stream stream)
        {
            // Read song from BGM
            var pi = GetPlayInfo(trackInfo);
            var ms = await StreamUtils.CopyStreamAsync(stream, pi.Start, pi.Length);

            return(ms);
        }
Ejemplo n.º 3
0
        public override async Task <IScriptCommand> ExecuteAsync(ParameterDic pm)
        {
            var    srcProfile   = _srcModel.Profile as IDiskProfile;
            var    destProfile  = _destDirModel.Profile as IDiskProfile;
            string destName     = _srcModel.GetName();
            string srcFullName  = _srcModel.FullPath;
            string destFullName = _destDirModel.Combine(destName);

            ChangeType ct = ChangeType.Created;

            if (destFullName.StartsWith("::"))
            {
                return(ResultCommand.Error(new ArgumentException("Transfer does not work with shell folders.")));
            }
            if (File.Exists(destFullName))
            {
                File.Delete(destFullName);
                ct = ChangeType.Changed;
            }

            using (var srcStream = await srcProfile.DiskIO.OpenStreamAsync(_srcModel.FullPath,
                                                                           FileExplorer.Defines.FileAccess.Read, pm.CancellationToken))
                using (var destStream = await destProfile.DiskIO.OpenStreamAsync(destFullName,
                                                                                 FileExplorer.Defines.FileAccess.Write, pm.CancellationToken))
                {
                    _progress.Report(TransferProgress.From(srcFullName, destFullName));
                    await StreamUtils.CopyStreamAsync(srcStream, destStream, false, false, false,
                                                      p => _progress.Report(new TransferProgress()
                    {
                        CurrentProgressPercent = p
                    })).ConfigureAwait(false);
                }
            if (_removeOriginal)
            {
                await srcProfile.DiskIO.DeleteAsync(_srcModel, pm.CancellationToken).ConfigureAwait(false);
            }

            _progress.Report(TransferProgress.IncrementProcessedEntries());

            return(new NotifyChangedCommand(_destDirModel.Profile, destFullName,
                                            _srcModel.Profile, srcFullName, ct));
        }