private void Window_Loaded(object sender, RoutedEventArgs e)
{
MenuModeFull.Tag = EEngMode.Bootstrap;
MenuModeLite.Tag = EEngMode.Lite;
LvWallet.ItemsSource = ActiveWalletForms;
LvEvent.ItemsSource = WalletEvents;
var port = UserAppRegistryKey.GetValue("LocalPort");
if (port != null)
{
try {
Eng.LocalPort = Convert.ToUInt16(port);
} catch (Exception) {
}
}
var proxyType = UserAppRegistryKey.GetValue("ProxyType");
if (proxyType != null)
{
try {
Eng.ProxyString = ToProxyString(Convert.ToString(proxyType), Convert.ToString(UserAppRegistryKey.GetValue("ProxyEndPoint")));
} catch (Exception) {
}
}
if (App.Testnet)
{
Eng.Testnet = App.Testnet;
}
Wallet[] wallets = null;
try {
wallets = Eng.Wallets;
} catch (Exception x) {
MessageBox.Show(x.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
Application.Current.Shutdown();
return;
}
foreach (var wallet in wallets)
{
string currencyName = wallet.CurrencyName;
var wf = new WalletForms();
wf.Wallet = wallet;
MenuItem mi = new MenuItem();
wf.MenuItem = mi;
mi.Header = $"{wallet.CurrencySymbol} {currencyName}";
mi.Icon = new Image()
{
Source = new BitmapImage(new Uri($"images/{Regex.Replace(currencyName, @"-testnet\d?", "")}.ico", UriKind.Relative))
};
menuCurrency.Items.Add(mi);
mi.Template = menuTemplate;
mi.IsCheckable = true;
mi.Tag = wf;
mi.Checked += Currency_CheckChanged;
mi.Unchecked += Currency_CheckChanged;
m_wallet2forms[wallet] = wf;
EEngMode mode = EEngMode.Bootstrap;
bool bMiningEnabled = false;
var sk = UserAppRegistryKey.OpenSubKey(wf.Wallet.CurrencySymbol);
if (sk != null)
{
switch ((string)sk.GetValue("DBMode"))
{
case "Bootstrap": mode = EEngMode.Bootstrap; break;
case "Lite": mode = EEngMode.Lite; break;
}
try {
// bMiningEnabled = (int)sk.GetValue("Mining", 0) != 0;
} catch (Exception) { }
}
wallet.Mode = mode;
if (wallet.MiningAllowed)
{
wallet.MiningEnabled = bMiningEnabled;
}
}
timer1.Tick += (s, e1) => {
bool b = false;
foreach (var wf in ActiveWalletForms)
{
b |= wf.CheckForChanges();
}
if (b)
{
UpdateView();
}
};
timer1.Start();
List <WalletForms> ar = new List <WalletForms>();
var obj = UserAppRegistryKey.GetValue("ActiveCurrencies", null);
if (obj == null)
{
ar = (from de in m_wallet2forms select de.Value).Take(2).ToList();
//!!!R foreach (var de in m_wallet2forms)
//!!!R ar.Add(de.Value);
}
else
{
foreach (var name in (string[])obj)
{
try {
WalletForms wf = null;
foreach (var pp in m_wallet2forms)
{
if (pp.Key.CurrencyName == name)
{
wf = pp.Value;
break;
}
}
if (wf != null)
{
ar.Add(wf);
}
} catch (Exception) {
}
}
}
foreach (var wf in ar)
{
try {
wf.MenuItem.IsChecked = true;
} catch (Exception ex) {
MessageBox.Show(ex.Message, "Coin", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
m_Loaded = true;
UpdateView();
CheckForCommands();
if (LvWallet.SelectedItem == null && LvWallet.Items.Count == 1)
{
LvWallet.SelectedIndex = 0;
}
// RegisterUriHandler();
}