forked from osoumen/C700
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlistBRRFile.cpp
98 lines (85 loc) · 2.45 KB
/
PlistBRRFile.cpp
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
/*
* PlistBRRFile.cpp
* C700
*
* Created by osoumen on 12/10/11.
* Copyright 2012 __MyCompanyName__. All rights reserved.
*
*/
#include "PlistBRRFile.h"
//-----------------------------------------------------------------------------
PlistBRRFile::PlistBRRFile( const char *path, bool isWriteable )
: FileAccess(path, isWriteable)
{
}
//-----------------------------------------------------------------------------
PlistBRRFile::~PlistBRRFile()
{
if ( mIsLoaded ) {
#if MAC
CFRelease(mPropertydata);
#endif
}
}
#if MAC
//-----------------------------------------------------------------------------
bool PlistBRRFile::Load()
{
if ( IsLoaded() ) {
CFRelease(mPropertydata);
}
if ( mPath == NULL ) return false;
//CFURLを作成
CFURLRef path = CFURLCreateFromFileSystemRepresentation(NULL, (UInt8*)mPath, strlen(mPath), false);
//保存されたパッチ(.brrファイル)の読み込み
CFReadStreamRef filestream = CFReadStreamCreateWithFile(NULL, path);
if (CFReadStreamOpen(filestream)) {
CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
mPropertydata = CFPropertyListCreateFromStream(NULL,filestream,0,
kCFPropertyListImmutable,
&format,NULL);
if ( mPropertydata ) {
mIsLoaded = true;
}
else {
mIsLoaded = false;
}
CFReadStreamClose(filestream);
}
CFRelease(filestream);
return mIsLoaded;
}
//-----------------------------------------------------------------------------
bool PlistBRRFile::Write()
{
if ( IsLoaded() == false ) return false;
if ( mPath == NULL ) return false;
//CFURLを作成
CFURLRef savefile = CFURLCreateFromFileSystemRepresentation(NULL, (UInt8*)mPath, strlen(mPath), false);
//バイナリ形式に変換
CFWriteStreamRef filestream = CFWriteStreamCreateWithFile(NULL,savefile);
if (CFWriteStreamOpen(filestream)) {
CFPropertyListWriteToStream(mPropertydata,filestream,kCFPropertyListBinaryFormat_v1_0,NULL);
CFWriteStreamClose(filestream);
}
CFRelease(filestream);
CFRelease(savefile);
return true;
}
//-----------------------------------------------------------------------------
void PlistBRRFile::SetPlistData( CFPropertyListRef propertydata )
{
if ( mIsLoaded ) {
CFRelease(mPropertydata);
}
mPropertydata = propertydata;
CFRetain(mPropertydata);
mIsLoaded = true;
}
//-----------------------------------------------------------------------------
CFPropertyListRef PlistBRRFile::GetPlistData() const
{
if ( IsLoaded() == false ) return NULL;
return mPropertydata;
}
#endif