Exemple #1
0
        public override void OnBackPressed()
        {
            if (IsBooting == true)
            {
                return;
            }

            var ad = new AndroidX.AppCompat.App.AlertDialog.Builder(this, Resource.Style.GFD_Dialog);

            ad.SetTitle("ShutDown Zina OS");
            ad.SetMessage("Do you want to shutdown Zina OS?");
            ad.SetPositiveButton("Shutdown", delegate
            {
                IsBooting = true;
                _         = ShutdownZinaOS();
            });
            ad.SetNegativeButton("Cancel", delegate { });
            ad.SetCancelable(true);

            try
            {
                ad.Show();
            }
            catch (Exception ex)
            {
                ETC.LogError(ex, this);
            }
        }
        private async void Adapter_ItemClick(object sender, int e)
        {
            string pvFileName = pvList[e];

            try
            {
                if (!File.Exists(Path.Combine(pvPath, $"{pvFileName}.mp4")))
                {
                    var builder = new AndroidX.AppCompat.App.AlertDialog.Builder(this, ETC.dialogBG);
                    builder.SetTitle(Resource.String.GFPVActivity_DownloadRequireDialog_Title);
                    builder.SetMessage(Resource.String.GFPVActivity_DownloadRequireDialog_Message);
                    builder.SetCancelable(true);
                    builder.SetPositiveButton(Resource.String.AlertDialog_Download, async delegate { await PVDownload(pvFileName, e); });
                    builder.SetNegativeButton(Resource.String.AlertDialog_Cancel, delegate { });

                    builder.Show();
                }
                else
                {
                    await RunPV(Path.Combine(pvPath, $"{pvFileName}.mp4"));
                }
            }
            catch (Exception ex)
            {
                ETC.LogError(ex, this);
            }
        }
Exemple #3
0
        private async Task CheckUpdate()
        {
            await Task.Delay(100);

            bool isMissing = false;

            try
            {
                isMissing = CheckImage();

                if (!isMissing)
                {
                    using (WebClient wc = new WebClient())
                    {
                        string LocalVerPath = Path.Combine(ETC.systemPath, "ShortGuideVer.txt");

                        if (!File.Exists(LocalVerPath))
                        {
                            hasUpdate = true;
                        }
                        else
                        {
                            int serverVer = int.Parse(await wc.DownloadStringTaskAsync(Path.Combine(ETC.server, "ShortGuideVer.txt")));
                            int localVer  = 0;

                            using (StreamReader sr = new StreamReader(new FileStream(LocalVerPath, FileMode.Open, FileAccess.Read)))
                            {
                                localVer = int.Parse(sr.ReadToEnd());
                            }

                            hasUpdate = localVer < serverVer;
                        }
                    }
                }

                if (hasUpdate || isMissing)
                {
                    var builder = new AndroidX.AppCompat.App.AlertDialog.Builder(Activity);
                    builder.SetTitle(Resource.String.UpdateDialog_Title);
                    builder.SetMessage(Resource.String.UpdateDialog_Message);
                    builder.SetCancelable(true);
                    builder.SetPositiveButton(Resource.String.AlertDialog_Confirm, async delegate { await DownloadShortGuideImage(); });
                    builder.SetNegativeButton(Resource.String.AlertDialog_Cancel, delegate { });

                    var dialog = builder.Create();
                    dialog.Show();
                }
            }
            catch (Exception ex)
            {
                ETC.LogError(ex, Activity);
                ETC.ShowSnackbar(snackbarLayoutF, Resource.String.UpdateCheck_Fail, Snackbar.LengthLong, Android.Graphics.Color.DarkRed);
            }
        }
        internal void ShowDownloadCheckMessage <T>(List <T> downloadList, string serverPath, string targetPath)
        {
            var ad = new AndroidX.AppCompat.App.AlertDialog.Builder(this, ETC.dialogBG);

            ad.SetTitle(Resource.String.DBList_DownloadCropImageCheckTitle);
            ad.SetMessage(Resource.String.DBList_DownloadCropImageCheckMessage);
            ad.SetCancelable(true);
            ad.SetPositiveButton(Resource.String.AlertDialog_Download, delegate { _ = CropImageDownloadProcess(downloadList, serverPath, targetPath); });
            ad.SetNegativeButton(Resource.String.AlertDialog_Cancel, delegate { });

            ad.Show();
        }
