-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGDSaveData_android.cpp
More file actions
104 lines (86 loc) · 2.09 KB
/
GDSaveData_android.cpp
File metadata and controls
104 lines (86 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//
// SaveData_android.cpp
// BasketWorldCup2
//
// Created by ksoo k on 13. 1. 4..
//
//
#include "GDSaveData_android.h"
/*
string filePath = "KSDATA";
NSArray* paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES );
NSString* documentsDirectory = [paths objectAtIndex:0];
NSString* nsfilePath = [NSString stringWithUTF8String:filePath.c_str()];
NSString* fullFileName = [NSString stringWithFormat:@"%@/%@", documentsDirectory, nsfilePath ];
const char* szFilePath = [fullFileName UTF8String];
FILE* fp = fopen( szFilePath, "w" );
fprintf(fp, "%s", tt.c_str());
fclose(fp);
}
string readF()
{
string filePath = "KSDATA";
NSArray* paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES );
NSString* documentsDirectory = [paths objectAtIndex:0];
NSString* nsfilePath = [NSString stringWithUTF8String:filePath.c_str()];
NSString* fullFileName = [NSString stringWithFormat:@"%@/%@", documentsDirectory, nsfilePath ];
const char* szFilePath = [fullFileName UTF8String];
cout << szFilePath << endl;
FILE* fp = fopen( szFilePath, "r" );
string result;
if(fp)
{
fseek(fp, 0L, SEEK_END);
int s = ftell(fp);
fseek(fp, 0L, SEEK_SET);
char* buffer = new char[s+1];
memset(buffer, 0, sizeof(s+1));
fread(buffer, sizeof(char), s, fp);
fclose(fp);
result = buffer;
delete [] buffer;
}
else
{
return "";
}
return result;
}
*/
#if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID
void gdwriteF(string path, string tt)
{
string path2 = path + "GDKSDATA";
FILE* fp = fopen( path2.c_str(), "w" );
if(!fp)
{
CCLog("file failure2");
}
fprintf(fp, "%s", tt.c_str());
fclose(fp);
}
string gdreadF(string path)
{
string path2 = path + "GDKSDATA";
FILE* fp = fopen( path2.c_str(), "r" );
string result;
if(fp)
{
fseek(fp, 0L, SEEK_END);
int s = ftell(fp);
fseek(fp, 0L, SEEK_SET);
char* buffer = new char[s+1];
memset(buffer, 0, sizeof(s+1));
fread(buffer, sizeof(char), s, fp);
fclose(fp);
result = buffer;
delete [] buffer;
}
else
{
CCLog("read fail");
return "";
}
return result;
}
#endif