Пример #1
0
        private void UF_ParseIPType(String serverIp, int serverPorts, out String newServerIp, out AddressFamily mIPType)
        {
            mIPType     = AddressFamily.InterNetwork;
            newServerIp = serverIp;
            try
            {
                #if UNITY_IPHONE && !UNITY_EDITOR
                string mIP = DLLImport.__GetIPv6(serverIp, serverPorts.ToString());
                #else
                string mIP = m_Host + "&&ipv4";
                                #endif

                if (!string.IsNullOrEmpty(mIP))
                {
                    string[] m_StrTemp = System.Text.RegularExpressions.Regex.Split(mIP, "&&");
                    if (m_StrTemp != null && m_StrTemp.Length >= 2)
                    {
                        string IPType = m_StrTemp[1];
                        if (IPType == "ipv6")
                        {
                            newServerIp = m_StrTemp[0].Trim();
                            mIPType     = AddressFamily.InterNetworkV6;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Debugger.UF_Exception(e);
            }
        }
Пример #2
0
 //only call on main thread
 public static void UF_Call(string method, string arg)
 {
     if (!string.IsNullOrEmpty(method))
     {
         if (arg == null)
         {
             arg = string.Empty;
         }
         try{
             Debugger.UF_Log(string.Format("Call SDK Method:{0}\n Param:{1} ", method, arg));
                                 #if UNITY_EDITOR || UNITY_STANDALONE
             m_WinSDKActivity.CallSDKMethod(method, arg);
                                 #elif UNITY_ANDROID
             AndroidJavaClass  jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
             AndroidJavaObject jo = jc.GetStatic <AndroidJavaObject>("currentActivity");
             jo.Call("onUnityCall", method, arg);
             jo.Dispose();
             jc.Dispose();
                                 #elif UNITY_IPHONE
             DLLImport.__UnityCall(method, arg);
                                 #endif
         }
         catch (System.Exception e) {
             Debugger.UF_Exception(e);
         }
     }
 }
Пример #3
0
        //安装补丁文件文件
        private int UF_install_patch_zip(string ZipFilePath)
        {
            UF_logInfo(string.Format("install_patch_zip -- begin install zipfile : {0}", ZipFilePath));

            string cachefolderPath = GlobalPath.CachePath;
            string resfolderPath   = GlobalPath.ResPersistentPath;
            string rawfolderPath   = GlobalPath.StreamingAssetsPath + "/";
            int    retcode         = 0;

            //检查zip包是否存在
            FileInfo fi = new FileInfo(ZipFilePath);

            if (!fi.Exists)
            {
                UF_logError(string.Format("install_unzip -- zip file{0} not exist! ", ZipFilePath));
                return(-103);
            }

            //解压补丁文件到缓存目录
            if (0 != (retcode = DLLImport.LLFileExtract(ZipFilePath, cachefolderPath, Handle_ExtractProgress, Handle_UnZipError)))
            {
                UF_logError(string.Format("install_unzip -- DLLImport.LLFileExtrac Failed retcode[{0}] zipfile[{1}]", retcode, ZipFilePath));
                return(retcode);
            }

            UF_logInfo("install_patch_zip -- loading version");

            //获取补丁列表处理解压出来的补丁文件
            Dictionary <string, FILE_TYPE> dicUpdatePatch = new Dictionary <string, FILE_TYPE> ();

            if (UF_wrapdicFilePatch(cachefolderPath + "res_version.txt", dicUpdatePatch) != 0)
            {
                UF_deleteCacheFolder(new DirectoryInfo(cachefolderPath));
                return(-104);
            }

            UF_logInfo("Start Patching Files");
            //处理补丁文件
            if ((UF_handlepatchfile(cachefolderPath, resfolderPath, rawfolderPath, dicUpdatePatch)) != 0)
            {
                UF_deleteCacheFolder(new DirectoryInfo(cachefolderPath));
                return(-105);
            }

            UF_deleteCacheFolder(new DirectoryInfo(cachefolderPath));

            UF_logInfo("install_patch_zip -- install game thread end");

            return(0);
        }
Пример #4
0
        //处理更新文件
        private int UF_handlepatchfile(string cachefolderPath, string filefolderPath, string rawfolderPath, Dictionary <string, FILE_TYPE> dicUpdatePatch)
        {
            int count       = 0;
            int whole_count = dicUpdatePatch.Count;
            int retcode     = 0;

            m_ProgressUpdate = 0;

            try{
                foreach (KeyValuePair <string, FILE_TYPE> item in dicUpdatePatch)
                {
                    string t_file_name     = item.Key.Replace(".patch", "").Replace("#", "/");
                    string patch_file_path = string.Format("{0}{1}", cachefolderPath, item.Key);
                    string old_file_path   = string.Format("{0}{1}", filefolderPath, t_file_name);

                    UF_logInfo(string.Format("Patching: {0} ", t_file_name));

                    if (item.Value == FILE_TYPE.MODIFY)
                    {
                        string new_file_path = string.Format("{0}{1}.new", cachefolderPath, Path.GetFileName(t_file_name));

                        if (!File.Exists(old_file_path))
                        {
                            //如果 Old File中没有原始文件,会在Raw 文件夹中拷贝原始文件到Res中,安卓除外
                                                        #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_IPHONE
                            string raw_file_path = string.Format("{0}{1}", rawfolderPath, t_file_name);
                            UF_logInfo(string.Format("Old File not Exist,Try Copy Raw file to:{0}", old_file_path));
                            if (!File.Exists(raw_file_path))
                            {
                                UF_logError(string.Format("Raw File not Exist: {0} ", raw_file_path));
                                return(-201);
                            }
                            else
                            {
                                UF_checkfilefolder(old_file_path, true);
                                UF_copyfile(raw_file_path, old_file_path);
                            }
                                                        #else
                            UF_logError(string.Format("Old File not Exist: {0} ", old_file_path));
                            return(-201);
                                                        #endif
                        }
                        if (!File.Exists(patch_file_path))
                        {
                            UF_logError(string.Format("Patch File not Exist: {0} ", patch_file_path));
                            return(-202);
                        }
                        //对文件进行补丁,生成最新版本的文件
                        retcode = DLLImport.LLFilePatch(old_file_path, new_file_path, patch_file_path);
                        if (retcode != 0)
                        {
                            UF_logError(string.Format("DLLImport.LLFilePatch Failed  retcode[{0}]", retcode));
                            UF_logError(old_file_path);
                            UF_logError(new_file_path);
                            UF_logError(patch_file_path);
                            return(retcode);
                        }
                        if (!File.Exists(new_file_path))
                        {
                            UF_logError(string.Format("New File not Exist: {0} ", new_file_path));
                            return(-203);
                        }
                        //删除原来的文件
                        UF_deletefile(old_file_path);

                        //移动新的文件到原文件位置
                        UF_movefile(new_file_path, old_file_path);
                    }
                    else if (item.Value == FILE_TYPE.ADD)
                    {
                        if (UF_checkfilefolder(old_file_path, true))
                        {
                            //删除原来的文件
                            UF_deletefile(old_file_path);
                        }
                        //移动新的文件到原文件位置
                        UF_movefile(patch_file_path, old_file_path);
                    }
                    else if (item.Value == FILE_TYPE.DELETE)
                    {
                        //删除目标文件
                        UF_deletefile(old_file_path);
                    }

                    count++;
                    m_ProgressUpdate = (float)count / (float)whole_count;
                }
            }
            catch (System.Exception e) {
                UF_logError(string.Format("Patch File Exception:{0}", e.Message));
                UF_logError(e.StackTrace);
            }

            m_ProgressUpdate = 1;

            return(0);
        }
Пример #5
0
        private int UF_threadInstallNet(object e)
        {
            UF_logInfo("running in thread -> threaddownLoadAndIntallzip");

            string zipName = e as string;

            if (string.IsNullOrEmpty(zipName))
            {
                UF_logError("Thread Install Failed,Zip Name is null");
            }
            string zipfilePath = GlobalPath.CachePath + zipName;
            string url_zipfile = GlobalSettings.UrlAssetsUpgrade + zipName;

            UF_logInfo(string.Format("Start Install Zip file:{0}\n{1}\n{2}\n", zipName, zipfilePath, url_zipfile));

            string cachefolderPath = GlobalSettings.UrlAssetsUpgrade;

            UF_SetUpgradeInfo(GlobalText.LAN_START_INSTALL_GAME);

            int retcode = 0;

            m_ProgressTotal  = 1;
            m_ProgressUpdate = 0;
            s_ProgresssZip   = 0;
            m_CurProgress    = 0;

            //下载base 安装包
            UF_SetUpgradeInfo(GlobalText.LAN_DOWNLOAD_GAME);
            m_UseDownloadProgress = true;
            while (true)
            {
                if (0 != (retcode = UF_downloadzipfile(url_zipfile, cachefolderPath)))
                {
                    //断点更新失败
                    if (retcode == 416)
                    {
                        if (File.Exists(zipfilePath))
                        {
                            UF_logError(string.Format("Download breakpoint continue Failed url:[{1}],try again now", retcode, url_zipfile));
                            File.Delete(zipfilePath);
                            continue;
                        }
                    }
                    else
                    {
                        UF_logError(string.Format("Download zipfile Failed retcode:[{0}]  url:[{1}]", retcode, url_zipfile));
                        break;
                    }
                }
                break;
            }
            //下载成功,进行安装
            UF_SetUpgradeInfo(GlobalText.LAN_INSTALL_GAME);
            m_UseDownloadProgress = false;
            m_ProgressTotal       = 1;
            m_ProgressUpdate      = 0;
            s_ProgresssZip        = 0;
            m_CurProgress         = 0;

            //解压安装 文件
            retcode = DLLImport.LLFileExtract(zipfilePath, GlobalPath.ResPersistentPath, Handle_ExtractProgress, Handle_UnZipError);

#if !UNITY_EDITOR && UNITY_ANDROID
            //清空cache 中的安装文件
            System.IO.FileInfo zipfi = new System.IO.FileInfo(zipfilePath);
            if (zipfi.Exists)
            {
                zipfi.Delete();
            }
            UF_logInfo("Clean Install file in Cache");
#endif

            if (retcode != 0)
            {
                UF_logError(string.Format("AppDLLImport.FileExtract Failed [{0}] \n{1}\n{2}", retcode, zipfilePath, GlobalPath.ResPersistentPath));
            }

            m_CurProgress = 1;

            return(retcode);
        }
Пример #6
0
        //zip 的安装方式
        private int UF_threadInstallBase(object e)
        {
            UF_logInfo("running in thread -> threadInstallzip");

            string zipName = e as string;

            if (string.IsNullOrEmpty(zipName))
            {
                UF_logError("Thread Install Failed,Zip Name is null");
            }

            UF_logInfo(string.Format("Start Install Zip file:{0}", zipName));

            string zipfilePath = GlobalPath.CachePath + zipName;

            string cachefolderPath = GlobalPath.CachePath;

            UF_SetUpgradeInfo(GlobalText.LAN_START_INSTALL_GAME);
            int retcode = 0;

            m_ProgressTotal  = 1;
            m_ProgressUpdate = 0;
            s_ProgresssZip   = 0;
            m_CurProgress    = 0;

                        #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_IPHONE
            zipfilePath = GlobalPath.StreamingAssetsPath + "/" + zipName;
#elif UNITY_ANDROID
            string apkPath     = GlobalPath.AppPath;
            string packageName = "assets/" + zipName;
            zipfilePath = cachefolderPath + zipName;
            UF_logInfo(string.Format("Extract Base File[{0}] Zip file Form: {1} \n To: {2}", packageName, apkPath, cachefolderPath));
            //解压apK中的安装文件到cache目录
            retcode = DLLImport.LLSpecifiedFileExtract(apkPath, packageName, cachefolderPath);
            if (retcode != 0)
            {
                UF_logError(string.Format("DLLImport.LLSpecifiedFileExtract Failed [{0}] \n{1}\n{2}\n{3}", retcode, apkPath, packageName, cachefolderPath));
                return(retcode);
            }
            UF_logInfo("Extract Install zip to Cache");
#endif
            UF_SetUpgradeInfo(GlobalText.LAN_INSTALL_GAME);

            //解压安装 文件
            retcode = DLLImport.LLFileExtract(zipfilePath, GlobalPath.ResPersistentPath, Handle_ExtractProgress, Handle_UnZipError);

                        #if !UNITY_EDITOR && UNITY_ANDROID
            //清空cache 中的安装文件
            System.IO.FileInfo zipfi = new System.IO.FileInfo(zipfilePath);
            if (zipfi.Exists)
            {
                zipfi.Delete();
            }
            UF_logInfo("Clean Install file in Cache");
                        #endif

            if (retcode != 0)
            {
                UF_logError(string.Format("DLLImport.FileExtract Failed [{0}] \n{1}\n{2}", retcode, zipfilePath, GlobalPath.ResPersistentPath));
            }

            s_ProgresssZip = 1;

            return(retcode);
        }