2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
// Aaru Data Preservation Suite
|
2016-07-27 02:35:29 +01:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : ExtractFiles.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2016-07-27 02:35:29 +01:00
|
|
|
//
|
2020-03-11 21:56:55 +00:00
|
|
|
// Component : Commands.
|
2016-07-27 02:35:29 +01:00
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
2020-03-11 21:56:55 +00:00
|
|
|
// Implements the 'extract' command.
|
2016-07-27 02:35:29 +01:00
|
|
|
//
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as
|
|
|
|
|
// published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-12-03 16:07:10 +00:00
|
|
|
// Copyright © 2011-2023 Natalia Portillo
|
2016-07-27 02:35:29 +01:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2020-01-02 04:09:39 +00:00
|
|
|
using System.CommandLine;
|
2022-04-10 12:54:04 +01:00
|
|
|
using System.CommandLine.NamingConventionBinder;
|
2017-12-19 19:33:46 +00:00
|
|
|
using System.IO;
|
2022-05-20 19:39:08 +01:00
|
|
|
using System.Runtime.InteropServices;
|
2017-12-19 19:33:46 +00:00
|
|
|
using System.Text;
|
2020-02-27 00:33:26 +00:00
|
|
|
using Aaru.CommonTypes;
|
|
|
|
|
using Aaru.CommonTypes.Enums;
|
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
|
|
|
|
using Aaru.CommonTypes.Structs;
|
|
|
|
|
using Aaru.Console;
|
|
|
|
|
using Aaru.Core;
|
2022-11-18 11:18:45 +00:00
|
|
|
using Aaru.Localization;
|
2021-08-17 18:18:05 +01:00
|
|
|
using JetBrains.Annotations;
|
2021-09-13 19:53:32 +01:00
|
|
|
using Spectre.Console;
|
2020-02-27 00:33:26 +00:00
|
|
|
using FileAttributes = Aaru.CommonTypes.Structs.FileAttributes;
|
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
namespace Aaru.Commands.Filesystem;
|
|
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
sealed class ExtractFilesCommand : Command
|
2016-07-27 02:35:29 +01:00
|
|
|
{
|
2021-11-14 03:52:44 +00:00
|
|
|
const long BUFFER_SIZE = 16777216;
|
|
|
|
|
|
2022-11-18 11:18:45 +00:00
|
|
|
public ExtractFilesCommand() : base("extract", UI.Filesystem_Extract_Command_Description)
|
2016-07-27 02:35:29 +01:00
|
|
|
{
|
2022-04-10 12:54:04 +01:00
|
|
|
Add(new Option<string>(new[]
|
|
|
|
|
{
|
|
|
|
|
"--encoding", "-e"
|
2022-11-18 11:18:45 +00:00
|
|
|
}, () => null, UI.Name_of_character_encoding_to_use));
|
2021-11-14 03:52:44 +00:00
|
|
|
|
2022-04-10 12:54:04 +01:00
|
|
|
Add(new Option<string>(new[]
|
|
|
|
|
{
|
|
|
|
|
"--options", "-O"
|
2022-11-18 11:18:45 +00:00
|
|
|
}, () => null, UI.Comma_separated_name_value_pairs_of_filesystem_options));
|
2021-09-13 20:31:32 +01:00
|
|
|
|
2022-04-10 12:54:04 +01:00
|
|
|
Add(new Option<bool>(new[]
|
|
|
|
|
{
|
|
|
|
|
"--xattrs", "-x"
|
2022-11-18 11:18:45 +00:00
|
|
|
}, () => false, UI.Extract_extended_attributes_if_present));
|
2021-11-14 03:52:44 +00:00
|
|
|
|
2022-04-10 12:54:04 +01:00
|
|
|
Add(new Option<string>(new[]
|
|
|
|
|
{
|
|
|
|
|
"--namespace", "-n"
|
2022-11-18 11:18:45 +00:00
|
|
|
}, () => null, UI.Namespace_to_use_for_filenames));
|
2021-11-14 03:52:44 +00:00
|
|
|
|
|
|
|
|
AddArgument(new Argument<string>
|
2016-07-27 02:35:29 +01:00
|
|
|
{
|
2021-11-14 03:52:44 +00:00
|
|
|
Arity = ArgumentArity.ExactlyOne,
|
2022-11-18 11:18:45 +00:00
|
|
|
Description = UI.Disc_image_path,
|
2021-11-14 03:52:44 +00:00
|
|
|
Name = "image-path"
|
|
|
|
|
});
|
2019-01-05 16:59:23 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
AddArgument(new Argument<string>
|
|
|
|
|
{
|
|
|
|
|
Arity = ArgumentArity.ExactlyOne,
|
2022-11-18 11:18:45 +00:00
|
|
|
Description = UI.Directory_where_extracted_files_will_be_created,
|
2021-11-14 03:52:44 +00:00
|
|
|
Name = "output-dir"
|
|
|
|
|
});
|
2019-01-05 16:59:23 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
Handler = CommandHandler.Create(GetType().GetMethod(nameof(Invoke)));
|
|
|
|
|
}
|
2019-01-05 16:59:23 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
public static int Invoke(bool debug, bool verbose, string encoding, bool xattrs, string imagePath,
|
|
|
|
|
string @namespace, string outputDir, string options)
|
|
|
|
|
{
|
|
|
|
|
MainClass.PrintCopyright();
|
2019-01-05 16:59:23 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
if(debug)
|
|
|
|
|
{
|
|
|
|
|
IAnsiConsole stderrConsole = AnsiConsole.Create(new AnsiConsoleSettings
|
2019-01-05 16:59:23 +00:00
|
|
|
{
|
2022-11-15 15:58:43 +00:00
|
|
|
Out = new AnsiConsoleOutput(System.Console.Error)
|
2020-01-02 04:09:39 +00:00
|
|
|
});
|
2019-01-05 16:59:23 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
AaruConsole.DebugWriteLineEvent += (format, objects) =>
|
2019-01-05 16:59:23 +00:00
|
|
|
{
|
2021-11-14 03:52:44 +00:00
|
|
|
if(objects is null)
|
|
|
|
|
stderrConsole.MarkupLine(format);
|
|
|
|
|
else
|
|
|
|
|
stderrConsole.MarkupLine(format, objects);
|
|
|
|
|
};
|
2020-01-02 04:09:39 +00:00
|
|
|
}
|
|
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
if(verbose)
|
|
|
|
|
AaruConsole.WriteEvent += (format, objects) =>
|
|
|
|
|
{
|
|
|
|
|
if(objects is null)
|
|
|
|
|
AnsiConsole.Markup(format);
|
|
|
|
|
else
|
|
|
|
|
AnsiConsole.Markup(format, objects);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Statistics.AddCommand("extract-files");
|
|
|
|
|
|
|
|
|
|
AaruConsole.DebugWriteLine("Extract-Files command", "--debug={0}", debug);
|
|
|
|
|
AaruConsole.DebugWriteLine("Extract-Files command", "--encoding={0}", encoding);
|
|
|
|
|
AaruConsole.DebugWriteLine("Extract-Files command", "--input={0}", imagePath);
|
|
|
|
|
AaruConsole.DebugWriteLine("Extract-Files command", "--options={0}", options);
|
|
|
|
|
AaruConsole.DebugWriteLine("Extract-Files command", "--output={0}", outputDir);
|
|
|
|
|
AaruConsole.DebugWriteLine("Extract-Files command", "--verbose={0}", verbose);
|
|
|
|
|
AaruConsole.DebugWriteLine("Extract-Files command", "--xattrs={0}", xattrs);
|
|
|
|
|
|
|
|
|
|
var filtersList = new FiltersList();
|
|
|
|
|
IFilter inputFilter = null;
|
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
Core.Spectre.ProgressSingleSpinner(ctx =>
|
2021-11-14 03:52:44 +00:00
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
ctx.AddTask(UI.Identifying_file_filter).IsIndeterminate();
|
2021-11-14 03:52:44 +00:00
|
|
|
inputFilter = filtersList.GetFilter(imagePath);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Dictionary<string, string> parsedOptions = Core.Options.Parse(options);
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.DebugWriteLine("Extract-Files command", UI.Parsed_options);
|
2021-11-14 03:52:44 +00:00
|
|
|
|
|
|
|
|
foreach(KeyValuePair<string, string> parsedOption in parsedOptions)
|
|
|
|
|
AaruConsole.DebugWriteLine("Extract-Files command", "{0} = {1}", parsedOption.Key, parsedOption.Value);
|
|
|
|
|
|
|
|
|
|
parsedOptions.Add("debug", debug.ToString());
|
|
|
|
|
|
|
|
|
|
if(inputFilter == null)
|
2020-01-02 04:09:39 +00:00
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.ErrorWriteLine(UI.Cannot_open_specified_file);
|
2021-11-14 03:52:44 +00:00
|
|
|
|
|
|
|
|
return (int)ErrorNumber.CannotOpenFile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Encoding encodingClass = null;
|
2020-01-02 04:09:39 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
if(encoding != null)
|
|
|
|
|
try
|
2021-09-13 19:53:32 +01:00
|
|
|
{
|
2021-11-14 03:52:44 +00:00
|
|
|
encodingClass = Claunia.Encoding.Encoding.GetEncoding(encoding);
|
2021-09-13 19:53:32 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
if(verbose)
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.VerboseWriteLine(UI.encoding_for_0, encodingClass.EncodingName);
|
2021-09-13 19:53:32 +01:00
|
|
|
}
|
2021-11-14 03:52:44 +00:00
|
|
|
catch(ArgumentException)
|
|
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.ErrorWriteLine(UI.Specified_encoding_is_not_supported);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
return (int)ErrorNumber.EncodingUnknown;
|
|
|
|
|
}
|
2019-01-05 16:59:23 +00:00
|
|
|
|
2022-12-17 20:50:17 +00:00
|
|
|
PluginBase plugins = PluginBase.Singleton;
|
2016-07-27 02:35:29 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
IMediaImage imageFormat = null;
|
|
|
|
|
IBaseImage baseImage = null;
|
2021-09-13 19:53:32 +01:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
Core.Spectre.ProgressSingleSpinner(ctx =>
|
2021-09-13 19:53:32 +01:00
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
ctx.AddTask(UI.Identifying_image_format).IsIndeterminate();
|
2021-11-14 03:52:44 +00:00
|
|
|
baseImage = ImageFormat.Detect(inputFilter);
|
|
|
|
|
imageFormat = baseImage as IMediaImage;
|
2021-09-13 19:53:32 +01:00
|
|
|
});
|
2016-09-05 17:37:31 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
if(baseImage == null)
|
|
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.WriteLine(UI.Image_format_not_identified_not_proceeding_with_file_extraction);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
return (int)ErrorNumber.UnrecognizedFormat;
|
|
|
|
|
}
|
2018-06-22 08:08:38 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
if(imageFormat == null)
|
2016-07-27 02:35:29 +01:00
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.WriteLine(UI.Command_not_supported_for_this_image_type);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
return (int)ErrorNumber.InvalidArgument;
|
2016-07-27 02:35:29 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
if(verbose)
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.VerboseWriteLine(UI.Image_format_identified_by_0_1, imageFormat.Name, imageFormat.Id);
|
2021-11-14 03:52:44 +00:00
|
|
|
else
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.WriteLine(UI.Image_format_identified_by_0, imageFormat.Name);
|
2017-10-12 23:54:02 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
if(outputDir == null)
|
|
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.WriteLine(UI.Output_directory_missing);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
return (int)ErrorNumber.MissingArgument;
|
|
|
|
|
}
|
2020-01-02 04:09:39 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
if(Directory.Exists(outputDir) ||
|
|
|
|
|
File.Exists(outputDir))
|
|
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.ErrorWriteLine(UI.Destination_exists_aborting);
|
2021-11-14 03:52:44 +00:00
|
|
|
|
|
|
|
|
return (int)ErrorNumber.FileExists;
|
|
|
|
|
}
|
2017-10-12 23:54:02 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
Directory.CreateDirectory(outputDir);
|
2016-07-27 02:35:29 +01:00
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2021-11-14 03:52:44 +00:00
|
|
|
ErrorNumber opened = ErrorNumber.NoData;
|
2021-09-13 19:53:32 +01:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
Core.Spectre.ProgressSingleSpinner(ctx =>
|
2021-09-13 19:53:32 +01:00
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
ctx.AddTask(UI.Invoke_Opening_image_file).IsIndeterminate();
|
2021-11-14 03:52:44 +00:00
|
|
|
opened = imageFormat.Open(inputFilter);
|
2021-09-13 19:53:32 +01:00
|
|
|
});
|
2016-07-27 02:35:29 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
if(opened != ErrorNumber.NoError)
|
2019-10-05 13:49:21 +02:00
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.WriteLine(UI.Unable_to_open_image_format);
|
2022-11-23 16:06:46 +00:00
|
|
|
AaruConsole.WriteLine(Localization.Core.Error_0, opened);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
return (int)opened;
|
2019-10-05 13:49:21 +02:00
|
|
|
}
|
|
|
|
|
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.DebugWriteLine("Extract-Files command", UI.Correctly_opened_image_file);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.DebugWriteLine("Extract-Files command", UI.Image_without_headers_is_0_bytes,
|
2021-11-14 03:52:44 +00:00
|
|
|
imageFormat.Info.ImageSize);
|
2016-07-27 02:35:29 +01:00
|
|
|
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.DebugWriteLine("Extract-Files command", UI.Image_has_0_sectors, imageFormat.Info.Sectors);
|
2016-07-27 02:35:29 +01:00
|
|
|
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.DebugWriteLine("Extract-Files command", UI.Image_identifies_disk_type_as_0,
|
2021-11-14 03:52:44 +00:00
|
|
|
imageFormat.Info.MediaType);
|
2021-09-13 19:53:32 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
Statistics.AddMediaFormat(imageFormat.Format);
|
|
|
|
|
Statistics.AddMedia(imageFormat.Info.MediaType, false);
|
|
|
|
|
Statistics.AddFilter(inputFilter.Name);
|
|
|
|
|
}
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.ErrorWriteLine(UI.Unable_to_open_image_format);
|
2022-11-23 16:06:46 +00:00
|
|
|
AaruConsole.ErrorWriteLine(Localization.Core.Error_0, ex.Message);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
return (int)ErrorNumber.CannotOpenFormat;
|
|
|
|
|
}
|
2016-07-27 02:35:29 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
List<Partition> partitions = null;
|
2020-01-02 04:09:39 +00:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
Core.Spectre.ProgressSingleSpinner(ctx =>
|
2021-11-14 03:52:44 +00:00
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
ctx.AddTask(UI.Enumerating_partitions).IsIndeterminate();
|
2022-11-15 15:58:43 +00:00
|
|
|
partitions = Core.Partitions.GetAll(imageFormat);
|
2021-11-14 03:52:44 +00:00
|
|
|
});
|
2020-01-02 04:09:39 +00:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
Core.Partitions.AddSchemesToStats(partitions);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
if(partitions.Count == 0)
|
|
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.DebugWriteLine("Ls command", UI.No_partitions_found);
|
2016-07-27 02:35:29 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
partitions.Add(new Partition
|
2016-07-27 02:35:29 +01:00
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
Description = Localization.Core.Whole_device,
|
2021-11-14 03:52:44 +00:00
|
|
|
Length = imageFormat.Info.Sectors,
|
|
|
|
|
Offset = 0,
|
|
|
|
|
Size = imageFormat.Info.SectorSize * imageFormat.Info.Sectors,
|
|
|
|
|
Sequence = 1,
|
|
|
|
|
Start = 0
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-01-02 04:09:39 +00:00
|
|
|
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.WriteLine(UI._0_partitions_found, partitions.Count);
|
2021-11-14 03:52:44 +00:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
for(int i = 0; i < partitions.Count; i++)
|
2021-11-14 03:52:44 +00:00
|
|
|
{
|
|
|
|
|
AaruConsole.WriteLine();
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.WriteLine($"[bold]{string.Format(UI.Partition_0, partitions[i].Sequence)}[/]");
|
2016-07-27 02:35:29 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
List<string> idPlugins = null;
|
2021-09-13 19:53:32 +01:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
Core.Spectre.ProgressSingleSpinner(ctx =>
|
2021-09-13 19:53:32 +01:00
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
ctx.AddTask(UI.Identifying_filesystems_on_partition).IsIndeterminate();
|
2022-11-15 15:58:43 +00:00
|
|
|
Core.Filesystems.Identify(imageFormat, out idPlugins, partitions[i]);
|
2021-09-13 19:53:32 +01:00
|
|
|
});
|
|
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
if(idPlugins.Count == 0)
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.WriteLine(UI.Filesystem_not_identified);
|
2021-11-14 03:52:44 +00:00
|
|
|
else
|
2020-03-22 18:53:24 +00:00
|
|
|
{
|
2022-12-17 14:56:37 +00:00
|
|
|
Type pluginType;
|
|
|
|
|
ErrorNumber error = ErrorNumber.InvalidArgument;
|
2020-01-02 04:09:39 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
if(idPlugins.Count > 1)
|
2021-09-13 19:53:32 +01:00
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.WriteLine($"[italic]{string.Format(UI.Identified_by_0_plugins, idPlugins.Count)
|
|
|
|
|
}[/]");
|
2016-07-27 02:35:29 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
foreach(string pluginName in idPlugins)
|
2022-12-17 14:56:37 +00:00
|
|
|
if(plugins.ReadOnlyFilesystems.TryGetValue(pluginName, out pluginType))
|
2021-11-14 03:52:44 +00:00
|
|
|
{
|
2022-12-17 14:56:37 +00:00
|
|
|
AaruConsole.WriteLine($"[bold]{string.Format(UI.As_identified_by_0, pluginType.Name)
|
|
|
|
|
}[/]");
|
2020-03-22 18:53:24 +00:00
|
|
|
|
2022-12-17 14:56:37 +00:00
|
|
|
if(Activator.CreateInstance(pluginType) is not IReadOnlyFilesystem fs)
|
2022-03-17 00:46:26 +00:00
|
|
|
continue;
|
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
Core.Spectre.ProgressSingleSpinner(ctx =>
|
2020-07-22 13:20:25 +01:00
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
ctx.AddTask(UI.Mounting_filesystem).IsIndeterminate();
|
2020-03-22 18:53:24 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
error = fs.Mount(imageFormat, partitions[i], encodingClass, parsedOptions,
|
|
|
|
|
@namespace);
|
|
|
|
|
});
|
2020-07-22 13:20:25 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
if(error == ErrorNumber.NoError)
|
|
|
|
|
{
|
2022-12-15 22:21:07 +00:00
|
|
|
string volumeName = string.IsNullOrEmpty(fs.Metadata.VolumeName) ? "NO NAME"
|
|
|
|
|
: fs.Metadata.VolumeName;
|
2017-12-07 02:30:54 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
ExtractFilesInDir("/", fs, volumeName, outputDir, xattrs);
|
2016-07-27 02:35:29 +01:00
|
|
|
|
2022-12-15 22:21:07 +00:00
|
|
|
Statistics.AddFilesystem(fs.Metadata.Type);
|
2016-07-27 02:35:29 +01:00
|
|
|
}
|
2021-11-14 03:52:44 +00:00
|
|
|
else
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.ErrorWriteLine(UI.Unable_to_mount_volume_error_0, error.ToString());
|
2021-11-14 03:52:44 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2022-12-17 14:56:37 +00:00
|
|
|
plugins.ReadOnlyFilesystems.TryGetValue(idPlugins[0], out pluginType);
|
2020-03-09 21:11:52 +00:00
|
|
|
|
2022-12-17 14:56:37 +00:00
|
|
|
if(pluginType == null ||
|
|
|
|
|
Activator.CreateInstance(pluginType) is not IReadOnlyFilesystem fs)
|
2021-11-14 03:52:44 +00:00
|
|
|
continue;
|
2020-03-09 21:11:52 +00:00
|
|
|
|
2022-12-17 14:56:37 +00:00
|
|
|
AaruConsole.WriteLine($"[bold]{string.Format(UI.Identified_by_0, pluginType.Name)}[/]");
|
2022-03-17 00:46:26 +00:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
Core.Spectre.ProgressSingleSpinner(ctx =>
|
2021-11-14 03:52:44 +00:00
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
ctx.AddTask(UI.Mounting_filesystem).IsIndeterminate();
|
2021-11-14 03:52:44 +00:00
|
|
|
error = fs.Mount(imageFormat, partitions[i], encodingClass, parsedOptions, @namespace);
|
|
|
|
|
});
|
2020-01-02 04:09:39 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
if(error == ErrorNumber.NoError)
|
|
|
|
|
{
|
2022-12-15 22:21:07 +00:00
|
|
|
string volumeName = string.IsNullOrEmpty(fs.Metadata.VolumeName) ? "NO NAME"
|
|
|
|
|
: fs.Metadata.VolumeName;
|
2017-12-07 02:30:54 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
ExtractFilesInDir("/", fs, volumeName, outputDir, xattrs);
|
2016-07-27 02:35:29 +01:00
|
|
|
|
2022-12-15 22:21:07 +00:00
|
|
|
Statistics.AddFilesystem(fs.Metadata.Type);
|
2016-07-27 02:35:29 +01:00
|
|
|
}
|
2021-11-14 03:52:44 +00:00
|
|
|
else
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.ErrorWriteLine(UI.Unable_to_mount_volume_error_0, error.ToString());
|
2016-07-27 02:35:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-14 12:23:40 +01:00
|
|
|
}
|
2021-11-14 03:52:44 +00:00
|
|
|
}
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.ErrorWriteLine(string.Format(UI.Error_reading_file_0, ex.Message));
|
2021-11-14 03:52:44 +00:00
|
|
|
AaruConsole.DebugWriteLine("Extract-Files command", ex.StackTrace);
|
2019-04-14 12:23:40 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
return (int)ErrorNumber.UnexpectedException;
|
2019-04-14 12:23:40 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
return (int)ErrorNumber.NoError;
|
|
|
|
|
}
|
2019-04-14 13:03:45 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
static void ExtractFilesInDir(string path, [NotNull] IReadOnlyFilesystem fs, string volumeName, string outputDir,
|
|
|
|
|
bool doXattrs)
|
|
|
|
|
{
|
|
|
|
|
if(path.StartsWith('/'))
|
2022-11-15 01:35:06 +00:00
|
|
|
path = path[1..];
|
2020-01-02 04:09:39 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
ErrorNumber error = fs.ReadDir(path, out List<string> directory);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
if(error != ErrorNumber.NoError)
|
|
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.ErrorWriteLine(UI.Error_0_reading_directory_1, error.ToString(), path);
|
2019-04-14 12:23:40 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach(string entry in directory)
|
|
|
|
|
{
|
|
|
|
|
FileEntryInfo stat = new();
|
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
Core.Spectre.ProgressSingleSpinner(ctx =>
|
2019-04-14 12:23:40 +01:00
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
ctx.AddTask(UI.Retrieving_file_information).IsIndeterminate();
|
2021-11-14 03:52:44 +00:00
|
|
|
error = fs.Stat(path + "/" + entry, out stat);
|
|
|
|
|
});
|
2021-09-13 19:53:32 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
if(error == ErrorNumber.NoError)
|
|
|
|
|
{
|
|
|
|
|
string outputPath;
|
2020-01-02 04:09:39 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
if(stat.Attributes.HasFlag(FileAttributes.Directory))
|
2019-04-14 12:23:40 +01:00
|
|
|
{
|
2022-12-15 22:21:07 +00:00
|
|
|
outputPath = Path.Combine(outputDir, fs.Metadata.Type, volumeName, path, entry);
|
2019-04-14 13:03:45 +01:00
|
|
|
|
2022-05-20 19:39:08 +01:00
|
|
|
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
|
|
outputPath = outputPath.Replace('<', '\uFF1C').Replace('>', '\uFF1E').Replace(':', '\uFF1A').
|
|
|
|
|
Replace('\"', '\uFF02').Replace('|', '\uFF5C').Replace('?', '\uFF1F').
|
|
|
|
|
Replace('*', '\uFF0A').Replace('/', '\\');
|
|
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
Directory.CreateDirectory(outputPath);
|
2019-04-14 13:03:45 +01:00
|
|
|
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.WriteLine(UI.Created_subdirectory_at_0, Markup.Escape(outputPath));
|
2019-04-14 13:03:45 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
ExtractFilesInDir(path + "/" + entry, fs, volumeName, outputDir, doXattrs);
|
2019-04-14 13:03:45 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
var di = new DirectoryInfo(outputPath);
|
2019-04-14 13:03:45 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if(stat.CreationTimeUtc.HasValue)
|
|
|
|
|
di.CreationTimeUtc = stat.CreationTimeUtc.Value;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
2019-04-14 13:03:45 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if(stat.LastWriteTimeUtc.HasValue)
|
|
|
|
|
di.LastWriteTimeUtc = stat.LastWriteTimeUtc.Value;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
2019-04-14 13:03:45 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if(stat.AccessTimeUtc.HasValue)
|
|
|
|
|
di.LastAccessTimeUtc = stat.AccessTimeUtc.Value;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
|
|
|
|
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
|
2019-04-14 13:03:45 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
continue;
|
|
|
|
|
}
|
2019-04-14 13:03:45 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
FileStream outputFile;
|
2019-04-14 13:03:45 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
if(doXattrs)
|
|
|
|
|
{
|
|
|
|
|
List<string> xattrs = null;
|
2020-01-02 04:09:39 +00:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
Core.Spectre.ProgressSingleSpinner(ctx =>
|
2019-04-14 12:23:40 +01:00
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
ctx.AddTask(UI.Listing_extended_attributes).IsIndeterminate();
|
2021-11-14 03:52:44 +00:00
|
|
|
error = fs.ListXAttr(path + "/" + entry, out xattrs);
|
|
|
|
|
});
|
2021-09-13 19:53:32 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
if(error == ErrorNumber.NoError)
|
|
|
|
|
foreach(string xattr in xattrs)
|
2021-09-13 19:53:32 +01:00
|
|
|
{
|
2021-11-14 03:52:44 +00:00
|
|
|
byte[] xattrBuf = Array.Empty<byte>();
|
2020-01-02 04:09:39 +00:00
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
Core.Spectre.ProgressSingleSpinner(ctx =>
|
2016-07-27 02:35:29 +01:00
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
ctx.AddTask(UI.Reading_extended_attribute).IsIndeterminate();
|
2021-11-14 03:52:44 +00:00
|
|
|
error = fs.GetXattr(path + "/" + entry, xattr, ref xattrBuf);
|
|
|
|
|
});
|
2020-01-02 04:09:39 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
if(error != ErrorNumber.NoError)
|
|
|
|
|
continue;
|
2016-08-26 01:43:15 +01:00
|
|
|
|
2022-12-15 22:21:07 +00:00
|
|
|
outputPath = Path.Combine(outputDir, fs.Metadata.Type, volumeName, ".xattrs", path, xattr);
|
2021-06-22 19:40:35 +01:00
|
|
|
|
2022-05-20 19:39:08 +01:00
|
|
|
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
|
|
outputPath = outputPath.Replace('<', '\uFF1C').Replace('>', '\uFF1E').
|
|
|
|
|
Replace(':', '\uFF1A').Replace('\"', '\uFF02').
|
|
|
|
|
Replace('|', '\uFF5C').Replace('?', '\uFF1F').
|
|
|
|
|
Replace('*', '\uFF0A').Replace('/', '\\');
|
|
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
Directory.CreateDirectory(outputPath);
|
2019-04-14 12:23:40 +01:00
|
|
|
|
2022-05-20 19:39:08 +01:00
|
|
|
outputPath = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|
|
|
|
|
? Path.Combine(outputPath,
|
|
|
|
|
entry.Replace('/', '\uFF0F').Replace('\\', '\uFF3C'))
|
|
|
|
|
: Path.Combine(outputPath, entry);
|
|
|
|
|
|
|
|
|
|
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
|
|
outputPath = outputPath.Replace('<', '\uFF1C').Replace('>', '\uFF1E').
|
|
|
|
|
Replace(':', '\uFF1A').Replace('\"', '\uFF02').
|
|
|
|
|
Replace('|', '\uFF5C').Replace('?', '\uFF1F').
|
|
|
|
|
Replace('*', '\uFF0A').Replace('/', '\\');
|
2019-04-14 12:23:40 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
if(!File.Exists(outputPath))
|
|
|
|
|
{
|
2022-11-15 15:58:43 +00:00
|
|
|
Core.Spectre.ProgressSingleSpinner(ctx =>
|
2016-07-27 02:35:29 +01:00
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
ctx.AddTask(UI.Writing_extended_attribute).IsIndeterminate();
|
2021-09-13 19:53:32 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
outputFile = new FileStream(outputPath, FileMode.CreateNew, FileAccess.ReadWrite,
|
|
|
|
|
FileShare.None);
|
2021-09-13 19:53:32 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
outputFile.Write(xattrBuf, 0, xattrBuf.Length);
|
|
|
|
|
outputFile.Close();
|
|
|
|
|
});
|
2020-01-02 04:09:39 +00:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
var fi = new FileInfo(outputPath);
|
|
|
|
|
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if(stat.CreationTimeUtc.HasValue)
|
|
|
|
|
fi.CreationTimeUtc = stat.CreationTimeUtc.Value;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
2016-07-27 02:35:29 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if(stat.LastWriteTimeUtc.HasValue)
|
|
|
|
|
fi.LastWriteTimeUtc = stat.LastWriteTimeUtc.Value;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
2016-07-27 02:35:29 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if(stat.AccessTimeUtc.HasValue)
|
|
|
|
|
fi.LastAccessTimeUtc = stat.AccessTimeUtc.Value;
|
2016-07-27 02:35:29 +01:00
|
|
|
}
|
2021-11-14 03:52:44 +00:00
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
|
|
|
|
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.WriteLine(UI.Written_0_bytes_of_xattr_1_from_file_2_to_3, xattrBuf.Length,
|
|
|
|
|
xattr, entry, outputPath);
|
2016-07-27 02:35:29 +01:00
|
|
|
}
|
2021-11-14 03:52:44 +00:00
|
|
|
else
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.ErrorWriteLine(UI.Cannot_write_xattr_0_for_1_output_exists, xattr, entry);
|
2021-11-14 03:52:44 +00:00
|
|
|
}
|
|
|
|
|
}
|
2021-06-22 19:40:35 +01:00
|
|
|
|
2022-12-15 22:21:07 +00:00
|
|
|
outputPath = Path.Combine(outputDir, fs.Metadata.Type, volumeName, path);
|
2019-04-14 12:23:40 +01:00
|
|
|
|
2022-05-20 19:39:08 +01:00
|
|
|
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
|
|
outputPath = outputPath.Replace('<', '\uFF1C').Replace('>', '\uFF1E').Replace(':', '\uFF1A').
|
|
|
|
|
Replace('\"', '\uFF02').Replace('|', '\uFF5C').Replace('?', '\uFF1F').
|
|
|
|
|
Replace('*', '\uFF0A').Replace('/', '\\');
|
|
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
Directory.CreateDirectory(outputPath);
|
2019-04-14 12:23:40 +01:00
|
|
|
|
2022-05-20 19:39:08 +01:00
|
|
|
outputPath = RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
|
|
|
|
|
? Path.Combine(outputPath, entry.Replace('/', '\uFF0F').Replace('\\', '\uFF3C'))
|
|
|
|
|
: Path.Combine(outputPath, entry);
|
|
|
|
|
|
|
|
|
|
if(RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
|
|
outputPath = outputPath.Replace('<', '\uFF1C').Replace('>', '\uFF1E').Replace(':', '\uFF1A').
|
|
|
|
|
Replace('\"', '\uFF02').Replace('|', '\uFF5C').Replace('?', '\uFF1F').
|
|
|
|
|
Replace('*', '\uFF0A').Replace('/', '\\');
|
2019-04-14 12:23:40 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
if(!File.Exists(outputPath))
|
|
|
|
|
{
|
|
|
|
|
long position = 0;
|
2019-04-14 12:23:40 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
outputFile = new FileStream(outputPath, FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None);
|
2021-09-13 19:53:32 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
AnsiConsole.Progress().AutoClear(true).HideCompleted(true).
|
|
|
|
|
Columns(new TaskDescriptionColumn(), new ProgressBarColumn(), new PercentageColumn()).
|
|
|
|
|
Start(ctx =>
|
|
|
|
|
{
|
2022-11-18 11:18:45 +00:00
|
|
|
ProgressTask task =
|
|
|
|
|
ctx.AddTask(string.Format(UI.Reading_file_0, Markup.Escape(entry)));
|
2021-09-13 19:53:32 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
task.MaxValue = stat.Length;
|
2022-12-19 11:03:51 +00:00
|
|
|
byte[] outBuf = new byte[BUFFER_SIZE];
|
|
|
|
|
error = fs.OpenFile(path + "/" + entry, out IFileNode fileNode);
|
2020-01-02 04:09:39 +00:00
|
|
|
|
2022-12-19 11:03:51 +00:00
|
|
|
if(error == ErrorNumber.NoError)
|
2021-11-14 03:52:44 +00:00
|
|
|
{
|
2022-12-19 11:03:51 +00:00
|
|
|
while(position < stat.Length)
|
|
|
|
|
{
|
|
|
|
|
long bytesToRead;
|
2019-04-14 12:23:40 +01:00
|
|
|
|
2022-12-19 11:03:51 +00:00
|
|
|
if(stat.Length - position > BUFFER_SIZE)
|
|
|
|
|
bytesToRead = BUFFER_SIZE;
|
|
|
|
|
else
|
|
|
|
|
bytesToRead = stat.Length - position;
|
2019-04-14 12:23:40 +01:00
|
|
|
|
2022-12-19 11:03:51 +00:00
|
|
|
error = fs.ReadFile(fileNode, bytesToRead, outBuf, out long bytesRead);
|
2021-09-13 20:31:32 +01:00
|
|
|
|
2022-12-19 11:03:51 +00:00
|
|
|
if(error == ErrorNumber.NoError)
|
|
|
|
|
outputFile.Write(outBuf, 0, (int)bytesRead);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
AaruConsole.ErrorWriteLine(UI.Error_0_reading_file_1, error, entry);
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-09-13 20:31:32 +01:00
|
|
|
|
2022-12-19 11:03:51 +00:00
|
|
|
position += bytesToRead;
|
|
|
|
|
task.Increment(bytesToRead);
|
2021-09-13 20:31:32 +01:00
|
|
|
}
|
|
|
|
|
|
2022-12-19 11:03:51 +00:00
|
|
|
fs.CloseFile(fileNode);
|
2021-11-14 03:52:44 +00:00
|
|
|
}
|
2022-12-19 11:03:51 +00:00
|
|
|
else
|
|
|
|
|
AaruConsole.ErrorWriteLine(UI.Error_0_reading_file_1, error, entry);
|
2021-11-14 03:52:44 +00:00
|
|
|
});
|
2021-09-13 20:31:32 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
outputFile.Close();
|
2021-09-13 20:31:32 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
var fi = new FileInfo(outputPath);
|
|
|
|
|
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if(stat.CreationTimeUtc.HasValue)
|
|
|
|
|
fi.CreationTimeUtc = stat.CreationTimeUtc.Value;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
2021-09-13 20:31:32 +01:00
|
|
|
|
2021-11-14 03:52:44 +00:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if(stat.LastWriteTimeUtc.HasValue)
|
|
|
|
|
fi.LastWriteTimeUtc = stat.LastWriteTimeUtc.Value;
|
2016-07-27 02:35:29 +01:00
|
|
|
}
|
2021-11-14 03:52:44 +00:00
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if(stat.AccessTimeUtc.HasValue)
|
|
|
|
|
fi.LastAccessTimeUtc = stat.AccessTimeUtc.Value;
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// ignored
|
|
|
|
|
}
|
|
|
|
|
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.WriteLine(UI.Written_0_bytes_of_file_1_to_2, position, Markup.Escape(entry),
|
2021-11-14 03:52:44 +00:00
|
|
|
Markup.Escape(outputPath));
|
2016-07-27 02:35:29 +01:00
|
|
|
}
|
2020-01-02 04:09:39 +00:00
|
|
|
else
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.ErrorWriteLine(UI.Cannot_write_file_0_output_exists, Markup.Escape(entry));
|
2016-07-27 02:35:29 +01:00
|
|
|
}
|
2021-11-14 03:52:44 +00:00
|
|
|
else
|
2022-11-18 11:18:45 +00:00
|
|
|
AaruConsole.ErrorWriteLine(UI.Error_reading_file_0, Markup.Escape(entry));
|
2016-07-27 02:35:29 +01:00
|
|
|
}
|
|
|
|
|
}
|
2020-01-02 04:09:39 +00:00
|
|
|
}
|