Ejemplo n.º 1
0
    void DownloadFileCompleted(object sender, DownloadFileCompletedArgs eventArgs)
    {
        if (eventArgs.State == CompletedState.Succeeded && eventArgs.BytesReceived == eventArgs.BytesTotal)
        {
            //download completed
            vesal_log.vesal_write_log("completed file percent:" + eventArgs.DownloadProgress);
            vesal_log.vesal_write_log("bytes:" + eventArgs.BytesReceived.ToString() + "::" + eventArgs.BytesTotal);

            string suffix = Vesal_DirFiles.get_name_suffix(savepath);

            if (suffix == "assetbundle")
            {
//                state = "saveab";
                abfile_process();
            }
            else if (suffix.ToLower() == "zip")
            {
//                state = "zip";
                unzip_process();
            }
            else
            {
                File.Move(temppath, savepath);
                if (succes_method != null)
                {
                    succes_method();
                }
            }
        }
        else
        {
            vesal_log.vesal_write_log("download fail:" + eventArgs.DownloadProgress);
            //download failed
            Vesal_DirFiles.DelFile(temppath);
            if (fail_method != null)
            {
                fail_method(eventArgs.Error);
            }
        }
        if (fileDownloader != null)
        {
            fileDownloader.Dispose();
        }
    }
Ejemplo n.º 2
0
    public bool DownLoad(string downUrl, string savePath, Action callBack = null, Action <Exception> errorCallBack = null, bool NameSubDir = false)
    {
        state          = "download";
        sameNameSubDir = NameSubDir;
        vesal_log.vesal_write_log("-- download: " + downUrl + savePath);
        savepath = savePath;
        temppath = savepath + ".temp";
        string suffix = Vesal_DirFiles.get_name_suffix(savepath);

        if (suffix.ToLower() == "zip")
        {
            isZipFile = true;
        }
        Vesal_DirFiles.DelFile(temppath);
        if (callBack != null)
        {
            succes_method = callBack;
        }
        if (errorCallBack != null)
        {
            fail_method = errorCallBack;
        }
        try
        {
            Uri      url = new Uri(downUrl);
            TimeSpan x   = new TimeSpan(0, 0, 8);
            fileDownloader                          = new FileDownloader.FileDownloader();
            fileDownloader.MaxAttempts              = 10;
            fileDownloader.SafeWaitTimeout          = x;
            fileDownloader.DownloadProgressChanged += DownLoadFileChanged;
            fileDownloader.DownloadFileCompleted   += DownloadFileCompleted;
            fileDownloader.DownloadFileAsync(url, temppath);
            vesal_log.vesal_write_log("-- downalod asy started");
        }
        catch
        {
            return(false);
        }
        return(true);
    }
Ejemplo n.º 3
0
    //下载完回调
    void DownLoad_complete()
    {
        vesal_log.vesal_write_log("--download completed  ");
        string fileSuffix = "";

        if (this_app.ab_path != null && this_app.ab_path != "")
        {
            fileSuffix = Vesal_DirFiles.get_name_suffix(this_app.ab_path).ToLower();
        }
        switch (PublicClass.app.app_type)
        {
        case "microlesson":
            //微课解压播放
            OperaStatus = AppOperState.UnZip;
            //微课自动播放
            //OperaStatus = AppOperState.Apprun;
            break;

        case "medical":
            if (targetSourcePath == "" || Directory.Exists(targetSourcePath))
            {
                OperaStatus = AppOperState.Apprun;
            }
            else
            {
                Directory.CreateDirectory(targetSourcePath);
                OperaStatus = AppOperState.UpdateData;
            }
            break;

        case "animation":
            OperaStatus = AppOperState.Apprun;
            break;

        default:
            OperaStatus = AppOperState.AssetLoad;
            break;
        }
    }
