Пример #1
0
 static public bool generateWallet(string pass)
 {
     if (IxianHandler.getWalletList().Count == 0)
     {
         WalletStorage ws = new WalletStorage(Path.Combine(Config.spixiUserFolder, Config.walletFile));
         if (ws.generateWallet(pass))
         {
             return(IxianHandler.addWallet(ws));
         }
     }
     return(false);
 }
Пример #2
0
        public static string startingScreen = ""; // Which screen to start on

        private App()
        {
            InitializeComponent();

            // Fix for issue https://github.com/xamarin/Xamarin.Forms/issues/10712#issuecomment-629394090
            Device.SetFlags(new string[] { "anything" });

            // check if already started
            if (Node.Instance == null)
            {
                // Prepare the personal folder
                if (!Directory.Exists(Config.spixiUserFolder))
                {
                    Directory.CreateDirectory(Config.spixiUserFolder);
                }

                // Init logging
                Logging.setOptions(5, 1, true);
                Logging.start(Config.spixiUserFolder);
                Logging.info(string.Format("Starting Spixi {0} ({1})", Config.version, CoreConfig.version));

                // Init fatal exception handlers
                AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
                TaskScheduler.UnobservedTaskException      += TaskSchedulerOnUnobservedTaskException;

                // Load or generate a device ID.
                if (Application.Current.Properties.ContainsKey("uid"))
                {
                    byte[] uid = Application.Current.Properties["uid"] as byte[];
                    if (uid == null)
                    {
                        // Generate and save the device ID
                        Application.Current.Properties["uid"] = CoreConfig.device_id;
                    }
                    else
                    {
                        CoreConfig.device_id = uid;
                    }
                }
                else
                {
                    // Generate and save the device ID
                    Application.Current.Properties["uid"] = CoreConfig.device_id;
                }

                if (Application.Current.Properties.ContainsKey("language"))
                {
                    if (!SpixiLocalization.loadLanguage(Application.Current.Properties["language"] as string))
                    {
                        Application.Current.Properties["language"] = SpixiLocalization.getCurrentLanguage();
                        Application.Current.SavePropertiesAsync();  // Force-save properties for compatibility with WPF
                    }
                }
                else
                {
                    string lang = CultureInfo.CurrentCulture.Name.ToLower();
                    if (SpixiLocalization.loadLanguage(lang))
                    {
                        Xamarin.Forms.Application.Current.Properties["language"] = SpixiLocalization.getCurrentLanguage();
                        Xamarin.Forms.Application.Current.SavePropertiesAsync();  // Force-save properties for compatibility with WPF
                    }
                }

                movePersonalFiles();

                // Load theme and appearance
                OSAppTheme currentTheme = Application.Current.RequestedTheme;
                Current.UserAppTheme = currentTheme;
                ThemeAppearance themeAppearance = ThemeAppearance.automatic;
                if (Application.Current.Properties.ContainsKey("appearance"))
                {
                    themeAppearance = (ThemeAppearance)Current.Properties["appearance"];
                }
                ThemeManager.loadTheme("spixiui", themeAppearance);
                Current.RequestedThemeChanged += (s, a) =>
                {
                    // Respond to the theme change
                    Current.UserAppTheme = a.RequestedTheme;
                    if (ThemeManager.getActiveAppearance() == ThemeAppearance.automatic)
                    {
                        ThemeManager.changeAppearance(ThemeAppearance.automatic);
                    }

                    UIHelpers.reloadAllPages();
                };

                // Start Ixian code
                node = new Node();

                // Attempt to load a pre-existing wallet
                bool wallet_found = Node.checkForExistingWallet();

                if (!wallet_found)
                {
                    // Wallet not found, go to initial launch page
                    MainPage = new NavigationPage(new SPIXI.LaunchPage());
                }
                else
                {
                    // Wallet found, see if it can be decrypted
                    bool wallet_decrypted = IxianHandler.getWalletList().Count > 0 ? IxianHandler.getWalletStorage().isLoaded() : false;
                    if (!wallet_decrypted)
                    {
                        wallet_decrypted = Node.loadWallet();
                    }

                    if (wallet_decrypted == false)
                    {
                        MainPage = new NavigationPage(new SPIXI.LaunchRetryPage());
                    }
                    else
                    {
                        // Wallet found

                        if (isLockEnabled())
                        {
                            // Show the lock screen
                            MainPage = new NavigationPage(new SPIXI.LockPage());
                        }
                        else
                        {
                            // Show the home screen
                            MainPage = new NavigationPage(HomePage.Instance());
                        }
                    }
                }
                NavigationPage.SetHasNavigationBar(MainPage, false);
            }
            else
            {
                // Already started before
                node = Node.Instance;
            }
        }