forked from CloudCoinConsortium/PNG_Console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
168 lines (153 loc) · 6.08 KB
/
Program.cs
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
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Linq;
namespace AddToPng
{
///Class discriptions
// Program
// PngClass
// -Constructor
// -PngClass() , will prompt user to choose a png.
// -Accessors
// - string name
// - string path
// - string designator
// - int length
// - int count
// - int value
// - byte[] data
// - List <CoinClass> listOfCoins
// - List <CoinClass> listOfStagedCoins
// - bool hasCoins
// - bool hasStagedCoins
//
//
//
// CoinClass
// -Constructors
// -CoinClass(string pathToCloudCoin)
// -CoinClass(byte[] cloudCoinsByteFile)
// -Accessors
// - PngChunk .pngChunk = PngChunk(cloudcoin) easy access to the needed pngChunk.
// - string .name = The name of this coin. ie 250.CloudCoin.1.11111111.tag.Stack
// - string .path = Coins that are not in a png will have a path.
// - string .tag = Used for creating the Stack name.
// - string .val = Value of this Coin.
// - string .sn = This coins Serial number.
// - string .nn = This coins Network number.
// - int .length = The same as PngChunk.chunkLength
//
//
// PngChunk
// -Constructors
// -PngChunk(string pathToCloudCoin)
// -PngChunk(byte[] cloudCoinsByteFile)
// -Accessor
// -byte[] .chunk = the cloudCoinData ready to be inserted as a png chunk.
// -int .chunkLength = numeric representation of the chunk size.
//
class Program
{
Encoding FileEncoding = Encoding.ASCII;
private string[] status_;
public string [] status { get{ return status_; }
set { status_ = value; }
}//end
//Track activity
static void Main(string[] args)
{
Program prog = new Program();
prog.runProgram();
}
void runProgram()
{
Utils util = new Utils();
PngClass png = new PngClass(true);
bool makingChanges = true;
while (makingChanges)
{
int choice = 0;
try
{
setStatus(png);
choice = Utils.printOptions(); //Display user choices.
}
catch(Exception e)
{
Console.WriteLine("Exception: " + e);
}
switch (choice)
{
case 1://add new png.
png = new PngClass();
break;
case 2://select a png file.
png = new PngClass(true);
break;
case 3://select cloudcoins
png.stageCoins();
break;
case 4://insert cloudcoins to png ([byte[] data][string Names][int length])
if(png.hasStagedCoins)
png.SaveCoins();
png.updatePNG();
break;
case 5://retrieve cloudcoins from png
png.removeCoins();
break;
case 6://quit
makingChanges = false;//Select the png file.
break;
}
if(png.hasCoins){
}
}
}// end runProgram
private void setStatus(PngClass png){
//For saved coins.
string sCount = "0";
string sVal = "0";
if(png.hasCoins)
{
List<CoinClass> coinList = png.listOfCoins;
string[] hasCoinsStatus = new string[coinList.Count()];
int n = 0;
foreach(CoinClass coin in coinList){
hasCoinsStatus[n] = "Name: " + coin.name + "\r\n" + "Value: " + coin.strVal;
n++;
}//end foreach
}
//For staged coins.
string[] updateStagedCoins;
if(png.hasStagedCoins)
{
int stagedVal = 0;
int i = 0;
updateStagedCoins = new string[png.listOfStagedCoins.Count()];
foreach(CoinClass coin in png.listOfStagedCoins){
updateStagedCoins[i] = coin.name + ": ";
int temp = 0;
Int32.TryParse(coin.strVal, out temp);
stagedVal += temp;
i++;
}
sVal = stagedVal.ToString();
sCount = i.ToString();
// Utils.consolePrintList(updateStagedCoins, false, "Staged coins: ", false);
Console.WriteLine(" ----- ");
}else{
updateStagedCoins = new string[0];
}
status = new string[] {
"File: " + png.name +"."+png.tag,
"Coins found: " + png.count,
"Value of png: " + png.storedVal,
"Coins staged: " + sCount,
"Value of staged Coins: " + sVal
};
Utils.consolePrintList(status_, false, "Updates: ", false);
}//end status()
}
}