Exemple #5
0
        public override void OnBackPressed()
        {
            var exitDialog = new AndroidX.AppCompat.App.AlertDialog.Builder(this, Resource.Style.GFD_Dialog);

            exitDialog.SetTitle(Resource.String.Main_CheckExitTitle);
            exitDialog.SetMessage(Resource.String.Main_CheckExit);
            exitDialog.SetCancelable(true);
            exitDialog.SetPositiveButton(Resource.String.AlertDialog_Exit, delegate
            {
                FinishAffinity();
                Process.KillProcess(Process.MyPid());
            });
            exitDialog.SetNegativeButton(Resource.String.AlertDialog_Cancel, delegate { });
            exitDialog.Show();
        }
        private void SelectCache()
        {
            string freeText    = Resources.GetString(Resource.String.SelectCache_FreeSpace);
            string requireText = Resources.GetString(Resource.String.SelectCache_RequireSpace);

            if (categoryCheck == null)
            {
                categoryCheck = new Dictionary <CacheCategory, bool>();
            }

            categoryCheck.Clear();

            cacheSelectView = LayoutInflater.Inflate(Resource.Layout.CacheSelectLayout, null);

            cacheSelectView.FindViewById <XTextView>(Resource.Id.CacheSelectNowFreeSpace).Text                = $"{freeText} : {freeSize}MB";
            cacheSelectView.FindViewById <XTextView>(Resource.Id.CacheSelectRequireSpace).Text                = $"{requireText} : {expectSize}MB";
            cacheSelectView.FindViewById <XCheckBox>(Resource.Id.CacheSelectCategoryDic).CheckedChange       += CacheSelectCategory_CheckedChange;
            cacheSelectView.FindViewById <XCheckBox>(Resource.Id.CacheSelectCategoryOldGFD).CheckedChange    += CacheSelectCategory_CheckedChange;
            cacheSelectView.FindViewById <XCheckBox>(Resource.Id.CacheSelectCategoryGuideBook).CheckedChange += CacheSelectCategory_CheckedChange;
            cacheSelectView.FindViewById <XCheckBox>(Resource.Id.CacheSelectCategoryStory).CheckedChange     += CacheSelectCategory_CheckedChange;
            cacheSelectView.FindViewById <XCheckBox>(Resource.Id.CacheSelectCategoryPV).CheckedChange        += CacheSelectCategory_CheckedChange;
            cacheSelectView.FindViewById <XCheckBox>(Resource.Id.CacheSelectCategoryOST).CheckedChange       += CacheSelectCategory_CheckedChange;
            //cacheSelectView.FindViewById<XCheckBox>(Resource.Id.CacheSelectCategoryCartoon).CheckedChange += CacheSelectCategory_CheckedChange;

            var ad = new AndroidX.AppCompat.App.AlertDialog.Builder(Activity, ETC.dialogBG);

            ad.SetTitle(Resource.String.SelectCache_Dialog_Title);
            ad.SetCancelable(true);
            ad.SetNegativeButton(Resource.String.AlertDialog_Cancel, delegate { });
            ad.SetPositiveButton(Resource.String.AlertDialog_Confirm, async delegate
            {
                categoryCheck.Add(CacheCategory.Dic, cacheSelectView.FindViewById <XCheckBox>(Resource.Id.CacheSelectCategoryDic).Checked);
                categoryCheck.Add(CacheCategory.OldGFD, cacheSelectView.FindViewById <XCheckBox>(Resource.Id.CacheSelectCategoryOldGFD).Checked);
                categoryCheck.Add(CacheCategory.GuideBook, cacheSelectView.FindViewById <XCheckBox>(Resource.Id.CacheSelectCategoryGuideBook).Checked);
                categoryCheck.Add(CacheCategory.Story, cacheSelectView.FindViewById <XCheckBox>(Resource.Id.CacheSelectCategoryStory).Checked);
                categoryCheck.Add(CacheCategory.PV, cacheSelectView.FindViewById <XCheckBox>(Resource.Id.CacheSelectCategoryPV).Checked);
                categoryCheck.Add(CacheCategory.OST, cacheSelectView.FindViewById <XCheckBox>(Resource.Id.CacheSelectCategoryOST).Checked);
                //categoryCheck.Add(CacheCategory.Cartoon, cacheSelectView.FindViewById<XCheckBox>(Resource.Id.CacheSelectCategoryCartoon).Checked);

                await DownloadAllCache();
            });
            ad.SetView(cacheSelectView);

            var dialog = ad.Show();
        }
