-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetBin_DLG_FileIO.cpp
109 lines (109 loc) · 2.8 KB
/
GetBin_DLG_FileIO.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
99
100
101
102
103
104
105
106
107
108
109
#include "GetBin_DLG.h"
void GetBin_DLG::dLoadBin( void )
{
xStrT st;
u8 keyNo = 0;
long i = 0;
bool atGrp = false;
bool atKey = false;
BIN* bin;
RAM ram;
xStr key, text, path, file, name;
gGetBinFile( path, file );
s8 index = dBinName_LB->GetCount();
for ( --index; index >= 0; --index )
{
bin = dGetBin( index );
if ( !bin->isDefault ) dBinName_LB->Delete( index );
}
wxFileConfig cfgBin( dTitle, dVendor, file );
bin = new BIN;
bin->isDefault = false;
for
(
atGrp = cfgBin.GetFirstGroup( name, i );
atGrp;
atGrp = cfgBin.GetNextGroup( name, i )
)
{
bin->nowName = name;
bin->oldName = name;
bin->SetCount( 1 );
cfgBin.SetPath( name );
for
(
atKey = cfgBin.GetFirstEntry( key, i );
atKey;
atKey = cfgBin.GetNextEntry( key, i )
)
{
cfgBin.Read( key, &text );
st.SetString( text, wxT( ";" ) );
if ( key.CmpNoCase( wxT( "data" ) ) == 0 )
{
text = st.GetNextToken();
if ( text.CmpNoCase( wxT( "file" ) ) == 0 ) bin->isFile = true;
else bin->isFile = false;
bin->nowFile = st.GetNextToken();
bin->oldFile = bin->nowFile;
bin->bind = st.GetNextToken();
bin->path = st.GetNextToken();
}
else
{
keyNo = GetHex( key, 1u );
if ( keyNo < 16u )
{
ram.name = st.GetNextToken();
ram.ptrDepth = GetHex( st.GetNextToken(), 1u );
ram.byte = GetHex( st.GetNextToken() );
ram.size = GetHex( st.GetNextToken() );
if ( keyNo >= bin->GetCount() ) bin->SetCount( keyNo + 1 );
( *bin )[ keyNo ] = ram;
}
}
}
dNewBin( bin );
}
delete bin;
dBinName_LB->Select( 0 );
dShowBin();
}
void GetBin_DLG::dSaveBin( void )
{
RAM ram;
BIN* bin;
u8 j, jCount;
s8 i, iCount = dBinName_LB->GetCount();
xStr key, text, path, file;
gGetBinFile( path, file );
wxFileConfig cfgBin( dTitle, dVendor, file );
cfgBin.DeleteAll();
gGetDBPFile( path, file );
for ( i = 0; i < iCount; ++i )
{
bin = dGetBin( i );
if ( bin->isDefault ) continue;
key = wxT( "data" );
jCount = bin->GetCount();
cfgBin.SetPath( bin->nowName );
if ( bin->isFile ) text = wxT( "file;" );
else text = wxT( "app;" );
cfgBin.Write( key, text + bin->nowFile + wxT( ";" ) +
bin->bind + wxT( ";" ) + bin->path );
for ( j = 0u; j < jCount; ++j )
{
ram = ( *bin )[ j ];
key.Printf( wxT( "%X" ), j );
text.Printf( wxT( ";%X;%llX;%llX" ),
ram.ptrDepth, ram.byte, ram.size );
cfgBin.Write( key, ram.name + text );
}
// Change old data
file = path + bin->oldFile + wxT( ".hexdb" );
if ( wxFileExists( file ) )
wxRenameFile( file, path + bin->nowFile + wxT( ".hexdb" ) );
bin->oldName = bin->nowName;
bin->oldFile = bin->nowFile;
}
}