Skip to content

Commit

Permalink
Allow specifying subscription index for more commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
HomerSp committed Jan 16, 2020
1 parent 71c1cc8 commit a67cc4e
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 26 deletions.
3 changes: 3 additions & 0 deletions EfsTools/CommandLineOptions/EfsDowloadDirectoryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
3 changes: 3 additions & 0 deletions EfsTools/CommandLineOptions/EfsReadFileOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
3 changes: 3 additions & 0 deletions EfsTools/CommandLineOptions/EfsUploadDirectoryOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
3 changes: 3 additions & 0 deletions EfsTools/CommandLineOptions/EfsWriteFileOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
16 changes: 8 additions & 8 deletions EfsTools/EfsTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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))
{
Expand All @@ -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);
}
}
Expand Down
8 changes: 4 additions & 4 deletions EfsTools/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ private static void Main(string[] args)
.WithParsed<GetTaggetInfoOptions>(opts => tools.GetTargetInfo())
.WithParsed<GetEfsInfoOptions>(opts => tools.GetEfsInfo())
.WithParsed<EfsReadFileOptions>(opts =>
tools.EfsReadFile(opts.InEfsFilePath, opts.OutComputerFilePath))
tools.EfsReadFile(opts.InEfsFilePath, opts.OutComputerFilePath, opts.SubscriptionIndex))
.WithParsed<EfsWriteFileOptions>(opts => tools.EfsWriteFile(opts.InComputerFilePath,
opts.OutEfsFilePath, !opts.DontCreateEfsFile,
opts.IsItemFile))
opts.IsItemFile, opts.SubscriptionIndex))
.WithParsed<EfsRenameFileOptions>(opts =>
tools.EfsRenameFile(opts.EfsFilePath, opts.NewEfsFilePath))
.WithParsed<EfsDowloadDirectoryOptions>(opts =>
tools.EfsDownloadDirectory(opts.InEfsPath, opts.OutComputerPath, opts.NoExtraData,
opts.ProcessNvItems))
opts.ProcessNvItems, opts.SubscriptionIndex))
.WithParsed<EfsUploadDirectoryOptions>(opts => tools.EfsUploadDirectory(opts.InComputerPath,
opts.OutEfsPath, opts.CreateItemFilesAsDefault, opts.ProcessNvItems))
opts.OutEfsPath, opts.CreateItemFilesAsDefault, opts.ProcessNvItems, opts.SubscriptionIndex))
.WithParsed<EfsFixFileNamesOptions>(opts => tools.EfsFixFileNames(opts.EfsPath))
.WithParsed<EfsCreateDirectoryOptions>(opts =>
tools.EfsCreateDirectory(opts.Path, !opts.NoRecursive))
Expand Down
38 changes: 24 additions & 14 deletions EfsTools/Utils/FileUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
}
}
}
Expand All @@ -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
{
Expand All @@ -298,15 +298,15 @@ 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)
if (file != null && !PathUtils.IsNvItemFileName(file))
{
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)
Expand All @@ -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)
Expand All @@ -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();
Expand All @@ -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)
{
Expand All @@ -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
{
Expand All @@ -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)
Expand Down

0 comments on commit a67cc4e

Please sign in to comment.