forked from worthingtonse/CloudCoinCore4
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDumper.cs
More file actions
272 lines (240 loc) · 13 KB
/
Dumper.cs
File metadata and controls
272 lines (240 loc) · 13 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Foundation
{
class Dumper
{
FileUtils fileUtils;
Random random;
public Dumper( FileUtils fileUtils ) {
this.fileUtils = fileUtils;
random = new Random();
}//end Dumper constructor
public void dumpAll() {
// 1. Get all file names in bank
String[] bankFileNames = new DirectoryInfo(this.fileUtils.bankFolder).GetFiles().Select(o => o.Name).ToArray();//Get all files in suspect folder
// 2. loop. Each name create a new name
String newFileName = "";
for(int i= 0; i < bankFileNames.Length; i++) {
newFileName = bankFileNames[i];
int randInt = random.Next(100000, 10000000);
string randomIntString = "." + randInt.ToString() + ".";
newFileName = newFileName.Replace("..", randomIntString);
// 3. move file to export.
File.Move(this.fileUtils.bankFolder + bankFileNames[i], this.fileUtils.exportFolder + newFileName);
}//end for each file name
}//end dump all
/* Write JSON to .stack File */
public bool dumpSome(int m1, int m5, int m25, int m100, int m250 )
{
bool jsonExported = true;
int totalSaved = m1 + (m5 * 5) + (m25 * 25) + (m100 * 100) + (m250 * 250);
// Track the total coins
int coinCount = m1 + m5 + m25 + m100 + m250;
String[] coinsToDelete = new String[coinCount];
String[] bankedFileNames = new DirectoryInfo(this.fileUtils.bankFolder).GetFiles().Select(o => o.Name).ToArray();//Get all names in bank folder
String[] frackedFileNames = new DirectoryInfo(this.fileUtils.frackedFolder).GetFiles().Select(o => o.Name).ToArray(); ;
// Add the two arrays together
var list = new List<String>();
list.AddRange(bankedFileNames);
list.AddRange(frackedFileNames);
// Program will spend fracked files like perfect files
bankedFileNames = list.ToArray();
// Check to see the denomination by looking at the file start
int c = 0;
// c= counter
String json = "";
String start = "{" + Environment.NewLine;
start = start + "\t\"cloudcoin\": [" + Environment.NewLine;
String end = "\t]" + Environment.NewLine + "}";
String bankFileName;
String frackedFileName;
string denomination;
// Put all the JSON together and add header and footer
String filename = "";
for (int i = 0; (i < bankedFileNames.Length); i++)
{
denomination = bankedFileNames[i].Split('.')[0];
bankFileName = this.fileUtils.bankFolder + bankedFileNames[i];//File name in bank folder
frackedFileName = this.fileUtils.frackedFolder + bankedFileNames[i];//File name in fracked folder
if (denomination == "1" && m1 > 0)
{
if (c != 0)//This is the json seperator between each coin. It is not needed on the first coin
{
json += ",\n";
}
if (File.Exists(bankFileName)) // Is it a bank file
{
CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(bankFileName);
coinNote.aoid = null;//Clear all owner data
json = start + this.fileUtils.setJSON(coinNote) + end;
int randInt = random.Next(100000, 10000000);
filename = this.fileUtils.exportFolder + Path.DirectorySeparatorChar + coinNote.getDenomination() + ".CloudCoins." + randInt + ".stack";
File.WriteAllText( filename, json);
Console.Out.WriteLine("Writing to " + filename);
coinsToDelete[c] = bankFileName;
c++;
}
else
{
CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(frackedFileName);
coinNote.aoid = null;
json = start + this.fileUtils.setJSON(coinNote) + end;
int randInt = random.Next(100000, 10000000);
filename = this.fileUtils.exportFolder + Path.DirectorySeparatorChar + coinNote.getDenomination() + ".CloudCoins." + randInt + ".stack";
File.WriteAllText(filename, json);
Console.Out.WriteLine("Writing to " + filename);
coinsToDelete[c] = frackedFileName;
c++;
}
m1--;
// Get the clean JSON of the coin
}// end if coin is a 1
if (denomination == "5" && m5 > 0)
{
if ((c != 0))
{
json += ",\n";
}
if (File.Exists(bankFileName))
{
CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(bankFileName);
coinNote.aoid = null;//Clear all owner data
json = start + this.fileUtils.setJSON(coinNote) + end;
int randInt = random.Next(100000, 10000000);
filename = this.fileUtils.exportFolder + Path.DirectorySeparatorChar + coinNote.getDenomination() + ".CloudCoins." + randInt + ".stack";
File.WriteAllText(filename, json);
Console.Out.WriteLine("Writing to " + filename);
coinsToDelete[c] = bankFileName;
c++;
}
else
{
CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(frackedFileName);
coinNote.aoid = null;
json = start + this.fileUtils.setJSON(coinNote) + end;
int randInt = random.Next(100000, 10000000);
filename = this.fileUtils.exportFolder + Path.DirectorySeparatorChar + coinNote.getDenomination() + ".CloudCoins." + randInt + ".stack";
File.WriteAllText(filename, json);
Console.Out.WriteLine("Writing to " + filename);
coinsToDelete[c] = frackedFileName;
c++;
}
m5--;
} // end if coin is a 5
if (denomination == "25" && m25 > 0)
{
if ((c != 0))
{
json += ",\n";
}
if (File.Exists(bankFileName))
{
CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(bankFileName);
coinNote.aoid = null;//Clear all owner data
json = start + this.fileUtils.setJSON(coinNote) + end;
int randInt = random.Next(100000, 10000000);
filename = this.fileUtils.exportFolder + Path.DirectorySeparatorChar + coinNote.getDenomination() + ".CloudCoins." + randInt + ".stack";
File.WriteAllText(filename, json);
Console.Out.WriteLine("Writing to " + filename);
coinsToDelete[c] = bankFileName;
c++;
}
else
{
CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(frackedFileName);
coinNote.aoid = null;
json = start + this.fileUtils.setJSON(coinNote) + end;
int randInt = random.Next(100000, 10000000);
filename = this.fileUtils.exportFolder + Path.DirectorySeparatorChar + coinNote.getDenomination() + ".CloudCoins." + randInt + ".stack";
File.WriteAllText(filename, json);
Console.Out.WriteLine("Writing to " + filename);
coinsToDelete[c] = frackedFileName;
c++;
}
m25--;
}// end if coin is a 25
if (denomination == "100" && m100 > 0)
{
if ((c != 0))
{
json += ",\n";
}
if (File.Exists(bankFileName))
{
CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(bankFileName);
coinNote.aoid = null;//Clear all owner data
json = start + this.fileUtils.setJSON(coinNote) + end;
int randInt = random.Next(100000, 10000000);
filename = this.fileUtils.exportFolder + Path.DirectorySeparatorChar + coinNote.getDenomination() + ".CloudCoins." + randInt + ".stack";
File.WriteAllText(filename, json);
Console.Out.WriteLine("Writing to " + filename);
coinsToDelete[c] = bankFileName;
c++;
}
else
{
CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(frackedFileName);
coinNote.aoid = null;
json = start + this.fileUtils.setJSON(coinNote) + end;
int randInt = random.Next(100000, 10000000);
filename = this.fileUtils.exportFolder + Path.DirectorySeparatorChar + coinNote.getDenomination() + ".CloudCoins." + randInt + ".stack";
File.WriteAllText(filename, json);
Console.Out.WriteLine("Writing to " + filename);
coinsToDelete[c] = frackedFileName;
c++;
}
m100--;
} // end if coin is a 100
if (denomination == "250" && m250 > 0)
{
if ((c != 0))
{
json += ",\n";
}
if (File.Exists(bankFileName))
{
CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(bankFileName);
coinNote.aoid = null;//Clear all owner data
json = start + this.fileUtils.setJSON(coinNote) + end;
int randInt = random.Next(100000, 10000000);
filename = this.fileUtils.exportFolder + Path.DirectorySeparatorChar + coinNote.getDenomination() + ".CloudCoins." + randInt + ".stack";
File.WriteAllText(filename, json);
Console.Out.WriteLine("Writing to " + filename);
coinsToDelete[c] = bankFileName;
c++;
}
else
{
CloudCoin coinNote = this.fileUtils.loadOneCloudCoinFromJsonFile(frackedFileName);
coinNote.aoid = null;
json = start + this.fileUtils.setJSON(coinNote) + end;
int randInt = random.Next(100000, 10000000);
filename = this.fileUtils.exportFolder + Path.DirectorySeparatorChar + coinNote.getDenomination() + ".CloudCoins." + randInt + ".stack";
File.WriteAllText(filename, json);
Console.Out.WriteLine("Writing to " + filename);
coinsToDelete[c] = frackedFileName;
c++;
}
m250--;
}// end if coin is a 250
if (m1 == 0 && m5 == 0 && m25 == 0 && m100 == 0 && m250 == 0)
{
break;
} // Break if all the coins have been called for.
}// end for each coin needed
/*DELETE FILES THAT HAVE BEEN EXPORTED*/
for (int cc = 0; cc < coinsToDelete.Length; cc++)
{
// Console.Out.WriteLine("Deleting " + coinsToDelete[cc]);
if (coinsToDelete[cc] != null) { File.Delete(coinsToDelete[cc]); }
}//end for all coins to delete
// end if write was good
return jsonExported;
}//end write json to file
}//end class dump
}//end namespace