Exemple #1
0
        public static void GetAbfile_Synchronize(string from_path, string temp_path)
        {
            if (!File.Exists(from_path))
            {
                UnityEngine.Debug.LogError("!File.Exists : " + from_path);
                return;
            }
            var local_db = new DbRepository <Abfiles>();

            local_db.DataService("vesali.db");
            Abfiles res = local_db.SelectOne <Abfiles>((temp) => {
                if (temp.file_name == get_file_name_from_full_path(from_path))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            });

            if (res == null)
            {
                UnityEngine.Debug.LogError("res == null");
                local_db.Close();
                return;
            }

            byte[] data = new byte[1024];
            data = Convert.FromBase64String(res.head);

            FileStream FileOut = new FileStream(temp_path, System.IO.FileMode.Create);

            FileOut.Write(data, 0, 1024);

            FileStream FileIn = new FileStream(from_path, System.IO.FileMode.Open);
            //将此剩余字节写入temp_path
            int readLen;

            while (true)
            {
                readLen = FileIn.Read(data, 0, data.Length);
                if (readLen <= 0)
                {
                    break;
                }

                FileOut.Write(data, 0, readLen);
            }

            FileOut.Close();
            FileIn.Close();
        }
Exemple #2
0
        public static void GetAbfile2(string from_path, string temp_path)
        {
            byte[] data = new byte[1024];
            if (!File.Exists(from_path))
            {
                return;
            }

            var local_db = new DbRepository <Abfiles>();

            local_db.DataService("vesali.db");
            Abfiles res = local_db.SelectOne <Abfiles>((temp) =>
            {
                if (temp.file_name == get_file_name_from_full_path(from_path))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            });

            if (res == null)
            {
                local_db.Close();
                return;
            }
            local_db.Close();
            byte[]     data1   = Convert.FromBase64String(res.head);
            FileStream FileOut = new FileStream(temp_path, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite, FileShare.ReadWrite);

            FileOut.Write(data1, 0, data1.Length);

            FileStream FileIn = new FileStream(from_path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            //将此剩余字节写入temp_path
            int readLen;

            while (true)
            {
                readLen = FileIn.Read(data, 0, data.Length);
                if (readLen <= 0)
                {
                    break;
                }
                FileOut.Write(data, 0, readLen);
            }
            FileOut.Flush();
            FileIn.Close();
            FileOut.Close();

            //            vesal_log.vesal_write_log("load model phase 2 start: " + DateTime.Now.Ticks);
        }
Exemple #3
0
    /// <summary>
    /// 加载标注
    /// </summary>
    /// <param name="downLoad_name">标注ab</param>
    public void Load_ps(string downLoad_name, string ab_path)
    {
#if UNITY_EDITOR || UNITY_STANDALONE_WIN
        var    local_db  = new DbRepository <Abfiles>();
        string temp_path = PublicClass.tempPath + "temp.dat";
        local_db.DataService("vesali.db");
        Abfiles res = local_db.SelectOne <Abfiles>((temp) =>
        {
            if (temp.file_name == Vesal_DirFiles.get_file_name_from_full_path(ab_path))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        });
        local_db.Close();
        if (res == null || !File.Exists(ab_path))
        {
            if (PPTGlobal.PPTEnv == PPTGlobal.PPTEnvironment.plugin)
            {
                try
                {
                    curBundleObj = LoadPSModel(LoadModel_ppt.url, LoadModel_ppt.password, LoadModel_ppt.sceneName);
                }
                catch (Exception e)
                {
                    Debug.Log(e.Message);
                }
            }
        }
        else
        {
            //解压ab文件
            psmodel = null;
            ReadTextureAB(PublicClass.filePath + "sign/");
            Vesal_DirFiles.GetAbfile_Synchronize(ab_path, temp_path);
            curBundleObj = AssetBundle.LoadFromFile(temp_path);
        }
        GameObject realObj = (GameObject)curBundleObj.LoadAsset(downLoad_name, typeof(GameObject));
        CurrentObj      = Instantiate(realObj);
        CurrentObj.name = "temp_parent";
        CurrentObj.name = CurrentObj.name.Replace("(Clone)", "");
        // realObj.transform.SetParent(Transform_parent);
        // Camera.main.GetComponent<ChooseModel>().SetCameraPosition(CurrentObj.transform);
        Reset();
        GetMaterialsFromModel(downLoad_name);
        curBundleObj.Unload(false);//卸载内存中的资源
        if (File.Exists(temp_path))
        {
            Vesal_DirFiles.DelFile(temp_path);
        }
#elif UNITY_ANDROID || UNITY_IOS
        downLoad_name = GetSAFromSignidTable(PublicClass.app.struct_name);
        curBundleObj  = AssetBundle.LoadFromFile(PublicClass.filePath + "Android_sign/" + downLoad_name + ".assetbundle");
        GameObject realObj = (GameObject)curBundleObj.LoadAsset(downLoad_name, typeof(GameObject));
        CurrentObj      = Instantiate(realObj);
        CurrentObj.name = "temp_parent";
        CurrentObj.name = CurrentObj.name.Replace("(Clone)", "");
        Reset();
        GetMaterialsFromModel(downLoad_name);
        curBundleObj.Unload(false);  //卸载内存中的资源
#endif
    }
Exemple #4
0
        public static byte[] GetAbfile(string from_path, string temp_path)
        {
            //string fnf = get_file_name_from_full_path(from_path);
            //UnityEngine.Debug.Log(PublicClass.filePath  + fnf);
            //if (File.Exists(PublicClass.filePath+fnf)) {
            //    return File.ReadAllBytes(PublicClass.filePath + fnf);
            //}

            byte[] data = new byte[1024];
            if (!File.Exists(from_path))
            {
                return(data);
            }

            var local_db = new DbRepository <Abfiles>();

            local_db.DataService("vesali.db");
            Abfiles res = local_db.SelectOne <Abfiles>((temp) =>
            {
                if (temp.file_name == get_file_name_from_full_path(from_path))
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            });

            if (res == null)
            {
                local_db.Close();
                return(data);
            }
            data = Convert.FromBase64String(res.head);
            byte[] data2  = File.ReadAllBytes(from_path);
            byte[] result = new byte[data.Length + data2.Length];
            Array.Copy(data, result, data.Length);
            Array.Copy(data2, 0, result, data.Length, data2.Length);
            // FileStream FileOut = new FileStream(temp_path, System.IO.FileMode.Create);

            //FileOut.Write(data, 0, 1024);


            //FileStream FileIn = new FileStream(from_path, System.IO.FileMode.Open);
            ////将此剩余字节写入temp_path
            //int readLen;
            //while (true)
            //{
            //    readLen = FileIn.Read(data, 0, data.Length);
            //    if (readLen <= 0)
            //        break;

            //    //FileOut.Write(data, 0, readLen);
            //}

            //FileOut.Close();
            vesal_log.vesal_write_log("load model phase 2 start: " + DateTime.Now.Ticks);
            local_db.Close();
            return(result);
            //FileIn.Close();
        }
Exemple #5
0
        public static void SaveAbfile(string temp_path, string dest_path, bool decryptFlag, bool isDeleteSource = true)
        {
            if (!File.Exists(temp_path))
            {
                return;
            }
            string abtemp = PublicClass.tempPath + "Abtemptemp.ab";

            //解压文件并删除源文件
            if (decryptFlag)
            {
                VesalDecrypt.encrypt.DecryptFile(temp_path, abtemp, "Vesal17788051918");
                DelFile(temp_path);
            }
            else
            {
                abtemp = temp_path;
            }
            FileStream FileIn  = new FileStream(abtemp, System.IO.FileMode.Open);
            FileStream FileOut = new FileStream(dest_path, System.IO.FileMode.Create);

            try
            {
                byte[] data = new byte[1024];

                int readLen = FileIn.Read(data, 0, data.Length);

                //将此1024字节写入数据库的abfile表中
                var local_db = new DbRepository <Abfiles>();
                local_db.DataService("vesali.db");
                local_db.CreateTable();
                Abfiles file = new Abfiles {
                    file_name = get_file_name_from_full_path(dest_path), head = Convert.ToBase64String(data)
                };
                Abfiles res = local_db.SelectOne <Abfiles>((temp) =>
                {
                    if (temp.file_name == file.file_name)
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                });

                if (res == null)
                {
                    //insert
                    local_db.Insert(file);
                }
                else
                {
                    //update
                    local_db.Update(file);
                }

                local_db.Close();

                //将此剩余字节写入dest_path

                while (true)
                {
                    readLen = FileIn.Read(data, 0, data.Length);
                    if (readLen <= 0)
                    {
                        break;
                    }

                    FileOut.Write(data, 0, readLen);
                }
                FileIn.Close();
                FileOut.Close();

                if (isDeleteSource)
                {
                    DelFile(abtemp);
                }
            }
            catch (Exception e)
            {
                UnityEngine.Debug.Log(e.Message);
                FileIn.Close();
                FileOut.Close();
            }
        }