Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Add support for containerURLs through publisher cache folders - #2384

Merged
Allen Ballway (aballway) merged 3 commits into
microsoft:developfrom
aballway:develop
Apr 4, 2017
Merged

Allen Ballway (aballway) merged 3 commits into
microsoft:developfrom
aballway:develop

Conversation

@aballway

Copy link
Copy Markdown
Contributor

The reference platform has a concept of an application-group entitlement which allows apps made by the same publisher to share folders and semaphores. The shared folders can be accessed through -[NSFileManager containerURLForSecurityApplicationGroupIdentifier:] which will return an NSURL pointing to the shared folder with the given name if one exists.

These folders are declared in an entitlements file separate from the main .pbxproj and info.plist where other settings are stored, and is pointed at by the value with key CODE_SIGN_ENTITLEMENTS in the PBXNativeTarget's Build Configurations.

Here, the shared folders are implemented using Windows' Publisher Cache Folders, which also allow files to be shared in designated folders between apps of the same publisher, but with the caveat that users can clear the data at any time so it should not be used as the sole storage for key data.

VSImporter has been modified to check if CODE_SIGN_ENTITLEMENTS exists, and if it does, read the file and look for com.apple.security.application-groups, which will contain an array of folder names which are to be shared. The reference platform specifies the format which folders must be named, but Publisher Cache Folders does not have such a restriction for names so any valid folder names will be taken and used.

-[NSFileManager containerURLForSecurityApplicationGroupIdentifier:] is implemented by checking if a Publisher Cache Folder of the given name, and if it does returning an NSURL to it.

Fixes #2295
Fixes #2307

Comment thread Frameworks/Foundation/NSFileManager.mm Outdated

#include <COMIncludes.h>
#import <windows.storage.h>
#import <wrl\client.h>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

standardize on /

Comment thread Frameworks/Foundation/NSFileManager.mm Outdated
ComPtr<IStorageItem> storageItem;
RETURN_NULL_IF_FAILED(folder.As(&storageItem));

HSTRING folderPath;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want a HStringReference here; i think get_Path will return a +1 HSTRING, and you'll leak it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, spent too much time with CF, got used to Get = 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You actually want a Wrappers::HString https://msdn.microsoft.com/en-us/library/hh771141.aspx

HStringReference is for a reference to an existing string resource to avoid copies.


In reply to: 109047974 [](ancestors = 109047974)


PBXFileReference* m_productReferencePtr;
BuildRuleList m_buildRulePtrs;
XCConfigurationList* m_nativeBuildConfigurationListPtr;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XCConfigurationList* [](start = 3, length = 21)

this is fine as a raw ptr? do we not own the config list here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not, it is just a pointer to an object owned by the pbxDoc. Ideally it would be a shared_ptr but that's a lot more fixing than I want to do for this change set.

Comment thread tools/vsimporter/src/SBProject.cpp Outdated
extension +=
" </PublisherCacheFolders>\n"
" </Extension>\n";
ret.emplace_back(extension);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extension [](start = 25, length = 9)

should you std move extension here?

Comment thread tools/vsimporter/src/SBProject.cpp Outdated
pDict = boost::any_cast<Plist::dictionary_type>(&pAny);
} catch (const std::exception& e) {
SBLog::error() << e.what() << std::endl;
pDict = nullptr;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pDict = nullptr; [](start = 12, length = 20)

move this up to the declaration?

@bbowman

Copy link
Copy Markdown
Member

:shipit:


using namespace Microsoft::WRL;
using namespace ABI::Windows::Storage;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can get rid of the #ifdef linux code here.

// Dispose of any resources that can be recreated.
}

- (void)readFile {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

want to add a negative test here trying to read folder2?

Comment thread tools/vsimporter/src/SBProject.cpp Outdated
" </PublisherCacheFolders>\n"
" </Extension>\n";
ret.emplace_back(extension);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use pugixml for this. See VSTemplateProject.cpp.

</Application>
</Applications>

$extensions$

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$extensions$ [](start = 2, length = 12)

Use in combination with pugixml instead

String ret = "";
buildSettings.getValue("CODE_SIGN_ENTITLEMENTS", ret);
return ret;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SBResourcesBuildPhase.cpp does this simpler. See SBResourcesBuildPhase::writeVCProjectFiles:
String plistPath = bs.second->getValue("INFOPLIST_FILE");

@memontic-ms

Copy link
Copy Markdown
Contributor

🕐

extensionsOutput += " </Extensions>";
m_params["$extensions$"] = extensionsOutput;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't seem to be using this function anymore. Revert changes in VSTemplateParameters.cpp/h

Plist::dictionary_type* pDict = nullptr;
boost::any pAny;
try {
Plist::readPlist(entitlementsPath.c_str(), pAny);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plist::readPlist(entitlementsPath.c_str(), pAny); [](start = 8, length = 49)

Needs to be relative to xcodeproj or something, not relative to the current dir.

static void insertUrlSchemes(const String& file, const StringSet& schemes) {
//
// Inject registered URL schemes into the AppX manifest file, in this format:
static std::vector<String> getCacheFolders(const String& entitlementsPath) {

@msft-Jeyaram Jeyaraj (msft-Jeyaram) Apr 3, 2017 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getCacheFolders [](start = 27, length = 15)

return this by ref vs making a copy.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler should elide this copy #ByDesign

SBLog::error() << e.what() << std::endl;
}

if (pDict) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: a comment here would be nice

Comment thread tools/vsimporter/src/SBProject.cpp Outdated

#include <iostream>
#include <iterator>
#include <memory>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused include

#include "PBXBuildRule.h"
#include "PBXObjectIdConvert.h"
#include "VariableCollection.h"
#include "XCBuildConfiguration.h"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused includes

Comment thread tools/vsimporter/include/SBProject.h Outdated
void queryBuildConfigurations();
void selectBuildConfigurations(const StringSet* configNames);
void getMatchingFiles(fileMatchFunc matchFunc, ConstFileList& ret) const;
std::vector<std::string> SBProject::getPublisherCacheFolderNames() const;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove. This is never defined/used.

@aballway
Allen Ballway (aballway) merged commit 3438f59 into microsoft:develop Apr 4, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants