Exemplo n.º 1
0
 private void 打开钱包数据库OToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (OpenWalletDialog dialog = new OpenWalletDialog())
     {
         if (dialog.ShowDialog() != DialogResult.OK)
         {
             return;
         }
         if (UserWallet.GetVersion(dialog.WalletPath) < Version.Parse("1.3.5"))
         {
             if (MessageBox.Show(Strings.MigrateWalletMessage, Strings.MigrateWalletCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) != DialogResult.Yes)
             {
                 return;
             }
             string path_old = Path.ChangeExtension(dialog.WalletPath, ".old.db3");
             string path_new = Path.ChangeExtension(dialog.WalletPath, ".new.db3");
             UserWallet.Migrate(dialog.WalletPath, path_new);
             File.Move(dialog.WalletPath, path_old);
             File.Move(path_new, dialog.WalletPath);
             MessageBox.Show($"{Strings.MigrateWalletSucceedMessage}\n{path_old}");
         }
         UserWallet wallet;
         try
         {
             wallet = UserWallet.Open(dialog.WalletPath, dialog.Password);
         }
         catch (CryptographicException)
         {
             MessageBox.Show(Strings.PasswordIncorrect);
             return;
         }
         if (dialog.RepairMode)
         {
             wallet.Rebuild();
         }
         ChangeWallet(wallet);
         Settings.Default.LastWalletPath = dialog.WalletPath;
         Settings.Default.Save();
     }
 }
Exemplo n.º 2
0
 private void 打开钱包数据库OToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (OpenWalletDialog dialog = new OpenWalletDialog())
     {
         if (dialog.ShowDialog() != DialogResult.OK)
         {
             return;
         }
         string path = dialog.WalletPath;
         Wallet wallet;
         if (Path.GetExtension(path) == ".db3")
         {
             if (MessageBox.Show(Strings.MigrateWalletMessage, Strings.MigrateWalletCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
             {
                 string path_old = path;
                 path = Path.ChangeExtension(path_old, ".json");
                 NEP6Wallet nep6wallet;
                 try
                 {
                     nep6wallet = NEP6Wallet.Migrate(GetIndexer(), path, path_old, dialog.Password);
                 }
                 catch (CryptographicException)
                 {
                     MessageBox.Show(Strings.PasswordIncorrect);
                     return;
                 }
                 nep6wallet.Save();
                 nep6wallet.Unlock(dialog.Password);
                 wallet = nep6wallet;
                 MessageBox.Show($"{Strings.MigrateWalletSucceedMessage}\n{path}");
             }
             else
             {
                 try
                 {
                     wallet = UserWallet.Open(GetIndexer(), path, dialog.Password);
                 }
                 catch (CryptographicException)
                 {
                     MessageBox.Show(Strings.PasswordIncorrect);
                     return;
                 }
             }
         }
         else
         {
             NEP6Wallet nep6wallet = new NEP6Wallet(GetIndexer(), path);
             try
             {
                 nep6wallet.Unlock(dialog.Password);
             }
             catch (CryptographicException)
             {
                 MessageBox.Show(Strings.PasswordIncorrect);
                 return;
             }
             wallet = nep6wallet;
         }
         ChangeWallet(wallet);
         Settings.Default.LastWalletPath = path;
         Settings.Default.Save();
     }
 }