From a67cc4ead7448d0b99184f2fa110c56aff97779a Mon Sep 17 00:00:00 2001 From: Mathias Tillman Date: Thu, 16 Jan 2020 11:21:21 +0100 Subject: [PATCH] Allow specifying subscription index for more commands. --- .../EfsDowloadDirectoryOptions.cs | 3 ++ .../CommandLineOptions/EfsReadFileOptions.cs | 3 ++ .../EfsUploadDirectoryOptions.cs | 3 ++ .../CommandLineOptions/EfsWriteFileOptions.cs | 3 ++ EfsTools/EfsTools.cs | 16 ++++---- EfsTools/Program.cs | 8 ++-- EfsTools/Utils/FileUtils.cs | 38 ++++++++++++------- 7 files changed, 48 insertions(+), 26 deletions(-) diff --git a/EfsTools/CommandLineOptions/EfsDowloadDirectoryOptions.cs b/EfsTools/CommandLineOptions/EfsDowloadDirectoryOptions.cs index bccf8dacb..1931ad2de 100644 --- a/EfsTools/CommandLineOptions/EfsDowloadDirectoryOptions.cs +++ b/EfsTools/CommandLineOptions/EfsDowloadDirectoryOptions.cs @@ -26,5 +26,8 @@ public string OutComputerPath [Option('v', "processNvItems", Required = false, HelpText = "Process NV items", Default = false)] public bool ProcessNvItems { get; set; } + + [Option('s', "subscriptionIndex", Required = false, HelpText = "Subscription index. 0 - first SIM, 1 - second SIM", Default = 0)] + public int SubscriptionIndex { get; set; } } } \ No newline at end of file diff --git a/EfsTools/CommandLineOptions/EfsReadFileOptions.cs b/EfsTools/CommandLineOptions/EfsReadFileOptions.cs index b7d7e9037..c434f8bf7 100644 --- a/EfsTools/CommandLineOptions/EfsReadFileOptions.cs +++ b/EfsTools/CommandLineOptions/EfsReadFileOptions.cs @@ -20,5 +20,8 @@ public string OutComputerFilePath } private Layout _outComputerFilePathLayout; + + [Option('s', "subscriptionIndex", Required = false, HelpText = "Subscription index. 0 - first SIM, 1 - second SIM", Default = 0)] + public int SubscriptionIndex { get; set; } } } \ No newline at end of file diff --git a/EfsTools/CommandLineOptions/EfsUploadDirectoryOptions.cs b/EfsTools/CommandLineOptions/EfsUploadDirectoryOptions.cs index 6f6ba84c8..c1f73535f 100644 --- a/EfsTools/CommandLineOptions/EfsUploadDirectoryOptions.cs +++ b/EfsTools/CommandLineOptions/EfsUploadDirectoryOptions.cs @@ -27,5 +27,8 @@ public string InComputerPath [Option('v', "processNvItems", Required = false, HelpText = "Process NV items", Default = false)] public bool ProcessNvItems { get; set; } + + [Option('s', "subscriptionIndex", Required = false, HelpText = "Subscription index. 0 - first SIM, 1 - second SIM", Default = 0)] + public int SubscriptionIndex { get; set; } } } \ No newline at end of file diff --git a/EfsTools/CommandLineOptions/EfsWriteFileOptions.cs b/EfsTools/CommandLineOptions/EfsWriteFileOptions.cs index 63c97c2b3..6d0001b94 100644 --- a/EfsTools/CommandLineOptions/EfsWriteFileOptions.cs +++ b/EfsTools/CommandLineOptions/EfsWriteFileOptions.cs @@ -27,5 +27,8 @@ public string InComputerFilePath [Option('t', "item", Required = false, HelpText = "Create Item file", Default = false)] public bool IsItemFile { get; set; } + + [Option('s', "subscriptionIndex", Required = false, HelpText = "Subscription index. 0 - first SIM, 1 - second SIM", Default = 0)] + public int SubscriptionIndex { get; set; } } } \ No newline at end of file diff --git a/EfsTools/EfsTools.cs b/EfsTools/EfsTools.cs index 006a3a1e4..fe69eb479 100644 --- a/EfsTools/EfsTools.cs +++ b/EfsTools/EfsTools.cs @@ -160,21 +160,21 @@ public void GetEfsInfo() } } - public void EfsReadFile(string efsPath, string computerPath) + public void EfsReadFile(string efsPath, string computerPath, int subscription) { if (!string.IsNullOrEmpty(efsPath)) using (var manager = OpenQcdmManager()) { - FileUtils.PhoneReadFile(manager, efsPath, computerPath, _logger); + FileUtils.PhoneReadFile(manager, efsPath, computerPath, subscription, _logger); } } - public void EfsWriteFile(string computerPath, string efsPath, bool create, bool itemFile) + public void EfsWriteFile(string computerPath, string efsPath, bool create, bool itemFile, int subscription) { if (!string.IsNullOrEmpty(efsPath) && !string.IsNullOrEmpty(computerPath)) using (var manager = OpenQcdmManager()) { - FileUtils.PhoneWriteFile(manager, computerPath, efsPath, 0777, itemFile, _logger); + FileUtils.PhoneWriteFile(manager, computerPath, efsPath, 0777, itemFile, subscription, _logger); } } @@ -189,20 +189,20 @@ public void EfsRenameFile(string efsPath, string newEfsPath) } } - public void EfsDownloadDirectory(string efsPath, string computerPath, bool noExtraData, bool processNvItems) + public void EfsDownloadDirectory(string efsPath, string computerPath, bool noExtraData, bool processNvItems, int subscription) { if (!string.IsNullOrEmpty(efsPath) && !string.IsNullOrEmpty(computerPath)) using (var manager = OpenQcdmManager()) { var path1 = PathUtils.FixUnixPath(efsPath); var path2 = PathUtils.FixPath(computerPath); - FileUtils.PhoneDownloadDirectory(manager, path1, path2, noExtraData, _logger); + FileUtils.PhoneDownloadDirectory(manager, path1, path2, noExtraData, subscription, _logger); if (processNvItems) NvItemUtils.PhoneDownloadNvItems(manager, path2, _logger); } } public void EfsUploadDirectory(string computerPath, string efsPath, bool createItemFilesAsDefault, - bool processNvItems) + bool processNvItems, int subscription) { if (!string.IsNullOrEmpty(efsPath) && !string.IsNullOrEmpty(computerPath)) { @@ -214,7 +214,7 @@ public void EfsUploadDirectory(string computerPath, string efsPath, bool createI using (var manager = OpenQcdmManager()) { var path2 = PathUtils.FixUnixPath(efsPath); - FileUtils.PhoneUploadDirectory(manager, path1, path2, createItemFilesAsDefault, _logger); + FileUtils.PhoneUploadDirectory(manager, path1, path2, createItemFilesAsDefault, subscription, _logger); if (processNvItems) NvItemUtils.PhoneUploadNvItems(manager, path1, _logger); } } diff --git a/EfsTools/Program.cs b/EfsTools/Program.cs index e03b7b23c..6780422ce 100644 --- a/EfsTools/Program.cs +++ b/EfsTools/Program.cs @@ -48,17 +48,17 @@ private static void Main(string[] args) .WithParsed(opts => tools.GetTargetInfo()) .WithParsed(opts => tools.GetEfsInfo()) .WithParsed(opts => - tools.EfsReadFile(opts.InEfsFilePath, opts.OutComputerFilePath)) + tools.EfsReadFile(opts.InEfsFilePath, opts.OutComputerFilePath, opts.SubscriptionIndex)) .WithParsed(opts => tools.EfsWriteFile(opts.InComputerFilePath, opts.OutEfsFilePath, !opts.DontCreateEfsFile, - opts.IsItemFile)) + opts.IsItemFile, opts.SubscriptionIndex)) .WithParsed(opts => tools.EfsRenameFile(opts.EfsFilePath, opts.NewEfsFilePath)) .WithParsed(opts => tools.EfsDownloadDirectory(opts.InEfsPath, opts.OutComputerPath, opts.NoExtraData, - opts.ProcessNvItems)) + opts.ProcessNvItems, opts.SubscriptionIndex)) .WithParsed(opts => tools.EfsUploadDirectory(opts.InComputerPath, - opts.OutEfsPath, opts.CreateItemFilesAsDefault, opts.ProcessNvItems)) + opts.OutEfsPath, opts.CreateItemFilesAsDefault, opts.ProcessNvItems, opts.SubscriptionIndex)) .WithParsed(opts => tools.EfsFixFileNames(opts.EfsPath)) .WithParsed(opts => tools.EfsCreateDirectory(opts.Path, !opts.NoRecursive)) diff --git a/EfsTools/Utils/FileUtils.cs b/EfsTools/Utils/FileUtils.cs index bc308acbd..f5ada2317 100644 --- a/EfsTools/Utils/FileUtils.cs +++ b/EfsTools/Utils/FileUtils.cs @@ -254,7 +254,7 @@ public static void PhoneListDirectory(QcdmManager manager, string path, bool rec } public static void PhoneDownloadDirectory(QcdmManager manager, string efsPath, string computerPath, - bool noExtraData, Logger logger) + bool noExtraData, int subscription, Logger logger) { try { @@ -268,13 +268,13 @@ public static void PhoneDownloadDirectory(QcdmManager manager, string efsPath, s { var path = $"{efsPath}{entry.Name}/"; var newComputerPath = $"{computerPath}{entry.Name}/"; - PhoneDownloadDirectory(manager, path, newComputerPath, noExtraData, logger); + PhoneDownloadDirectory(manager, path, newComputerPath, noExtraData, subscription, logger); continue; } if (entry.EntryType == DirectoryEntryType.File || entry.EntryType == DirectoryEntryType.ItemFile) - PhoneDownloadFile(manager, entry, efsPath, computerPath, noExtraData, logger); + PhoneDownloadFile(manager, entry, efsPath, computerPath, noExtraData, subscription, logger); } } } @@ -285,7 +285,7 @@ public static void PhoneDownloadDirectory(QcdmManager manager, string efsPath, s } public static void PhoneUploadDirectory(QcdmManager manager, string computerPath, string efsPath, - bool createItemFilesAsDefault, Logger logger) + bool createItemFilesAsDefault, int subscription, Logger logger) { try { @@ -298,7 +298,7 @@ public static void PhoneUploadDirectory(QcdmManager manager, string computerPath { var name = Path.GetFileName(directory); var path = $"{efsPath}{name}/"; - PhoneUploadDirectory(manager, directory, path, createItemFilesAsDefault, logger); + PhoneUploadDirectory(manager, directory, path, createItemFilesAsDefault, subscription, logger); } foreach (var file in files) @@ -306,7 +306,7 @@ public static void PhoneUploadDirectory(QcdmManager manager, string computerPath { var fileName = Path.GetFileName(file); var path = PathUtils.RemoveExtraData(fileName, efsPath); - PhoneUploadFile(manager, file, path, createItemFilesAsDefault, logger); + PhoneUploadFile(manager, file, path, createItemFilesAsDefault, subscription, logger); } } catch (Exception e) @@ -315,10 +315,12 @@ public static void PhoneUploadDirectory(QcdmManager manager, string computerPath } } - public static void PhoneReadFile(QcdmManager manager, string efsPath, string computerPath, Logger logger) + public static void PhoneReadFile(QcdmManager manager, string efsPath, string computerPath, int subscription, Logger logger) { if (!string.IsNullOrEmpty(efsPath)) - using (var input = PhoneOpenRead(manager, efsPath)) + { + string efsPathSub = PathUtils.GetEfsFilePath(efsPath, subscription); + using (var input = PhoneOpenRead(manager, efsPathSub)) { using (var output = string.IsNullOrEmpty(computerPath) ? StreamUtils.CreateLoggerStream(logger) @@ -331,17 +333,19 @@ public static void PhoneReadFile(QcdmManager manager, string efsPath, string com input.Close(); } + } } public static void PhoneWriteFile(QcdmManager manager, string computerPath, string efsPath, int permission, - bool itemFile, Logger logger) + bool itemFile, int subscription, Logger logger) { if (!string.IsNullOrEmpty(efsPath) && !string.IsNullOrEmpty(computerPath)) using (var input = LocalOpenRead(computerPath)) { + string efsPathSub = PathUtils.GetEfsFilePath(efsPath, subscription); using (var output = itemFile - ? PhoneItemCreateWrite(manager, efsPath, permission, logger) - : PhoneCreateWrite(manager, efsPath, permission, logger)) + ? PhoneItemCreateWrite(manager, efsPathSub, permission, logger) + : PhoneCreateWrite(manager, efsPathSub, permission, logger)) { StreamUtils.Copy(input, output); output.Flush(); @@ -353,14 +357,14 @@ public static void PhoneWriteFile(QcdmManager manager, string computerPath, stri } private static void PhoneDownloadFile(QcdmManager manager, DirectoryEntry entry, string efsPath, - string computerPath, bool noExtraData, Logger logger) + string computerPath, bool noExtraData, int subscription, Logger logger) { try { var entryName = entry.Name; var path1 = $"{efsPath}{entryName}"; var path2 = PathUtils.BuildPath(computerPath, entryName, entry.Mode, entry.EntryType, noExtraData); - PhoneReadFile(manager, path1, path2, logger); + PhoneReadFile(manager, path1, path2, subscription, logger); } catch (Exception e) { @@ -370,6 +374,12 @@ private static void PhoneDownloadFile(QcdmManager manager, DirectoryEntry entry, private static void PhoneUploadFile(QcdmManager manager, string computerPath, string efsPath, bool createItemFilesAsDefault, Logger logger) + { + PhoneUploadFile(manager, computerPath, efsPath, createItemFilesAsDefault, 0, logger); + } + + private static void PhoneUploadFile(QcdmManager manager, string computerPath, string efsPath, + bool createItemFilesAsDefault, int subscription, Logger logger) { try { @@ -395,7 +405,7 @@ private static void PhoneUploadFile(QcdmManager manager, string computerPath, st } } - PhoneWriteFile(manager, computerPath, efsPath, permission, isItemFile, logger); + PhoneWriteFile(manager, computerPath, efsPath, permission, isItemFile, subscription, logger); } } catch (Exception e)