Ejemplo n.º 4
0
    //本地路径检测下载
    void CheckAssetAB(string ab_path, string app_version, bool CancelDownload = false)
    {
        DebugLog.DebugLogInfo("本地路径检测下载------------------" + this_app.ab_path);
        if (this_app.ab_path == "" || this_app.ab_path == null || CancelDownload)
        {
            DebugLog.DebugLogInfo("无私有资源:" + this_app.ab_path);
            DownLoad_complete();
            return;
        }
        string path        = Vesal_DirFiles.get_dir_from_full_path(ab_path);
        string source_name = Vesal_DirFiles.get_file_name_from_full_path(ab_path);
        string short_name  = Vesal_DirFiles.remove_name_suffix(source_name);
        string suffix      = Vesal_DirFiles.get_name_suffix(source_name);

        downloadFilePath = path + short_name + "_" + app_version + "." + suffix;
        targetSourcePath = path + short_name + "_" + app_version;

        DebugLog.DebugLogInfo("targetSourcePath:" + targetSourcePath);
        //        if (!PublicClass.online_mode)
        //        {
        //            DebugLog.DebugLogInfo("离线模式");
        //            DebugLog.DebugLogInfo("资源路径:" + path);
        //            DebugLog.DebugLogInfo("short_name  " + short_name);

        //            int founded = 0;
        //            DirectoryInfo dif = new DirectoryInfo(path);
        //            FileSystemInfo[] fsis = dif.GetFileSystemInfos();
        //            for (int i = 0; i < fsis.Length; i++)
        //            {
        //                FileSystemInfo tmp = fsis[i];
        //                if (tmp.FullName == downloadFilePath || tmp.FullName == targetSourcePath || tmp.FullName.Replace("\\", "/") == targetSourcePath || tmp.FullName.Replace("\\", "/") == downloadFilePath)
        //                {
        //                    //PublicClass.app.struct_name = short_name;
        //                    PublicClass.app.ab_path = Vesal_DirFiles.get_file_name_from_full_path(tmp.FullName);
        //                    PublicClass.app.xml_path = tmp.FullName;
        //                    founded = 1;
        //                    break;
        //                }
        //            }
        //            if (founded == 0)
        //            {
        //                this_app = null;
        //                PublicClass.app = null;
        //                SetOperaToLoop();
        //                //发送
        //#if UNITY_EDITOR || UNITY_STANDALONE_WIN
        //                if (PPTGlobal.PPTEnv != PPTGlobal.PPTEnvironment.plugin)
        //                {
        //                    send_cmd((byte)VESAL_CMD_CODE.MSG_CMD, "hide");
        //                }
        //#elif UNITY_IOS
        //                    Unity_Tools.clear_message_from_platform_for_ios();
        //                    Unity_Tools.ui_return_to_platform();
        //#elif UNITY_ANDROID
        //                    Unity_Tools.clear_message_from_platform_for_android();
        //                    Unity_Tools.ui_return_to_platform();
        //#else
        //#endif
        //                return;
        //            }
        //            else
        //            {
        //                DownLoad_complete();
        //            }
        //        }
        //        else
        //        {
        DebugLog.DebugLogInfo("在线模式");
        switch (PublicClass.app.app_type)
        {
        // case "medical":
        //     //目录存在,说明已经成功下载
        //     if (Directory.Exists(targetSourcePath))
        //     {
        //         DownLoad_complete();
        //     }
        //     else
        //     {
        //         DownLoadSignGroup(PublicClass.app.ab_path, downloadFilePath);
        //     }
        //     break;
        default:
            // PublicClass.TimelineFilePath = targetSourcePath;
            PublicClass.app.xml_path = downloadFilePath;
            string tmpPath = this_app.ab_path + "";
            PublicClass.app.ab_path = short_name + "_" + app_version + "." + suffix;
            //删除旧版本
            int    currentVersion  = int.Parse(app_version);
            string lastVersionPath = path + short_name + "_";
            for (int i = 0; i < currentVersion; i++)
            {
                if (Directory.Exists(lastVersionPath + i))
                {
                    Directory.Delete(lastVersionPath + i, true);
                }
            }
            if (!File.Exists(downloadFilePath) && !Directory.Exists(targetSourcePath))
            {
                string[] files = Directory.GetFiles(path);
                for (int i = 0; i < files.Length; i++)
                {
                    if (Vesal_DirFiles.get_file_name_from_full_path(files[i]).StartsWith(short_name))
                    {
                        Vesal_DirFiles.DelFile(files[i]);
                    }
                }
                //下载远程
                DownLoadSignGroup(tmpPath, downloadFilePath);
            }
            else
            {
                DownLoad_complete();
            }
            break;
            //}
        }
    }