Exemple #7
0
        internal async Task DownloadGFDImage()
        {
            View v = LayoutInflater.Inflate(Resource.Layout.ProgressDialogLayout, null);

            ProgressBar totalProgressBar = v.FindViewById <ProgressBar>(Resource.Id.TotalProgressBar);
            TextView    totalProgress    = v.FindViewById <TextView>(Resource.Id.TotalProgressPercentage);
            ProgressBar nowProgressBar   = v.FindViewById <ProgressBar>(Resource.Id.NowProgressBar);
            TextView    nowProgress      = v.FindViewById <TextView>(Resource.Id.NowProgressPercentage);

            var builder = new AndroidX.AppCompat.App.AlertDialog.Builder(Activity, ETC.dialogBGDownload);

            builder.SetTitle(Resource.String.UpdateDownloadDialog_Title);
            builder.SetView(v);
            builder.SetCancelable(false);

            Dialog dialog = builder.Create();

            dialog.Show();

            await Task.Delay(100);

            try
            {
                totalProgressBar.Max      = imageName.Length;
                totalProgressBar.Progress = 0;

                using (WebClient wc = new WebClient())
                {
                    wc.DownloadFileCompleted += (object sender, System.ComponentModel.AsyncCompletedEventArgs e) =>
                    {
                        totalProgressBar.Progress += 1;
                        totalProgress.Text         = $"{totalProgressBar.Progress} / {totalProgressBar.Max}";
                    };
                    wc.DownloadProgressChanged += (object sender, DownloadProgressChangedEventArgs e) =>
                    {
                        nowProgressBar.Progress = e.ProgressPercentage;
                        nowProgress.Text        = $"{e.BytesReceived / 1024}KB";
                    };

                    foreach (string s in imageName)
                    {
                        string url    = Path.Combine(ETC.server, "Data", "Images", "OldGFD", "Images", lang, $"{s}.png");
                        string target = Path.Combine(ETC.cachePath, "OldGFD", "Images", $"{lang}_{s}.gfdcache");

                        await wc.DownloadFileTaskAsync(url, target);
                    }

                    wc.DownloadFile(Path.Combine(ETC.server, "OldGFDVer.txt"), Path.Combine(ETC.systemPath, "OldGFDVer.txt"));
                }

                ETC.ShowSnackbar(snackbarLayout_F, Resource.String.UpdateDownload_Complete, Snackbar.LengthLong, Android.Graphics.Color.DarkOliveGreen);
            }
            catch (Exception ex)
            {
                ETC.LogError(ex, Activity);
                ETC.ShowSnackbar(snackbarLayout_F, Resource.String.UpdateDownload_Fail, Snackbar.LengthLong, Android.Graphics.Color.DarkRed);
            }
            finally
            {
                dialog.Dismiss();
            }

            await Task.Delay(100);
        }
        private async Task PVDownload(string pvName, int position)
        {
            Dialog dialog = null;

            try
            {
                ProgressBar nowProgressBar;
                TextView    nowProgress;

                View v = LayoutInflater.Inflate(Resource.Layout.ProgressDialogLayout, null);

                v.FindViewById <TextView>(Resource.Id.ProgressStatusMessage).SetText(Resource.String.GFPVActivity_DownloadDialog_Message);
                v.FindViewById <TextView>(Resource.Id.ProgressNowFile).Text = pvName;
                v.FindViewById <LinearLayout>(Resource.Id.TotalProgressLayout).Visibility = ViewStates.Gone;

                nowProgressBar = v.FindViewById <ProgressBar>(Resource.Id.NowProgressBar);
                nowProgress    = v.FindViewById <TextView>(Resource.Id.NowProgressPercentage);

                var pd = new AndroidX.AppCompat.App.AlertDialog.Builder(this, ETC.dialogBGDownload);
                pd.SetTitle(Resource.String.GFPVActivity_DownloadDialog_Title);
                pd.SetCancelable(false);
                pd.SetView(v);

                dialog = pd.Create();
                dialog.Show();

                string localPath  = Path.Combine(pvPath, $"{pvName}.mp4");
                string serverPath = Path.Combine(ETC.server, "Data", "Video", "PV", $"{pvName}.mp4");

                using (var wc = new WebClient())
                {
                    wc.DownloadProgressChanged += (sender, e) =>
                    {
                        MainThread.BeginInvokeOnMainThread(() =>
                        {
                            nowProgressBar.Progress = e.ProgressPercentage;
                            nowProgress.Text        = $"{e.ProgressPercentage}%";
                        });
                    };
                    wc.DownloadFileCompleted += (sender, e) =>
                    {
                        MainThread.BeginInvokeOnMainThread(() =>
                        {
                            nowProgressBar.Progress = 100;
                            nowProgress.Text        = "100%";
                        });
                    };

                    await wc.DownloadFileTaskAsync(serverPath, localPath);
                }

                await Task.Delay(500);

                recyclerView.GetAdapter().NotifyItemChanged(position);
            }
            catch (Exception ex)
            {
                ETC.LogError(ex, this);
            }
            finally
            {
                dialog?.Dismiss();
            }
        }
        private async Task CropImageDownloadProcess <T>(List <T> downloadList, string serverPath, string targetPath)
        {
            Dialog      dialog;
            ProgressBar totalProgressBar;
            ProgressBar nowProgressBar;
            TextView    totalProgress;
            TextView    nowProgress;

            var v = LayoutInflater.Inflate(Resource.Layout.ProgressDialogLayout, null);

            int pNow   = 0;
            int pTotal = 0;

            var pd = new AndroidX.AppCompat.App.AlertDialog.Builder(this, ETC.dialogBGDownload);

            pd.SetTitle(Resource.String.DBList_DownloadCropImageTitle);
            pd.SetCancelable(false);
            pd.SetView(v);

            dialog = pd.Create();
            dialog.Show();

            try
            {
                totalProgressBar = v.FindViewById <ProgressBar>(Resource.Id.TotalProgressBar);
                totalProgress    = v.FindViewById <TextView>(Resource.Id.TotalProgressPercentage);
                nowProgressBar   = v.FindViewById <ProgressBar>(Resource.Id.NowProgressBar);
                nowProgress      = v.FindViewById <TextView>(Resource.Id.NowProgressPercentage);

                pTotal = downloadList.Count;
                totalProgressBar.Max      = 100;
                totalProgressBar.Progress = pNow;

                using (var wc = new WebClient())
                {
                    wc.DownloadProgressChanged += (sender, e) =>
                    {
                        nowProgressBar.Progress = e.ProgressPercentage;

                        MainThread.BeginInvokeOnMainThread(() => { nowProgress.Text = $"{e.ProgressPercentage}%"; });
                    };
                    wc.DownloadFileCompleted += (sender, e) =>
                    {
                        pNow += 1;
                        totalProgressBar.Progress = Convert.ToInt32((pNow / Convert.ToDouble(pTotal)) * 100);

                        MainThread.BeginInvokeOnMainThread(() => { totalProgress.Text = $"{totalProgressBar.Progress}%"; });
                    };

                    for (int i = 0; i < pTotal; ++i)
                    {
                        string url    = Path.Combine(serverPath, $"{downloadList[i]}.png");
                        string target = Path.Combine(targetPath, $"{downloadList[i]}.gfdcache");

                        await wc.DownloadFileTaskAsync(url, target);
                    }
                }

                ETC.ShowSnackbar(snackbarLayout, Resource.String.DBList_DownloadCropImageComplete, Snackbar.LengthLong, Android.Graphics.Color.DarkOliveGreen);

                await Task.Delay(500);

                _ = ListItem();
            }
            catch (Exception ex)
            {
                ETC.LogError(ex, this);
                ETC.ShowSnackbar(snackbarLayout, Resource.String.DBList_DownloadCropImageFail, Snackbar.LengthShort, Android.Graphics.Color.DeepPink);
            }
            finally
            {
                dialog.Dismiss();
            }
        }
        private async Task DownloadAllCache()
        {
            var downloadURLs = new List <(string source, string target)>();

            var v = LayoutInflater.Inflate(Resource.Layout.SpinnerProgressDialogLayout, null);

            var ad = new AndroidX.AppCompat.App.AlertDialog.Builder(Activity, ETC.dialogBG);
            var pd = new AndroidX.AppCompat.App.AlertDialog.Builder(Activity, ETC.dialogBGDownload);

            pd.SetTitle(Resource.String.SettingActivity_DownloadAllCache_DialogTitle);
            pd.SetMessage(Resource.String.SettingActivity_DownloadAllCache_DialogMessage);
            pd.SetCancelable(false);
            pd.SetView(v);

            var dialog = pd.Show();

            try
            {
                var statusText = v.FindViewById <TextView>(Resource.Id.SpinnerProgressStatusMessage);

                statusText.Text = "Ready download list...";

                await Task.Delay(100);

                var listThread = new Thread(new ThreadStart(delegate
                {
                    if (categoryCheck[CacheCategory.Dic])
                    {
                        ListDoll(downloadURLs);
                        ListEquip(downloadURLs);
                        ListFairy(downloadURLs);
                        ListEnemy(downloadURLs);
                        ListFST(downloadURLs);
                        ListCoalition(downloadURLs);
                        ListSkill(downloadURLs);
                    }
                    if (categoryCheck[CacheCategory.OldGFD])
                    {
                        ListOldGFD(downloadURLs);
                    }
                    if (categoryCheck[CacheCategory.GuideBook])
                    {
                        ListGuideBook(downloadURLs);
                    }
                    if (categoryCheck[CacheCategory.Story])
                    {
                        ListStory(downloadURLs);
                    }
                    if (categoryCheck[CacheCategory.PV])
                    {
                        ListPV(downloadURLs);
                    }
                    if (categoryCheck[CacheCategory.OST])
                    {
                        ListMusic(downloadURLs);
                    }

                    /*if (categoryCheck[CacheCategory.Cartoon])
                     * {
                     *  ListCartoon(downloadURLs);
                     * }*/
                }));

                listThread.Start();
                listThread.Join();

                using (var wc = new WebClient())
                {
                    var now   = 0;
                    var total = downloadURLs.Count;

                    wc.DownloadFileCompleted += (sender, e) => { statusText.Text = $"{++now}/{total}"; };

                    foreach (var(source, target) in downloadURLs)
                    {
                        try
                        {
                            await wc.DownloadFileTaskAsync(source, target);
                        }
                        catch
                        {
                            statusText.Text += " Retry";
                            await wc.DownloadFileTaskAsync(source, target);
                        }
                    }
                }

                Toast.MakeText(Activity, Resource.String.SettingActivity_DownloadAllCache_CompleteDialogMessage, ToastLength.Short).Show();
            }
            catch (Exception ex)
            {
                Toast.MakeText(Activity, Resource.String.SettingActivity_DownloadAllCache_FailDialogMessage, ToastLength.Short).Show();
            }
            finally
            {
                dialog.Dismiss();
            }
        }
Exemple #11
0
        internal static async Task UpdateDB(Activity activity, bool dbLoad = false, int titleMsg = Resource.String.CheckDBUpdateDialog_Title, int messageMgs = Resource.String.CheckDBUpdateDialog_Message)
        {
            Dialog dialog;
            View   v = activity.LayoutInflater.Inflate(Resource.Layout.ProgressDialogLayout, null);

            TextView    status           = v.FindViewById <TextView>(Resource.Id.ProgressStatusMessage);
            ProgressBar totalProgressBar = v.FindViewById <ProgressBar>(Resource.Id.TotalProgressBar);
            TextView    totalProgress    = v.FindViewById <TextView>(Resource.Id.TotalProgressPercentage);
            ProgressBar nowProgressBar   = v.FindViewById <ProgressBar>(Resource.Id.NowProgressBar);
            TextView    nowProgress      = v.FindViewById <TextView>(Resource.Id.NowProgressPercentage);

            var pd = new AndroidX.AppCompat.App.AlertDialog.Builder(activity, dialogBGDownload);

            pd.SetTitle(titleMsg);
            pd.SetMessage(Resources.GetString(messageMgs));
            pd.SetView(v);
            pd.SetCancelable(false);

            dialog = pd.Create();
            dialog.Show();

            await Task.Delay(100);

            try
            {
                totalProgressBar.Max      = dbFiles.Length;
                totalProgressBar.Progress = 0;

                using (WebClient wc = new WebClient())
                {
                    wc.DownloadProgressChanged += (object sender, DownloadProgressChangedEventArgs e) =>
                    {
                        nowProgressBar.Progress = e.ProgressPercentage;
                        nowProgress.Text        = (e.BytesReceived > 2048) ? $"{e.BytesReceived / 1024}KB" : $"{e.BytesReceived}B";
                    };
                    wc.DownloadFileCompleted += (object sender, System.ComponentModel.AsyncCompletedEventArgs e) =>
                    {
                        totalProgressBar.Progress += 1;
                        totalProgress.Text         = $"{totalProgressBar.Progress} / {totalProgressBar.Max}";
                    };

                    for (int i = 0; i < dbFiles.Length; ++i)
                    {
                        await wc.DownloadFileTaskAsync(Path.Combine(server, "Data", "DB", dbFiles[i]), Path.Combine(tempPath, dbFiles[i]));
                    }

                    await wc.DownloadFileTaskAsync(Path.Combine(server, "DBVer.txt"), Path.Combine(tempPath, "DBVer.txt"));

                    await Task.Delay(100);
                }

                for (int i = 0; i < dbFiles.Length; ++i)
                {
                    //File.Copy(Path.Combine(tempPath, DBFiles[i]), Path.Combine(DBPath, DBFiles[i]), true);
                    CopyFile(Path.Combine(tempPath, dbFiles[i]), Path.Combine(dbPath, dbFiles[i]));

                    await Task.Delay(100);
                }

                await Task.Delay(500);

                activity.RunOnUiThread(() => { status.Text = Resources.GetString(Resource.String.UpdateDBDialog_RefreshVersionMessage); });

                string oldVersion = Path.Combine(systemPath, "DBVer.txt");
                string newVersion = Path.Combine(tempPath, "DBVer.txt");

                //File.Copy(newVersion, oldVersion, true);
                CopyFile(newVersion, oldVersion);

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

                await Task.Delay(500);

                if (dbLoad)
                {
                    activity.RunOnUiThread(() => { status.Text = Resources.GetString(Resource.String.UpdateDBDialog_LoadDB); });

                    await Task.Delay(100);
                    await LoadDB();
                }
            }
            catch (Exception ex)
            {
                LogError(ex, activity);
            }
            finally
            {
                dialog.Dismiss();
            }
        }
Exemple #12
0
        /// <summary>
        /// Check DB version & Refresh notification data
        /// </summary>
        private async Task CheckNetworkData()
        {
            await Task.Delay(100);

            //tv.Text = $"DB Ver.{ETC.dbVersion} ({Resources.GetString(Resource.String.Main_DBChecking)})";

            try
            {
                // Check Server Status


                /*await Task.Run(async () =>
                 * {
                 *  // Check DB Version
                 *
                 *  if (await ETC.CheckDBVersion())
                 *  {
                 *      //RunOnUiThread(() => { tv.Text = $"DB Ver.{ETC.dbVersion} ({Resources.GetString(Resource.String.Main_DBUpdateAvailable)})"; });
                 *
                 *      var ad = new Android.Support.V7.App.AlertDialog.Builder(this, ETC.dialogBG);
                 *      ad.SetTitle(Resource.String.CheckDBUpdateDialog_Title);
                 *      ad.SetMessage(Resource.String.CheckDBUpdateDialog_Question);
                 *      ad.SetCancelable(true);
                 *      ad.SetNegativeButton(Resource.String.AlertDialog_Cancel, delegate { });
                 *      ad.SetPositiveButton(Resource.String.AlertDialog_Confirm, async delegate
                 *      {
                 *          await ETC.UpdateDB(this, true);
                 *
                 *          if (!await ETC.CheckDBVersion())
                 *          {
                 *              //RunOnUiThread(() => { tv.Text = $"DB Ver.{ETC.dbVersion} ({Resources.GetString(Resource.String.Main_DBUpdateNewest)})"; });
                 *          }
                 *          else
                 *          {
                 *              //RunOnUiThread(() => { tv.Text = $"DB Ver.{ETC.dbVersion} ({Resources.GetString(Resource.String.Main_DBUpdateAvailable)})"; });
                 *          }
                 *
                 *      });
                 *
                 *      RunOnUiThread(() => { ad.Show(); });
                 *  }
                 *  else
                 *  {
                 *      //RunOnUiThread(() => { tv.Text = $"DB Ver.{ETC.dbVersion} ({Resources.GetString(Resource.String.Main_DBUpdateNewest)})"; });
                 *  }
                 * });*/

                if (await ETC.CheckDBVersion())
                {
                    //RunOnUiThread(() => { tv.Text = $"DB Ver.{ETC.dbVersion} ({Resources.GetString(Resource.String.Main_DBUpdateAvailable)})"; });

                    var ad = new AndroidX.AppCompat.App.AlertDialog.Builder(this, ETC.dialogBG);
                    ad.SetTitle(Resource.String.CheckDBUpdateDialog_Title);
                    ad.SetMessage(Resource.String.CheckDBUpdateDialog_Question);
                    ad.SetCancelable(true);
                    ad.SetNegativeButton(Resource.String.AlertDialog_Cancel, delegate { });
                    ad.SetPositiveButton(Resource.String.AlertDialog_Confirm, async delegate
                    {
                        await ETC.UpdateDB(this, true);

                        if (!await ETC.CheckDBVersion())
                        {
                            //RunOnUiThread(() => { tv.Text = $"DB Ver.{ETC.dbVersion} ({Resources.GetString(Resource.String.Main_DBUpdateNewest)})"; });
                        }
                        else
                        {
                            //RunOnUiThread(() => { tv.Text = $"DB Ver.{ETC.dbVersion} ({Resources.GetString(Resource.String.Main_DBUpdateAvailable)})"; });
                        }
                    });

                    RunOnUiThread(() => { ad.Show(); });
                }
                else
                {
                    //RunOnUiThread(() => { tv.Text = $"DB Ver.{ETC.dbVersion} ({Resources.GetString(Resource.String.Main_DBUpdateNewest)})"; });
                }
            }
            catch (Exception ex)
            {
                ETC.LogError(ex, this);
                ETC.ShowSnackbar(snackbarLayout, Resource.String.Main_NotificationInitializeFail, Snackbar.LengthLong, Android.Graphics.Color.DarkRed);
            }
        }
Exemple #13
0
        private async Task UpdateEvent()
        {
            View v = LayoutInflater.Inflate(Resource.Layout.ProgressDialogLayout, null);

            ProgressBar totalProgressBar = v.FindViewById <ProgressBar>(Resource.Id.TotalProgressBar);
            TextView    totalProgress    = v.FindViewById <TextView>(Resource.Id.TotalProgressPercentage);
            ProgressBar nowProgressBar   = v.FindViewById <ProgressBar>(Resource.Id.NowProgressBar);
            TextView    nowProgress      = v.FindViewById <TextView>(Resource.Id.NowProgressPercentage);

            var pd = new AndroidX.AppCompat.App.AlertDialog.Builder(this, ETC.dialogBGDownload);

            pd.SetTitle(Resource.String.UpdateEventDialog_Title);
            pd.SetMessage(Resources.GetString(Resource.String.UpdateEventDialog_Message));
            pd.SetView(v);
            pd.SetCancelable(false);

            Dialog dialog = pd.Create();

            dialog.Show();

            await Task.Delay(100);

            try
            {
                nowProgressBar.Indeterminate   = true;
                totalProgressBar.Indeterminate = true;

                if (!Directory.Exists(ETC.tempPath))
                {
                    Directory.CreateDirectory(ETC.tempPath);
                }
                if (!Directory.Exists(Path.Combine(ETC.cachePath, "Event", "Images")))
                {
                    Directory.CreateDirectory(Path.Combine(ETC.cachePath, "Event", "Images"));
                }

                using (WebClient wc = new WebClient())
                {
                    string url    = Path.Combine(ETC.server, "EventVer.txt");
                    string target = Path.Combine(ETC.tempPath, "EventVer.txt");

                    await wc.DownloadFileTaskAsync(url, target);

                    await Task.Delay(500);

                    nowProgressBar.Indeterminate   = false;
                    totalProgressBar.Indeterminate = false;
                    totalProgressBar.Progress      = 0;

                    wc.DownloadProgressChanged += (sender, e) =>
                    {
                        nowProgressBar.Progress = e.ProgressPercentage;
                        nowProgress.Text        = e.BytesReceived > 2048 ? $"{e.BytesReceived / 1024}KB" : $"{e.BytesReceived}B";
                    };
                    wc.DownloadFileCompleted += (sender, e) =>
                    {
                        totalProgressBar.Progress += 1;
                        totalProgress.Text         = $"{totalProgressBar.Progress} / {totalProgressBar.Max}";
                    };

                    int totalCount = 0;

                    using (StreamReader sr = new StreamReader(new FileStream(Path.Combine(ETC.tempPath, "EventVer.txt"), FileMode.Open, FileAccess.Read)))
                    {
                        totalCount += int.Parse(sr.ReadToEnd().Split(';')[2]);
                    }

                    totalProgressBar.Max = totalCount;

                    for (int i = 1; i <= totalCount; ++i)
                    {
                        string url2    = Path.Combine(ETC.server, "Data", "Images", "Events", "Event_" + i + ".png");
                        string target2 = Path.Combine(ETC.cachePath, "Event", "Images", "Event_" + i + ".png");

                        await wc.DownloadFileTaskAsync(url2, target2);

                        await Task.Delay(100);
                    }

                    await Task.Delay(500);

                    RunOnUiThread(() => { pd.SetMessage(Resources.GetString(Resource.String.UpdateEventDialog_RefreshVersionMessage)); });

                    string oldVersion = Path.Combine(ETC.cachePath, "Event", "EventVer.txt");
                    string newVersion = Path.Combine(ETC.tempPath, "EventVer.txt");

                    ETC.CopyFile(newVersion, oldVersion);

                    await Task.Delay(1000);
                }
            }
            catch (Exception ex)
            {
                ETC.LogError(ex, this);
            }
            finally
            {
                dialog.Dismiss();
            }
        }