-
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
Open
Smohamed-MSFT
wants to merge
5
commits into
master
Choose a base branch
from
user/smohamed/updateToSupportLoggingImprov
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2ce316d
Update to support logging improvement and fix build issues
S-mohamed1 362e664
Update to support logging improvement and fix build issues
S-mohamed1 75d46d8
update per PR comments
S-mohamed1 eeea0c9
update resource strings
S-mohamed1 82a4c90
Update to reflect PR comments
S-mohamed1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
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 << "Wrote 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 << "Wrote 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 << "Wrote error output to file: " << outputFilePath; | ||
} | ||
|
||
// Telemetry : Workflow Log | ||
QueryPerformanceCounter(&msixMgrLoad_EndCounter); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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;
use unpackFailureString everywhere std::wcout is used.
add unpackFailureString << std::flush;
then do:
std::wcout << unpackFailureString.rdbuf() << std::endl;
if (!outputFilePath.empty)
{
open
outFile << unpackFailureString.rdbuf() << std::endl;
}
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.
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 comment
The 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(
In std::wstring packageSource,
In std::vectorstd::wstring skippedFiles,
In std::vectorstd::wstring failedPackages,
In std::vector failedPackagesErrors,
In std::wstringstream& unpackFailureStringStream)
{
if (!skippedFiles.empty())
{
unpackFailureStringStream << std::endl;
unpackFailureStringStream << "[WARNING] The following items from " << packageSource << " were ignored because they are not packages or bundles " << std::endl;
...
etc
}
void OutputUnpackFailures(
In std::wstring packageSource,
In std::vectorstd::wstring skippedFiles,
In std::vectorstd::wstring failedPackages,
In std::vector failedPackagesErrors,
In std::wstring outputFilePath)
{
std::wstringstream unpackFailureStringStream;
GetUnpackOutputFailures(packageSource, skippedFiles, failedPackages, failedPackagesErrors, unpackFailureStringStream);
std::wstring unpackFailureString = unpackFailureStringStream.str();
std::wcout << unpackFailureString << std::endl;
if (!outputFilePath.empty())
{
std::wofstream outFile;
outFile.open(outputFilePath);
outFile << unpackFailureString << std::endl;
outFile.close();
wcout << "Wrote error output to file: " << outputFilePath;
}
}
And then just call the OutputUnpackFailures function and let it deal with the if\else for if outputFilePath is set.
std::wcout << std::endl;
std::wcout << "Finished unpacking packages to: " << unpackDestination << std::endl;
std::wcout << std::endl;
OutputUnpackFailures(packageSourcePath, skippedFiles, failedPackages, failedPackagesErrors, outputFilePath);
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.
Completed making those changes 82a4c90