Пример #1
0
            async Task ProcessDirectoryAsync(ProgressReporterBase r, string dirName)
            {
                var entities = await Lfs.EnumDirectoryAsync(dirName, false, EnumDirectoryFlags.None);

                foreach (var file in entities.Where(x => x.IsFile && x.IsSymbolicLink == false))
                {
                    TotalReadNum++;

                    try
                    {
                        //Con.WriteLine($"File '{file.FullPath}'");

                        using (var f = Lfs.Open(file.FullPath))
                        {
                            while (true)
                            {
                                int readSize = await f.ReadAsync(this.TmpBuffer);

                                if (readSize == 0)
                                {
                                    break;
                                }

                                TotalReadSize += readSize;

                                r.ReportProgress(new ProgressData(TotalReadSize));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Con.WriteError($"Reading the file '{file.FullPath}' error. {ex.Message}");
                        TotalErrorNum++;
                    }
                }

                foreach (var dir in entities.Where(x => x.IsDirectory && x.Attributes.Bit(FileAttributes.ReparsePoint) == false && x.IsSymbolicLink == false))
                {
                    try
                    {
                        //Con.WriteLine($"Directory '{dir.FullPath}'");

                        await ProcessDirectoryAsync(r, dir.FullPath);
                    }
                    catch (Exception ex)
                    {
                        Con.WriteError($"Processing the directory '{dir.FullPath}' error. {ex.Message}");
                    }
                }
            }
Пример #2
0
        static int RawDiskRestore(ConsoleService c, string cmdName, string str)
        {
            ConsoleParam[] args =
            {
                new ConsoleParam("[diskName]", ConsoleService.Prompt, "Physical disk name: ", ConsoleService.EvalNotEmpty, null),
                new ConsoleParam("src",        ConsoleService.Prompt, "Source file name: ",   ConsoleService.EvalNotEmpty, null),
                new ConsoleParam("truncate"),
            };

            ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args);

            string diskName    = vl.DefaultParam.StrValue;
            string dstFileName = vl["src"].StrValue;
            long   truncate    = vl["truncate"].StrValue._ToLong();

            if (truncate <= 0)
            {
                truncate = -1;
            }
            else
            {
                truncate = (truncate + 4095L) / 4096L * 4096L;
            }

            using (var rawFs = new LocalRawDiskFileSystem())
            {
                using (var disk = rawFs.Open($"/{diskName}", writeMode: true))
                {
                    using (var file = Lfs.Open(dstFileName, flags: FileFlags.AutoCreateDirectory))
                    {
                        using (var reporter = new ProgressReporter(new ProgressReporterSetting(ProgressReporterOutputs.Console, toStr3: true), null))
                        {
                            FileUtil.CopyBetweenFileBaseAsync(file, disk, truncateSize: truncate, param: new CopyFileParams(asyncCopy: true, bufferSize: 16 * 1024 * 1024), reporter: reporter)._GetResult();
                        }
                    }
                }
            }

            return(0);
        }