Recently i'm using cocos 2d-x ver-3.17.
I complied resource to jsc then make a server to upload it like update-server, control version i think.
Now when i build the app in IOS which will connect to update-server then download the file jsc. Unfortunately, when the app trying to save the file down it falling to the error " don't have permission to save the file". What should i do to provide them permission to solve it.
Fail to create directory :
"/var/mobile/Containers/Data/Application/C9BA91B9-AEF6-4FF8-B5F3-061AF15441A5/Documents_temp/":
You don’t have permission to save the file “Documents_temp” in the
folder “C9BA91B9-AEF6-4FF8-B5F3-061AF15441A5”.
bool FileUtilsApple::createDirectory(const std::string& path)
{
CCASSERT(!path.empty(), "Invalid path");
if (isDirectoryExist(path))
return true;
NSError* error;
bool result = [s_fileManager createDirectoryAtPath:[NSString stringWithUTF8String:path.c_str()] withIntermediateDirectories:YES attributes:nil error:&error];
if(!result && error != nil)
{
CCLOGERROR("Fail to create directory \"%s\": %s", path.c_str(), [error.localizedDescription UTF8String]);
}
return result;
}
How can i get permission to save the files ?
solved : https://forum.cocos.com/t/topic/47298/3
Self-reliance, find out the problem, you need to define the file directory
find your initAssetManager :
var storagePath = (jsb.fileUtils ? jsb.fileUtils.getWritablePath() : "./")+"temp/";
Related
I'm trying to automate a test where I need to upload a file, but I keep getting that the file can't be found.
I found in Selenium page that, for other languages, we have to use a Local File Detector so that the file that's in my computer are sent to the remote server.
The Local File Detector allows the transfer of files from the client machine to the remote server.
But I can't find any function related to that in Go.
I've tried the SendKeys function:
element, err := crediya.el.FindElement(selenium.ByID, "file")
if err != nil {
return fmt.Errorf(errors.Selenium.ElementNotFound+"\n%w", err)
}
if err = element.SendKeys(path); err != nil {
return fmt.Errorf(errors.Selenium.SendKeysFailure+"\n%w", err)
}
but I keep getting:
"unknown error - 61: invalid argument: File not found : "
Note: the element is an input of file type.
Thank you, in advance, for any help provided.
Can someone, please, help me?
In this way, I download a image successfully:
GTLServiceDrive *drive = ...;
GTLDriveFile *file = ...;
NSString *url = [NSString stringWithFormat:#"https://www.googleapis.com/drive/v3/files/%#?alt=media",file.identifier];
GTMSessionFetcher *fetcher = [drive.fetcherService fetcherWithURLString:url];
[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {
if (error == nil) {
NSLog(#"Retrieved file content");
// Do something with data
} else {
NSLog(#"An error occurred: %#", error);
}
}];
the document of google drive sdk tell me to download a pdf or google docs should use another url:
NSString *url = [NSString stringWithFormat:#"https://www.googleapis.com/drive/v3/files/%#/export?alt=media&mimeType=application/pdf",file.identifier];
but I failed, error is this:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "badRequest",
"message": "Bad Request"
}
],
"code": 400,
"message": "Bad Request"
}
}
In downloading file make sure your app must be authorized with a scope that allows reading of file content. For example, an app using the drive.readonly.metadata scope would not be authorized to download the file contents. Users with edit permission may restrict downloading by read-only users by setting the viewersCanCopyContent field to true.
There is another way to download a file by using the partial download. It involves downloading only a specified portion of a file. You can specify the portion of the file you want to dowload by using a byte range with the Range header.
This SO question is using partial download. I think it can help you.
This code demonstrate how to download a Google Document in PDF format.
String fileId = "1ZdR3L3qP4Bkq8noWLJHSr_iBau0DNT4Kli4SxNc2YEo";
OutputStream outputStream = new ByteArrayOutputStream();
driveService.files().export(fileId, "application/pdf")
.executeMediaAndDownloadTo(outputStream);
I'm trying to create a valid file URL which points to a file which I know exists.
NSURL* fileURL = [NSURL fileURLWithPath:[#"~/Users/zak/global.scss"
stringByExpandingTildeInPath] isDirectory:NO];
NSLog(#"Looks like you want me to open a %# file!", fileURL.pathExtension);
NSError *err;
if (![fileURL checkResourceIsReachableAndReturnError:&err]) {
NSLog(#"%#", err);
}
else {
NSLog(#"success!!!");
};
which always causes the compiler to keep telling me
Error Domain=NSCocoaErrorDomain Code=260 "The file “global.scss” couldn’t be
opened because there is no such file." UserInfo=0x1021937a0 {NSURL=file://
localhost/~/Users/zak/global.scss,
NSFilePath=/~/Users/zak/global.scss,
NSUnderlyingError=0x10212f4b0 "The operation couldn’t be completed.
No such file or directory"}
Why doesn't this work? Do I need to use some sort of constant as the base URL?
~/Users/zak/globals.scss almost certainly does not exist. That ~ is in a pretty weird looking place. You might try ~zak/global.scss or /Users/zak/globals.scss. To check the path, just do ls PATHTOTEST in a terminal window - it will tell you if it's there or not (and show you the expansion of the path if it failed).
As all Db files of Calls, SMS, Emails and Calender etc are present in,
SMS: /Var/Mobile/Library/SMS
Contacts /User/Library/AddressBook
Mail: /Var/Mobile/Library/Mail
Calendar: /Var/Mobile/Library/Calendar
Call History: /Var/Mobile/Library/CallHistory
Notes: /Var/Mobile/Library/Notes
Safari: /Var/Mobile/Library/Safari
how to create backup files of above all programmatically.
You Can try this if you want to backup that database to your device. apple may not allow you to access the db files of call lists.
if (![[NSFileManager defaultManager] fileExistsAtPath:#"YOUR DB FILE PATH"])
{
if ([[NSFileManager defaultManager] copyItemAtPath:"YOUR DB FILE PATH" toPath:#"PATH WHERE YOU WANT TO BACKUP" error:nil])
{
NSLog(#"Backuped");
}
else
{
NSLog(#"Error in backuping the database");
}
}
I have a remote directory with several subdirectories and files in them on Dropbox.
remote side:
-Mobile Profiles *(root)*
-- Custom Profiles
--- Profile1
--- Profile2
--- Profile3
Uploading the files and directories / and subdirectories with files is not a problem. I am having a brain fart when it comes to getting the subdirectories and their contents from dropbox to the device.
put
-(void)backupCustomProfiles {
for ( NSString *file in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:MP_CUSTOM error:&error] ) {
[self.restClient uploadFile:file toPath:#"/Mobile Profiles/Custom Profiles/" fromPath:EasyStrings(MP_CUSTOM,file)];
}
}
get
-(void)restoreCustomProfiles {
for ( ) {
/* ? */
}
}
I am not sure how to iterate through the subdirectories on the remote side.
First load the directory metadata, then load the files that it references.
To limit the number of parallel fetches, use a NSOperationQueue for all of the loadMetadata and loadFile calls to limit the number of parallel fetches. And to avoid redundant file downloads, remember the downloaded metadata in a plist.
- (void) restoreCustomProfiles
{
[self.client loadMetadata:#"/Mobile Profiles/Custom Profiles" withHash:hash];
}
- (void) restClient:(DBRestClient*)client loadedMetadata:(DBMetadata*)metadata
{
for (DBMetadata* child in metadata.contents) {
NSString *path = [child.path lowercaseString];
if (child.isDirectory) {
[client loadMetadata:child.path withHash:hash];
} else {
[client loadFile:pathToDownload intoPath:[
self.directory stringByAppendingString:path]];
}
}
}
- (void) restClient:(DBRestClient*)client loadedFile:(NSString*)destPath
{
// successfully downloaded a file to destPath
}