Skip to content
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

SetTempFolder() should take wchar_t instead of char so that we don't #1916

Merged
merged 3 commits into from
Feb 7, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions Frameworks/Foundation/NSDictionary.mm
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,7 @@ + (NSDictionary*)dictionaryWithContentsOfFile:(NSString*)filename {
@Notes Only file:// URLs supported
*/
+ (NSDictionary*)dictionaryWithContentsOfURL:(NSURL*)url {
const char* file = (char*)[[url path] UTF8String];
NSData* data = [NSData dataWithContentsOfFile:[NSString stringWithCString:file]];
NSData* data = [NSData dataWithContentsOfURL:url];
if (data == nil) {
return nil;
}
Expand All @@ -378,8 +377,7 @@ + (NSDictionary*)dictionaryWithContentsOfURL:(NSURL*)url {
@Notes Only file:// URLs supported
*/
- (NSDictionary*)initWithContentsOfURL:(id)url {
const char* file = (char*)[[url path] UTF8String];
NSData* data = [NSData dataWithContentsOfFile:[NSString stringWithCString:file]];
NSData* data = [NSData dataWithContentsOfURL:url];

NSDictionary* dictionary = nil;
if (data) {
Expand Down Expand Up @@ -800,12 +798,10 @@ - (void)enumerateKeysAndObjectsWithOptions:(NSEnumerationOptions)options usingBl
return;
}

_enumerateWithBlock([self keyEnumerator],
options,
^(id key, BOOL* stop) {
id value = [self objectForKey:key];
block(key, value, stop);
});
_enumerateWithBlock([self keyEnumerator], options, ^(id key, BOOL* stop) {
id value = [self objectForKey:key];
block(key, value, stop);
});
}

/**
Expand Down
14 changes: 7 additions & 7 deletions Frameworks/Foundation/NSDirectoryEnumerator.mm
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static void searchRecursive(const char* rootpath,
if (keys != nil) { // caller wants to fetch some properties for this URL
NSDictionary* fileAttributes = fileAttributesForFilePath(fileFullPath.c_str());
if (fileAttributes != nil) {
NSURL* newURL = [NSURL fileURLWithPath:[NSString stringWithCString:fileFullPath.c_str()]];
NSURL* newURL = [NSURL fileURLWithPath:[NSString stringWithUTF8String:fileFullPath.c_str()]];
for (NSString* key in keys) {
if ([key isEqualToString:NSURLContentModificationDateKey]) {
// TODO 7491994: Implement CFURL resourceValue APIs
Expand All @@ -116,7 +116,7 @@ static void searchRecursive(const char* rootpath,
}

} else {
NSString* newStr = [NSString stringWithCString:filename.c_str()];
NSString* newStr = [NSString stringWithUTF8String:filename.c_str()];
[objArray addObject:newStr];
}

Expand All @@ -137,12 +137,12 @@ static void searchRecursive(const char* rootpath,
@Public No
*/
- (instancetype)_initWithPath:(const char*)path
shallow:(BOOL)shallow
includingPropertiesForKeys:(NSArray*)keys
options:(NSDirectoryEnumerationOptions)mask
returnNSURL:(BOOL)returnNSURL {
shallow:(BOOL)shallow
includingPropertiesForKeys:(NSArray*)keys
options:(NSDirectoryEnumerationOptions)mask
returnNSURL:(BOOL)returnNSURL {
_rootFiles.attach([NSMutableArray new]);
_searchPath = [NSString stringWithCString:path];
_searchPath = [NSString stringWithUTF8String:path];
searchRecursive(path, "", shallow, _rootFiles, keys, mask, returnNSURL);
_currrentEnumerator.push_back([_rootFiles objectEnumerator]);
_currentDepth = 0;
Expand Down
21 changes: 9 additions & 12 deletions Frameworks/Foundation/NSFileManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ - (NSArray*)subpathsAtPath:(NSString*)path {
@Notes attributes parameter not supported. error parameter not supported.
*/
- (BOOL)createDirectoryAtURL:(NSURL*)url
withIntermediateDirectories:(BOOL)createIntermediates
attributes:(NSDictionary*)attrs
error:(NSError**)err {
withIntermediateDirectories:(BOOL)createIntermediates
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume the formats got corrected here?

attributes:(NSDictionary*)attrs
error:(NSError**)err {
id path = [url path];

return [self createDirectoryAtPath:path withIntermediateDirectories:createIntermediates attributes:attrs error:err];
Expand All @@ -280,9 +280,9 @@ - (BOOL)createDirectoryAtURL:(NSURL*)url
@Notes attributes parameter not supported. error parameter is not populated
*/
- (BOOL)createDirectoryAtPath:(NSString*)pathAddr
withIntermediateDirectories:(BOOL)createIntermediates
attributes:(NSDictionary*)attrs
error:(NSError**)err {
withIntermediateDirectories:(BOOL)createIntermediates
attributes:(NSDictionary*)attrs
error:(NSError**)err {
if (createIntermediates) {
const char* path = [pathAddr UTF8String];
id components = [pathAddr pathComponents];
Expand Down Expand Up @@ -400,11 +400,10 @@ - (BOOL)copyItemAtPath:(id)srcPath toPath:(id)destPath error:(NSError**)error {
[outputStream open];
[inputStream open];
auto closeStreams = wil::ScopeExit([&outputStream, &inputStream]() {
[outputStream close];
[inputStream close];
[outputStream close];
[inputStream close];
});


if (NSStreamStatusOpen != inputStream.streamStatus) {
TraceError(TAG, L"Error opening %hs", src);
return NO;
Expand All @@ -417,7 +416,6 @@ - (BOOL)copyItemAtPath:(id)srcPath toPath:(id)destPath error:(NSError**)error {

uint8_t in[4096];
while ([inputStream hasBytesAvailable]) {

NSInteger readResult = [inputStream read:in maxLength:_countof(in)];
if (readResult == -1) {
return NO;
Expand All @@ -427,7 +425,6 @@ - (BOOL)copyItemAtPath:(id)srcPath toPath:(id)destPath error:(NSError**)error {
const unsigned char* baseAddress = (const unsigned char*)in;

while (bytesToWrite > 0) {

auto result = [outputStream write:(baseAddress + (readResult - bytesToWrite)) maxLength:bytesToWrite];
if (result == -1) {
return NO;
Expand Down Expand Up @@ -844,7 +841,7 @@ - (const char*)fileSystemRepresentationWithPath:(id)pathAddr {
*/
- (id)stringWithFileSystemRepresentation:(const char*)path length:(NSUInteger)length {
UNIMPLEMENTED();
return [NSString stringWithCString:path length:length];
return [NSString stringWithUTF8String:path length:length];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not an actual method.

}

// Managing the Delegate
Expand Down
10 changes: 2 additions & 8 deletions Frameworks/UIKit/StarboardXaml/ApplicationCompositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,8 @@ void InitializeApp() {
initialized = true;

// Set our writable and temp folders
auto pathData = Windows::Storage::ApplicationData::Current->LocalFolder->Path;
IwSetWritableFolder(pathData->Data());

char writableFolder[2048];
size_t outLen;
auto tempPathData = Windows::Storage::ApplicationData::Current->TemporaryFolder->Path;
wcstombs_s(&outLen, writableFolder, tempPathData->Data(), sizeof(writableFolder) - 1);
SetTemporaryFolder(writableFolder);
IwSetWritableFolder(Windows::Storage::ApplicationData::Current->LocalFolder->Path->Data());
SetTemporaryFolder(Windows::Storage::ApplicationData::Current->TemporaryFolder->Path->Data());
Copy link
Member

Choose a reason for hiding this comment

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

This is really, really silly. Why do we need to set these at runtime like this. When would this not be what we want. Seems like we should have the getters return this ...

Copy link
Member

Choose a reason for hiding this comment

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

.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

? the first one is required because starboard is removed from the application layer. The second is rather bizarre, but NSPathUtilties depends on it. Sure, NSPathUtiltities can do this instead.

Copy link
Member

Choose a reason for hiding this comment

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

They are both silly. It doesn't make sense that the application compositor sets any sort of file system stuff. Starboard should know how to do this itself. That would be more proper encapsulation ...


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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bbowman any re-write on this should be considered through #1904. what we have is not ideal.


// Set the waiter routine for the main runloop to yield
SetupMainRunLoopTimedMultipleWaiter();
Expand Down
2 changes: 1 addition & 1 deletion Frameworks/UIKit/StarboardXaml/ApplicationMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ extern "C" int ApplicationMainStart(const char* principalName,
ActivationType activationType,
IInspectable* activationArg);

void SetTemporaryFolder(const char* folder);
void SetTemporaryFolder(const wchar_t* folder);
6 changes: 3 additions & 3 deletions Frameworks/UIKit/StarboardXaml/ApplicationMain.mm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//******************************************************************************
//******************************************************************************
//
// Copyright (c) Microsoft. All rights reserved.
//
Expand Down Expand Up @@ -179,6 +179,6 @@ int ApplicationMainStart(const char* principalName,
return 0;
}

void SetTemporaryFolder(const char* folder) {
NSSetTemporaryDirectory([NSString stringWithCString:folder]);
void SetTemporaryFolder(const wchar_t* folder) {
NSSetTemporaryDirectory([NSString stringWithCharacters:(const unichar*)folder length:wcslen(folder)]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could have just changed this function to use NSString stringWithUTF8String, but there is no need for back and forth conversions, so just roll with UTF16.

Copy link
Contributor

@msft-Jeyaram msft-Jeyaram Feb 3, 2017

Choose a reason for hiding this comment

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

nit:C++ style cast?

Choose a reason for hiding this comment

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

Darn. If there was some way to get a HSTRING out of the layer above this one, we could pass it via the NSString HSTRING bridge. That'd save us a whole copy :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DHowett-MSFT yes, and in fact, we do get the value from a HSTRING. But this being a temp folder, it is going to be copied when added to any file path.

Copy link
Member

Choose a reason for hiding this comment

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

Yes it will be copied there anyway. It would still save a copy to not have a useless extra layer here to set it ...


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

}
6 changes: 3 additions & 3 deletions Frameworks/UIKit/UIImage.mm
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ - (instancetype)initWithContentsOfFile:(NSString*)pathAddr {

if (EbrAccess(pathStr, 0) == -1) {
id pathFind =
[bundle pathForResource:[NSString stringWithCString:newStr] ofType:nil inDirectory:nil forLocalization:@"English"];
[bundle pathForResource:[NSString stringWithUTF8String:newStr] ofType:nil inDirectory:nil forLocalization:@"English"];

if (pathFind != nil) {
path = (char*)[pathFind UTF8String];
Expand Down Expand Up @@ -359,7 +359,7 @@ - (instancetype)initWithContentsOfFile:(NSString*)pathAddr {
}

const UIImageCachedObject* cachedImage =
reinterpret_cast<const UIImageCachedObject*>(CFDictionaryGetValue(g_imageCache, [NSString stringWithCString:pathStr]));
reinterpret_cast<const UIImageCachedObject*>(CFDictionaryGetValue(g_imageCache, [NSString stringWithUTF8String:pathStr]));

if (cachedImage) {
if (pathStr) {
Expand Down Expand Up @@ -399,7 +399,7 @@ - (instancetype)initWithContentsOfFile:(NSString*)pathAddr {
_imageStretch.size.height = 1.0f;

// Cache the image
_cacheImage = [UIImage cacheImage:self withName:[NSString stringWithCString:pathStr]];
_cacheImage = [UIImage cacheImage:self withName:[NSString stringWithUTF8String:pathStr]];

if (pathStr) {
IwFree(pathStr);
Expand Down
Loading