Exemplo n.º 1
0
        private async Task InitProcess()
        {
            await Task.Delay(500);

            try
            {
                // Initialize

                FindViewById <TextView>(Resource.Id.SplashAppVersion).Text = $"v{AppInfo.VersionString}({AppInfo.BuildString})";

                await ETC.AnimateText(statusText, "Initializing");

                if (Preferences.Get("CheckInitLowMemory", true))
                {
                    CheckDeviceMemory();
                }

                ETC.isLowRAM = Preferences.Get("LowMemoryOption", false);

                ETC.CheckInitFolder();


                // Check DB Update

                if (!CheckDBFiles())
                {
                    await ETC.AnimateText(statusText, "Download DB First");

                    try
                    {
                        await ETC.CheckServerNetwork();

                        if (!ETC.isServerDown)
                        {
                            await ETC.UpdateDB(this);
                        }
                        else
                        {
                            throw new Exception("Server is down");
                        }
                    }
                    catch (Exception ex)
                    {
                        ETC.LogError(ex, this);
                        Toast.MakeText(this, Resource.String.Splash_SkipCheckUpdate, ToastLength.Long).Show();
                    }
                }

                try
                {
                    int.TryParse(File.ReadAllText(Path.Combine(ETC.systemPath, "DBVer.txt")), out ETC.dbVersion);

                    //using (StreamReader sr = new StreamReader(new FileStream(, FileMode.Open, FileAccess.Read)))
                    //{
                    //    _ = int.TryParse(sr.ReadToEnd(), out ETC.dbVersion);
                    //}
                }
                catch
                {
                    ETC.dbVersion = 0;
                }


                // Finalize & Start Main

                StartActivity(typeof(Main));
                OverridePendingTransition(Android.Resource.Animation.SlideInLeft, Android.Resource.Animation.SlideOutRight);
                Finish();
            }
            catch (Exception ex)
            {
                ETC.LogError(ex, this);
                Toast.MakeText(this, Resource.String.InitLoad_Error, ToastLength.Long).Show();
            }
            finally
            {
                GC.Collect(GC.MaxGeneration, GCCollectionMode.Default, false, false);
            }
        }