-
Notifications
You must be signed in to change notification settings - Fork 177
[MSIX app attach] Enable logging of output to a file for the IT Pro. #600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
2ce316d
362e664
75d46d8
eeea0c9
82a4c90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,6 +175,19 @@ std::map<std::wstring, Options, CaseInsensitiveLess> CommandLineInterface::s_opt | |
return S_OK; | ||
}), | ||
}, | ||
{ | ||
L"-output", | ||
Option(true, IDS_STRING_HELP_OPTION_OUTPUT, | ||
[&](CommandLineInterface* commandLineInterface, const std::string& outPath) | ||
{ | ||
if (commandLineInterface->m_operationType != OperationType::Unpack) | ||
{ | ||
return E_INVALIDARG; | ||
} | ||
commandLineInterface->m_outputPath = utf8_to_utf16(outPath); | ||
|
||
return S_OK; | ||
}), | ||
}, | ||
{ | ||
L"-validateSignature", | ||
Option(false, IDS_STRING_HELP_OPTION_UNPACK_VALIDATESIGNATURE, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
#include "Util.hpp" | ||
#include "..\msixmgrLib\GeneralUtil.hpp" | ||
#include "resource.h" | ||
#include <fstream> | ||
#include <VersionHelpers.h> | ||
#include "UnpackProvider.hpp" | ||
#include "ApplyACLsProvider.hpp" | ||
|
@@ -173,6 +174,60 @@ void OutputUnpackFailures( | |
} | ||
} | ||
|
||
void OutputUnpackFailuresToFile( | ||
_In_ std::wstring packageSource, | ||
_In_ std::vector<std::wstring> skippedFiles, | ||
_In_ std::vector<std::wstring> failedPackages, | ||
_In_ std::vector<HRESULT> failedPackagesErrors, | ||
_In_ std::wstring outfilePath) | ||
{ | ||
std::wofstream outfile; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicating all this code for writing to the different types of logs should be unnecessary, but writing multiple streams at once also seems to have some complexity. Easiest solution seems like building a big wstringstream of everything that needs to get logged in this function and then having the wrapper function either write that to just std::wcout or both std::wcout and the file stream. std::wstringstream unpackFailureString; then do: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The duplication works because we want to have different behavior when output path is set and when it isn't this is something I've validated with PM during design. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicating all the output string logic isn't necessary to have different behavior when output path is set. void GetUnpackOutputFailures( void OutputUnpackFailures( And then just call the OutputUnpackFailures function and let it deal with the if\else for if outputFilePath is set. OutputUnpackFailures(packageSourcePath, skippedFiles, failedPackages, failedPackagesErrors, outputFilePath); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Completed making those changes 82a4c90 |
||
outfile.open(outfilePath); | ||
|
||
if (!skippedFiles.empty()) | ||
{ | ||
outfile << std::endl; | ||
outfile << "[WARNING] The following items from " << packageSource << " were ignored because they are not packages or bundles " << std::endl; | ||
outfile << std::endl; | ||
|
||
for (int i = 0; i < skippedFiles.size(); i++) | ||
{ | ||
outfile << skippedFiles.at(i) << std::endl; | ||
} | ||
|
||
outfile << std::endl; | ||
} | ||
|
||
if (!failedPackages.empty()) | ||
{ | ||
outfile << std::endl; | ||
outfile << "[WARNING] The following packages from " << packageSource << " failed to get unpacked. Please try again: " << std::endl; | ||
outfile << std::endl; | ||
|
||
for (int i = 0; i < failedPackages.size(); i++) | ||
{ | ||
HRESULT hr = failedPackagesErrors.at(i); | ||
|
||
outfile << L"Failed with HRESULT 0x" << std::hex << hr << L" when trying to unpack " << failedPackages.at(i) << std::endl; | ||
if (hr == static_cast<HRESULT>(MSIX::Error::CertNotTrusted)) | ||
{ | ||
outfile << L"Please confirm that the certificate has been installed for this package" << std::endl; | ||
} | ||
else if (hr == static_cast<HRESULT>(MSIX::Error::FileWrite)) | ||
{ | ||
outfile << L"The tool encountered a file write error. If you are unpacking to a VHD, please try again with a larger VHD, as file write errors may be caused by insufficient disk space." << std::endl; | ||
} | ||
else if (hr == E_INVALIDARG) | ||
{ | ||
outfile << "Please confirm the given package path is an .appx, .appxbundle, .msix, or .msixbundle file" << std::endl; | ||
} | ||
|
||
outfile << std::endl; | ||
} | ||
} | ||
outfile.close(); | ||
} | ||
|
||
int main(int argc, char * argv[]) | ||
{ | ||
// Register the providers | ||
|
@@ -478,7 +533,7 @@ int main(int argc, char * argv[]) | |
// Telemetry : Unpack Workflow Log | ||
msixmgrTraceLogging::TraceLogUnpackWorkflow(workflowId.c_str(), msixmgrTraceLogging::ExtractPackageNameFromFilePath(cli.GetPackageFilePathToInstall()).c_str(), | ||
cli.GetFileTypeAsString().c_str(), cli.GetVHDSize(), cli.IsCreate(), cli.IsApplyACLs()); | ||
|
||
auto outputFilePath = cli.GetOutputPath(); | ||
auto packageSourcePath = cli.GetPackageFilePathToInstall(); | ||
auto unpackDestination = cli.GetUnpackDestination(); | ||
auto rootDirectory = cli.GetRootDirectory(); | ||
|
@@ -645,8 +700,15 @@ int main(int argc, char * argv[]) | |
std::wcout << "Successfully created the CIM file: " << unpackDestination << std::endl; | ||
std::wcout << std::endl; | ||
|
||
OutputUnpackFailures(packageSourcePath, skippedFiles, failedPackages, failedPackagesErrors); | ||
|
||
if (outputFilePath.empty()) | ||
{ | ||
OutputUnpackFailures(packageSourcePath, skippedFiles, failedPackages, failedPackagesErrors); | ||
} | ||
else | ||
{ | ||
OutputUnpackFailuresToFile(packageSourcePath, skippedFiles, failedPackages, failedPackagesErrors, outputFilePath); | ||
wcout << "Written error output to file: " << outputFilePath; | ||
} | ||
// Telemetry : Workflow Log | ||
QueryPerformanceCounter(&msixMgrLoad_EndCounter); | ||
workflowElapsedTime = msixmgrTraceLogging::CalcWorkflowElapsedTime(msixMgrLoad_StartCounter, msixMgrLoad_EndCounter, msixMgrLoad_Frequency); | ||
|
@@ -761,7 +823,15 @@ int main(int argc, char * argv[]) | |
std::wcout << std::endl; | ||
} | ||
|
||
OutputUnpackFailures(packageSourcePath, skippedFiles, failedPackages, failedPackagesErrors); | ||
if (outputFilePath.empty()) | ||
{ | ||
OutputUnpackFailures(packageSourcePath, skippedFiles, failedPackages, failedPackagesErrors); | ||
} | ||
else | ||
{ | ||
OutputUnpackFailuresToFile(packageSourcePath, skippedFiles, failedPackages, failedPackagesErrors, outputFilePath); | ||
wcout << "Written error output to file: " << outputFilePath; | ||
} | ||
|
||
std::wcout << std::endl; | ||
std::wcout << "Finished unpacking packages to: " << unpackDestination << std::endl; | ||
|
@@ -801,7 +871,15 @@ int main(int argc, char * argv[]) | |
std::wcout << "Finished unpacking packages to: " << unpackDestination << std::endl; | ||
std::wcout << std::endl; | ||
|
||
OutputUnpackFailures(packageSourcePath, skippedFiles, failedPackages, failedPackagesErrors); | ||
if (outputFilePath.empty()) | ||
|
||
{ | ||
OutputUnpackFailures(packageSourcePath, skippedFiles, failedPackages, failedPackagesErrors); | ||
} | ||
else | ||
{ | ||
OutputUnpackFailuresToFile(packageSourcePath, skippedFiles, failedPackages, failedPackagesErrors, outputFilePath); | ||
wcout << "Written error output to file: " << outputFilePath; | ||
|
||
} | ||
|
||
// Telemetry : Workflow Log | ||
QueryPerformanceCounter(&msixMgrLoad_EndCounter); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,7 +134,7 @@ BEGIN | |
IDS_STRING_HELP_OPTION_MOUNT_FILETYPE "the type of file to mount or unmount. The following file types are currently supported: {VHD, VHDX, CIM}" | ||
IDS_STRING_HELP_OPTION_UNPACK_VHDSIZE "the desired size of the VHD or VHDX file in MB. Must be between 5 and 2040000 MB. Use only for VHD or VHDX files" | ||
IDS_STRING_HELP_OPTION_MOUNT_READONLY "boolean (true of false) indicating whether a VHD(X) should be mounted as read only. If not specified, the image is mounted as read-only by default" | ||
IDS_STRING_HELP_OPTION_OUTPUT "optional parameter selects logging location to write the command line output to" | ||
|
||
END | ||
|
||
#endif // English (United States) resources | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this option is unpack only I'd rename these to fit the unpack specific options elsewhere, so IDS_STRING_HELP_OPTION_UNPACK_OUTPUT
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed