Example #1
0
        public async void checkUpdateFromServer(string url)
        {
            //bool xx = File.Exists("ms-appdata:///local//www/index.html");
            //bool c = xx;
            //bool cc = xx;
            // deleteFolder("www");
            //        temp_activity.runOnUiThread(new Runnable()
            //        {
            //        public void run()
            //    {
            //        progressDialogx = ProgressDialog.show(temp_activity, "Check Update", "Please Wait...", true, true);

            //        //Callback here DOES NOT WORK
            //        //callbackContext.success(new JSONObject());
            //    };
            //});


            bool iSInternetAvilable = await SV.check_internet_connection_hard();

            iSInternetAvilable = true;
            bool isExternalFolder = CheckIfExtractFolder();

            if (!iSInternetAvilable && !isExternalFolder)
            {
                // progressDialogx.dismiss();

                EventForcheckUpdateResult("success", "1,No internet connection, no external folder so load index from assets then hide splash screen"); // Thread-safe.
                return;
            }

            else if (!iSInternetAvilable && isExternalFolder)
            {
                // progressDialogx.dismiss();
                EventForcheckUpdateResult("success", "2," + afterApdatePath + ",No internet connection, with external folder so change index.html path then hide splash screen"); // Thread-safe.

                return;
            }

            else if (!isExternalFolder)
            {
                //            long  freeSize=getFreeSize();
                //            long assetsSize=getAssetsSize();

                // changeProgressText("Please Wait... \r\n extract assets");


                if (extractAssets("www") != "OK")
                {
                    deleteFolder(ApplicationData.Current.LocalFolder.Path + "\\www");
                    //try again
                    string result = extractAssets("www");
                    if (result != "OK")
                    {
                        // progressDialogx.dismiss();
                        deleteFolder(ApplicationData.Current.LocalFolder.Path + "\\www");
                        EventForcheckUpdateResult("success", "1,internet connection is avilable , no external folder but problem with extract assets so load index from assets then hide splash screen error message =: " + result);

                        return;
                    }
                }
            }

            List <FileInfo> files = await getListFiles(ApplicationData.Current.LocalFolder.Path + "\\www");

            Stream stremaResult = null;

            try {
                stremaResult = await SV.PostForUpdateLinks(url, convertListToSTream(files));
            }
            catch (Exception exx)
            {
                EventForcheckUpdateResult("success", "2," + afterApdatePath + ",internet connection is avilable , with external folder but problem with download update so change index.html path then hide splash screen error message =: " + exx.Message); // Thread-safe.
                return;
            }



            StorageFolder localFolder = ApplicationData.Current.LocalFolder;
            StorageFile   storageFile = await localFolder.CreateFileAsync(tempUpdateFileName, CreationCollisionOption.ReplaceExisting);

            using (Stream outputStream = await storageFile.OpenStreamForWriteAsync())
            {
                await stremaResult.CopyToAsync(outputStream);
            }


            try
            {
                //   changeProgressText("Please Wait... \r\n extract update files");


                string resultx = await extractZipFile();

                if (resultx != "OK")
                {
                    EventForcheckUpdateResult("success", "2," + afterApdatePath + ",  internet connection is avilable , with external folder but problem with extractZipFile  so change index.html path then hide splash screen error message =: " + resultx); // Thread-safe.

                    return;
                }
            }
            catch (Exception ex)
            {
                //  progressDialogx.dismiss();
                EventForcheckUpdateResult("success", "2," + afterApdatePath + ",  internet connection is avilable , with external folder but problem with extractZipFile  so change index.html path then hide splash screen error message =: " + ex.Message); // Thread-safe.

                return;
            }

            try
            {
                File.Delete(ApplicationData.Current.LocalFolder.Path + "\\" + tempUpdateFileName);
            }
            catch (Exception)
            {
            }
            // progressDialogx.dismiss();
            EventForcheckUpdateResult("success", "2," + afterApdatePath + ",internet connection is avilable , with external folder noo error  so change index.html path then hide splash screen "); // Thread-safe.
        }