Ejemplo n.º 5
0
    IEnumerator update_db_process()
    {
        string fixdb = PublicClass.MedicalPath + "vesali.db";
        string tmpdb = PublicClass.vesal_db_path + "temp.db";

        Vesal_DirFiles.DelFile(tmpdb);
        if (File.Exists(fixdb))
        {
            File.Move(fixdb, tmpdb);
        }
        show_progress.current_progress = 0.03f;
        string[] fname = Directory.GetFiles(PublicClass.MedicalPath);
        foreach (string file in fname)
        {
            string name   = Vesal_DirFiles.get_file_name_from_full_path(file);
            string suffix = Vesal_DirFiles.get_name_suffix(name);
            if (suffix.ToLower() == "assetbundle")
            {
                Vesal_DirFiles.DelFile(PublicClass.filePath + name);
                Vesal_DirFiles.SaveAbfile(file, PublicClass.filePath + name, false);
                Vesal_DirFiles.DelFile(file);
            }
        }

        show_progress.current_progress = 0.1f;
        //        string tmpdb = PublicClass.vesal_db_path + "temp.db";
        //打开数据库进行更新
        List <string> fix_tab_list = new List <string>();

        if (File.Exists(tmpdb))
        {
            fix_tab_list = PublicTools.get_table_list("temp.db");
            if (fix_tab_list.Count != 0)
            {
                int tab_count = 0;
                foreach (string tab_name in fix_tab_list)
                {
                    switch (tab_name)
                    {
                    case "GetSubModel":
                        PublicTools.update_GetSubModel_db("temp.db");
                        break;

                    case "GetStructList":
                        PublicTools.update_GetStructList_db("temp.db");
                        break;

                    case "GetStructAbList":
                        PublicTools.update_GetStructAbList_db("temp.db");
                        break;

                    case "LayserSubModel":
                        PublicTools.update_LayserSubModel_db("temp.db");
                        break;

                    case "ModelRelationModel":
                        PublicTools.update_ModelRelationModel_db("temp.db");
                        break;

                    case "RightMenuLayerModel":
                        PublicTools.update_RightMenuLayerModel_db("temp.db");
                        break;

                    case "RightMenuModel":
                        PublicTools.update_RightMenuModel_db("temp.db");
                        break;

                    case "SignNewInfo":
                        PublicTools.update_SignNewInfo_db("temp.db");
                        break;

                    case "GetTextureModelList":
                        PublicTools.update_GetTextureModelList_db("temp.db");
                        break;

                    case "noun_no_info":
                        PublicTools.update_noun_no_info_db("temp.db");
                        break;

                    case "AbInfo":
                        PublicTools.update_ab_info_db("temp.db");
                        break;
                    }
                    tab_count++;
                    show_progress.current_progress = 0.1f + 0.9f * tab_count / fix_tab_list.Count;
                    yield return(null);
                }
            }
            else
            {
                PublicTools.update_GetSubModel_db("temp.db");
                PublicTools.update_GetStructList_db("temp.db");
                show_progress.current_progress = 0.35f;
                yield return(null);

                PublicTools.update_GetStructAbList_db("temp.db");
                PublicTools.update_LayserSubModel_db("temp.db");
                show_progress.current_progress = 0.5f;
                yield return(null);

                PublicTools.update_ModelRelationModel_db("temp.db");
                PublicTools.update_RightMenuLayerModel_db("temp.db");
                show_progress.current_progress = 0.7f;
                yield return(null);

                PublicTools.update_RightMenuModel_db("temp.db");
                PublicTools.update_SignNewInfo_db("temp.db");
                show_progress.current_progress = 0.85f;
                yield return(null);

                PublicTools.update_GetTextureModelList_db("temp.db");
                PublicTools.update_noun_no_info_db("temp.db");
                PublicTools.update_ab_info_db("temp.db");
                show_progress.current_progress = 0.99f;
                yield return(null);
            }
            Vesal_DirFiles.DelFile(tmpdb);
            PublicTools.Model_AB_dic_update();
            ManageModel.Instance.UpdateModelInfo();
        }
        OperaStatus = AppOperState.Apprun;
    }