public static void SaveIni() { Setting.SaveSetting(); Setting.SaveBoneDisplay(); Setting.SaveGizmoDisplay(); IniUtil.Save(); }
private static void LoadBoneDisplay() { Setting.boneSelectKey = (KeyCode)IniUtil.GetIntValue("BoneDisplay", "BoneSelectKey", 308); Setting.normalBoneColor = new Setting.SettingValue <Color>(ColorUtil.GetColorFromName(IniUtil.GetStringValue("BoneDisplay", "NormalBoneColor", "white"))); Setting.selectBoneColor = new Setting.SettingValue <Color>(ColorUtil.GetColorFromName(IniUtil.GetStringValue("BoneDisplay", "SelectBoneColor", "red"))); Setting.bodyBoneDisplay = new Setting.SettingValue <BodyBoneDisplay>((BodyBoneDisplay)IniUtil.GetIntValue("BoneDisplay", "BodyBoneDisplay", 1)); }
public void INI檔案寫入(string section, string key, string expected) { var before = IniUtil.Read(this._file, section, key); IniUtil.Write(this._file, section, key, expected); var actual = IniUtil.Read(this._file, section, key); Assert.AreEqual(expected, actual); // snapshot IniUtil.Write(this._file, section, key, before); }
private void SetPluginInfo() { PluginNameAttribute pluginNameAttribute = Attribute.GetCustomAttribute(base.GetType(), typeof(PluginNameAttribute)) as PluginNameAttribute; PluginVersionAttribute pluginVersionAttribute = Attribute.GetCustomAttribute(base.GetType(), typeof(PluginVersionAttribute)) as PluginVersionAttribute; string name = (pluginNameAttribute == null) ? base.Name : pluginNameAttribute.Name; string version = (pluginVersionAttribute == null) ? string.Empty : pluginVersionAttribute.Version; string @namespace = base.GetType().Namespace; PluginInfo.SetInfo(name, version, @namespace); IniUtil.Init(this); IniUtil.saveMethod += base.SaveConfig; Setting.LoadIni(); Setting.SaveIni(); }
static int SetGlobal(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); IniUtil obj = (IniUtil)ToLua.CheckObject(L, 1, typeof(IniUtil)); obj.SetGlobal(); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
void menu_Click(object sender, EventArgs e) { if (ClickEvent != null) { if ((sender as Button).Tag == null) { return; } string menuname = (sender as Button).Tag.ToString(); string section = "LeftMenu"; string path = Application.StartupPath + "\\Config.ini"; string url = IniUtil.ReadIniValue(path, section, menuname); ClickEvent(url); } }
static int OpenFromStreamingAssets(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); IniUtil obj = (IniUtil)ToLua.CheckObject(L, 1, typeof(IniUtil)); string arg0 = ToLua.CheckString(L, 2); bool o = obj.OpenFromStreamingAssets(arg0); LuaDLL.lua_pushboolean(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int OpenFromMemory(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); IniUtil obj = (IniUtil)ToLua.CheckObject(L, 1, typeof(IniUtil)); byte[] arg0 = ToLua.CheckByteBuffer(L, 2); bool o = obj.OpenFromMemory(arg0); LuaDLL.lua_pushboolean(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int WriteValue(IntPtr L) { try { ToLua.CheckArgsCount(L, 3); IniUtil obj = (IniUtil)ToLua.CheckObject(L, 1, typeof(IniUtil)); string arg0 = ToLua.CheckString(L, 2); object arg1 = ToLua.ToVarObject(L, 3); obj.WriteValue(arg0, arg1); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int ReadValue(IntPtr L) { try { ToLua.CheckArgsCount(L, 3); IniUtil obj = (IniUtil)ToLua.CheckObject(L, 1, typeof(IniUtil)); string arg0 = ToLua.CheckString(L, 2); string arg1 = ToLua.CheckString(L, 3); object o = obj.ReadValue(arg0, arg1); ToLua.Push(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int _CreateIniUtil(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 0) { IniUtil obj = new IniUtil(); ToLua.PushObject(L, obj); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: IniUtil.New")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
private static void LoadSetting() { Setting.boneDisplay = (BoneDisplay)IniUtil.GetIntValue("Setting", "BoneDisplay", 1); Setting.coordinateType = (ExGizmoRenderer.COORDINATE)IniUtil.GetIntValue("Setting", "CoordinateType", 0); Setting.gizmoType = (GizmoType)IniUtil.GetIntValue("Setting", "GizmoType", 2); }
public void INI檔案不存在(string section, string key, string expected) { var NotExistsFile = @"%Windir%/123.ini"; Assert.Catch <FileNotFoundException>(() => IniUtil.Read(NotExistsFile, section, key)); }
private static void LoadGizmoDisplay() { Setting.gizmoSmallKey = (KeyCode)IniUtil.GetIntValue("GizmoDisplay", "GizmoSmallKey", 304); Setting.gizmoBigKey = (KeyCode)IniUtil.GetIntValue("GizmoDisplay", "GizmoBigKey", 0); }
public static void Init(string s) { m_ht = IniUtil.CreateHashtable(s); }
public void 取得INI檔案設定值(string section, string key, string expected) { var actual = IniUtil.Read(this._file, section, key); Assert.AreEqual(expected, actual); }
// 根据选择语言进行初始化 public static int init() { destroy(); countryCodeTable = new Dictionary <string, string[]>(); countryIdTable = new Dictionary <int, string[]>(); languageCodeTable = new Dictionary <string, string[]>(); languageIdTable = new Dictionary <int, string[]>(); // 读取国家信息 TableUtil _countryTxt = new TableUtil(); if (_countryTxt.OpenFromData("localization_country.txt") == false) { return(-1); } for (int row = 0; row < _countryTxt.GetRecordsNum(); row++) { string countryCode = _countryTxt.GetValue(row, 0); // 国家英文代码(国际标准) string CountryID = _countryTxt.GetValue(row, 1); // 国家数字代码(国际标准) string CountryNameID = _countryTxt.GetValue(row, 2); // 国家名称ID string CountryFlag = _countryTxt.GetValue(row, 3); // 国旗资源名 string CountryMoney = _countryTxt.GetValue(row, 4); // 货币简称 // 英文编码作key if (countryCodeTable.ContainsKey(countryCode) == false) { string[] ls = new string[4]; ls[0] = CountryID; ls[1] = CountryNameID; ls[2] = CountryFlag; ls[3] = CountryMoney; countryCodeTable.Add(countryCode, ls); } // 数字编码作key if (countryIdTable.ContainsKey(Convert.ToInt32(CountryID)) == false) { string[] ls = new string[4]; ls[0] = countryCode; ls[1] = CountryNameID; ls[2] = CountryFlag; ls[3] = CountryMoney; countryIdTable.Add(Convert.ToInt32(CountryID), ls); } } // 读取语言信息 TableUtil _languageTxt = new TableUtil(); if (_languageTxt.OpenFromData("localization_language.txt") == false) { return(-2); } for (int row = 0; row < _languageTxt.GetRecordsNum(); row++) { string LanguageCode = _languageTxt.GetValue(row, 0); // 语言英文代码(国际标准) string LanguageCustomID = _languageTxt.GetValue(row, 1); // 语言自定义ID(无标准,暂时跟u3d里定义的语言ID走) string LanguageNameID = _languageTxt.GetValue(row, 2); // 语言名称ID string LanguageDirectory = _languageTxt.GetValue(row, 3); // 语言存在目录 string TranslationCode = _languageTxt.GetValue(row, 4); // 翻译Code // 英文编码作key if (languageCodeTable.ContainsKey(LanguageCode) == false) { string[] ls = new string[4]; ls[0] = LanguageCustomID; ls[1] = LanguageNameID; ls[2] = LanguageDirectory; ls[3] = TranslationCode; languageCodeTable.Add(LanguageCode, ls); } // 数字编码作key if (languageIdTable.ContainsKey(Convert.ToInt32(LanguageCustomID)) == false) { string[] ls = new string[4]; ls[0] = LanguageCode; ls[1] = LanguageNameID; ls[2] = LanguageDirectory; ls[3] = TranslationCode; languageIdTable.Add(Convert.ToInt32(LanguageCustomID), ls); } } // 用户本地配置文件里获取玩家已经选择的国家语言 IniUtil userIni = new IniUtil(); userIni.OpenFromTXT(PathUtil.ConfigPath() + "user.txt"); // 读取使用语言 currentLanguage = userIni.ReadValue("LANGUAGE", "").ToString(); if (currentLanguage == "") { // 没有存档的,使用设备当前的 currentLanguage = DeviceHelper.getLanguage(); userIni.WriteValue("LANGUAGE", currentLanguage); } // 读取使用国家 currentCountry = userIni.ReadValue("COUNTRY", "").ToString(); if (currentCountry == "") { // 没有存档的,使用设备当前的 currentCountry = DeviceHelper.getCountry(); userIni.WriteValue("COUNTRY", currentCountry); } // 先去语言信息里找一下,语言-地区的目录(如zh-cn),没有则直接使用语言(如zh,ru,en等),还是没有则使用英文的 string localizeDir = languageDirectory(currentLanguage + "-" + currentCountry); if (localizeDir == "") { localizeDir = languageDirectory(currentLanguage); if (localizeDir == "") { localizeDir = languageDirectory("en"); if (localizeDir == "") { return(-3); } } } localizeDir = localizeDir + "/"; // 读取基础文字表 TableUtil _localizetxt = new TableUtil(); localize = new Dictionary <int, string>(); if (_localizetxt.OpenFromData(localizeDir + "localize.txt") == false) { // 没有对应的语言文件夹,用英语的 localizeDir = languageDirectory("en") + "/"; if (_localizetxt.OpenFromData(localizeDir + "localize.txt") == false) { return(-4); } } for (int row = 0; row < _localizetxt.GetRecordsNum(); row++) { int key = Convert.ToInt32(_localizetxt.GetValue(row, 0)); string text = _localizetxt.GetValue(row, 1); text = text.Replace("\\n", "\n"); localize.Add(key, text); } // 读取道具文字表 TableUtil _localizeItemTxt = new TableUtil(); localize_item = new Dictionary <int, string>(); if (_localizeItemTxt.OpenFromData(localizeDir + "localize_item.txt") == false) { // 没有对应的语言文件夹,用英语的 localizeDir = languageDirectory("en") + "/"; if (_localizeItemTxt.OpenFromData(localizeDir + "localize_item.txt") == false) { return(-5); } } for (int row = 0; row < _localizeItemTxt.GetRecordsNum(); row++) { int key = Convert.ToInt32(_localizeItemTxt.GetValue(row, 0)); string text = _localizeItemTxt.GetValue(row, 1); text = text.Replace("\\n", "\n"); localize_item.Add(key, text); } // 读取任务文字表 TableUtil _localizeQuestTxt = new TableUtil(); localize_quest = new Dictionary <int, string>(); if (_localizeQuestTxt.OpenFromData(localizeDir + "localize_quest.txt") == false) { // 没有对应的语言文件夹,用英语的 localizeDir = languageDirectory("en") + "/"; if (_localizeQuestTxt.OpenFromData(localizeDir + "localize_quest.txt") == false) { return(-6); } } for (int row = 0; row < _localizeQuestTxt.GetRecordsNum(); row++) { int key = Convert.ToInt32(_localizeQuestTxt.GetValue(row, 0)); string text = _localizeQuestTxt.GetValue(row, 1); text = text.Replace("\\n", "\n"); localize_quest.Add(key, text); } // 容错处理,所有找不到的文字使用英文 localizeDir = languageDirectory("en") + "/"; // 读取基础文字表 TableUtil localizetxt_en_us = new TableUtil(); localize_en_us = new Dictionary <int, string>(); localizetxt_en_us.OpenFromData(localizeDir + "localize.txt"); for (int row = 0; row < localizetxt_en_us.GetRecordsNum(); row++) { int key = Convert.ToInt32(localizetxt_en_us.GetValue(row, 0)); string text = localizetxt_en_us.GetValue(row, 1); text = text.Replace("\\n", "\n"); localize_en_us.Add(key, text); } // 读取道具文字表 TableUtil localizeitemtxt_en_us = new TableUtil(); localize_item_en_us = new Dictionary <int, string>(); localizeitemtxt_en_us.OpenFromData(localizeDir + "localize_item.txt"); for (int row = 0; row < localizeitemtxt_en_us.GetRecordsNum(); row++) { int key = Convert.ToInt32(localizeitemtxt_en_us.GetValue(row, 0)); string text = localizeitemtxt_en_us.GetValue(row, 1); text = text.Replace("\\n", "\n"); localize_item_en_us.Add(key, text); } // 读取任务文字表 TableUtil localizequesttxt_en_us = new TableUtil(); localize_quest_en_us = new Dictionary <int, string>(); localizequesttxt_en_us.OpenFromData(localizeDir + "localize_quest.txt"); for (int row = 0; row < localizequesttxt_en_us.GetRecordsNum(); row++) { int key = Convert.ToInt32(localizequesttxt_en_us.GetValue(row, 0)); string text = localizequesttxt_en_us.GetValue(row, 1); text = text.Replace("\\n", "\n"); localize_quest_en_us.Add(key, text); } bInited = true; return(0); }
private void ReadData() { string[] files = Directory.GetFiles(Environment.CurrentDirectory + "\\data", "*.*", SearchOption.AllDirectories); var fileList = new List <string>(files); if (fileList.BinarySearch(Environment.CurrentDirectory + "\\data\\config.ini") < 0) { FileStream fs = new FileStream(Environment.CurrentDirectory + "\\data\\config.ini", FileMode.Create); StreamWriter sw = new StreamWriter(fs); sw.Write("//请使用英文逗号隔开选手ID" + "[Match]\r\n" + "Stage = 小组赛\r\n" + "Time = 2019-7-22 19:43\r\n" + "[Blue]\r\n" + "Name = UNITED KINGDOM\r\n" + "Player = Bubbleman,Doomsday\r\n" + "[Red]\r\n" + "Name = UNITED STATES\r\n" + "Player = Apraxia,Toy\r\n" ); sw.Flush(); sw.Close(); fs.Close(); } fileList.ForEach(file => { if (file.ToLower().EndsWith("match.png")) { Constant.MatchLogo = LoadImage(file); } if (file.ToLower().EndsWith("red_logo.png")) { Constant.RedLogo = LoadImage(file); } if (file.ToLower().EndsWith("blue_logo.png")) { Constant.BlueLogo = LoadImage(file); } if (file.ToLower().EndsWith("schedule.png")) { Constant.Schedule = LoadImage(file); } if (file.ToLower().EndsWith("xls") || file.ToLower().EndsWith("xlsx")) { Constant.MapPoolSet = Mp5MapPoolReadUtil.Read(file); } }); Constant.Stage = IniUtil.ReadIniData("Match", "Stage"); Constant.Time = IniUtil.ReadIniData("Match", "Time"); Constant.BlueTeamName = (IniUtil.ReadIniData("Blue", "Name")); Constant.RedTeamName = (IniUtil.ReadIniData("Red", "Name")); Constant.BluePlayers = (IniUtil.ReadIniData("Blue", "Player")); Constant.RedPlayers = (IniUtil.ReadIniData("Red", "Player")); //根据图池表格中的谱面ID读取子文件夹下的图片文件 fileList.ForEach(file => { Constant.MapPoolSet.Pool.ForEach( pool => { pool.Map.ForEach( map => { if (file.ToLower().EndsWith(map.BeatmapId + ".png")) { Constant.BgImages.Add(map.BeatmapId, LoadImage(file)); } } ); } ); } ); }
public static string Get(string category, string key) { return(IniUtil.GetValueFromHashtable(category, key, m_ht)); }
/// <summary> /// 第四步,启动web更新逻辑 /// </summary> IEnumerator OnUpdateResource() { LogUtil.GetInstance().WriteGame("Start UpdateResource!"); // 更新过程中,每秒都需要进行网络检查 StartCoroutine(OnCheckNetwork()); // 本地平台 IniUtil plat = new IniUtil(); plat.OpenFromData("plat.txt"); Const.platid = Convert.ToInt32(plat.ReadValue("PLATID", "")); LogUtil.GetInstance().WriteGame("PlatID:" + Const.platid); // 本地资源版本号 m_local_resource_version = Convert.ToInt32(m_pLocalResverIni.ReadValue("RESOURCE_VERSION", "0")); LogUtil.GetInstance().WriteGame("UpdateResource Start local_version:" + m_local_resource_version); // 本地资源文件列表,生成字典结构,文件名当索引,以便查找 Dictionary <string, string> szlocalFileMd5Dict = new Dictionary <string, string>(); Dictionary <string, int> szlocalFileSizeDict = new Dictionary <string, int>(); // 读取本地文件列表 string[] szlocalFileList = File.ReadAllLines(PathUtil.LocalPath() + m_szFilesName); LogUtil.GetInstance().WriteGame("FileList Readed!"); // 解析文件列表 foreach (var localFile in szlocalFileList) { string[] values = localFile.Split('|'); string fileName = values[0]; string fileMd5 = values[1]; int fileSize = Convert.ToInt32(values[2]); szlocalFileMd5Dict.Add(fileName, fileMd5); szlocalFileSizeDict.Add(fileName, fileSize); } // 更新地址 bool appSucc = m_pAppIni.OpenFromData(m_szAppTxt); LogUtil.GetInstance().WriteGame("Read App.txt:" + appSucc.ToString()); string url = Convert.ToString(m_pAppIni.ReadValue("UPDATE_URL", "")); // 获取服务器的更新文件地址 // 先取cfg文件,没有文件才取php LogUtil.GetInstance().WriteGame(url + "/update_" + m_szFilePrefix + ".cfg"); WWW www = new WWW(url + "/update_" + m_szFilePrefix + ".cfg"); yield return(www); if (www.error != null) { // 取php LogUtil.GetInstance().WriteGame(url + "/update_" + m_szFilePrefix + ".php"); www = new WWW(url + "/update_" + m_szFilePrefix + ".php"); yield return(www); if (www.error != null) { // 更新地址错误也进游戏 //m_uiText.text = "update url error"; OnInited(); yield break; } } LogUtil.GetInstance().WriteGame("www.text:" + www.text); string[] result = www.text.Split('|'); if (result.Length < 2) { OnInited(); yield break; } // 最新版本 int latest_version = Convert.ToInt32(result[0]); // 更新地址 string updateResUrl = result[1]; // 强制更新版本号(程序版本),低于这个版本都需要强制更新 if (result.Length == 3) { int forceVersion = Convert.ToInt32(result[2]); // 本地程序版本号 string[] appVersionArray = Application.version.Split('.'); int appVersion = Convert.ToInt32(appVersionArray[2]); LogUtil.GetInstance().WriteGame("appVersion:" + appVersion); if (appVersion < forceVersion) { // 请前去下载最新版本游戏 m_uiForceUpdateBox.transform.Find("Text").GetComponent <UIText>().text = Localization.text(425); m_uiForceUpdateBox.SetActive(true); yield break; } } LogUtil.GetInstance().WriteGame("web_latest_version:" + latest_version); if (latest_version < m_local_resource_version) { // 本地版本大于远端版本,不更新直接进游戏 //m_uiText.text = Localization.text( 403 ); LogUtil.GetInstance().WriteGame("Has been the latest version"); OnInited(); yield break; } // 先下载文件列表到本地 www = new WWW(updateResUrl + "/" + m_szFilesName); yield return(www); if (www.error != null) { //m_uiText.text = "files url error"; LogUtil.GetInstance().WriteGame("files url error:" + www.error); OnInited(); yield break; } // 如果存在,那么先删除在创建 if (Directory.Exists(PathUtil.PatchDownloadPath())) { Directory.Delete(PathUtil.PatchDownloadPath(), true); } Directory.CreateDirectory(PathUtil.PatchDownloadPath()); File.WriteAllBytes(PathUtil.PatchDownloadPath() + m_szFilesName, www.bytes); // 比较web下载下来的文件列表和本地的两个文件列表的差异数据 m_downloadsize_total = 0; m_szNeedUpdateFileDict = new Dictionary <string, DownLoadFile>(); string[] szUpdateFileList = File.ReadAllLines(PathUtil.PatchDownloadPath() + m_szFilesName); foreach (var updateFile in szUpdateFileList) { string[] values = updateFile.Split('|'); string updateFileName = values[0]; string updateFileMd5 = values[1]; int updateFileSize = Convert.ToInt32(values[2]); string updateFilePath = (PathUtil.PatchDownloadPath() + updateFileName).Trim(); string updateFileDirectory = Path.GetDirectoryName(updateFilePath); if (!Directory.Exists(updateFileDirectory)) { Directory.CreateDirectory(updateFileDirectory); #if UNITY_IOS UnityEngine.iOS.Device.SetNoBackupFlag(updateFileDirectory); #endif } // 1.先找这个文件本地是否存在,不存在直接下载 bool isUpdate = false; // 2.如果存在,比较文件大小,一样大就比较MD5,不一样大就直接下载 if (szlocalFileSizeDict.ContainsKey(updateFileName) == false) { isUpdate = true; LogUtil.GetInstance().WriteGame("[" + updateFilePath + "]Not Exists,Download!"); } else { if (szlocalFileSizeDict[updateFileName] != updateFileSize) { isUpdate = true; LogUtil.GetInstance().WriteGame("[" + updateFilePath + "] FileSize,Download!"); } else { if (!szlocalFileMd5Dict[updateFileName].Equals(updateFileMd5)) { isUpdate = true; LogUtil.GetInstance().WriteGame("[" + updateFilePath + "] MD5,Download!"); } } } // 如果需要更新 if (isUpdate) { m_szNeedUpdateFileDict.Add(updateFileName, new DownLoadFile(updateFileSize, updateFileMd5)); m_downloadsize_total += updateFileSize; } } // 这里要询问玩家是否进行更新 if (m_downloadsize_total > 1024 * 1024) { // 大于1mb提示 m_AskSureUpdate = true; long nTotalSize = m_downloadsize_total; if (nTotalSize < 1024) { nTotalSize = 1024; } m_uiWarningBox.transform.Find("Text").GetComponent <UIText>().text = string.Format(Localization.text(407), nTotalSize / 1024.0 / 1024.0); m_uiWarningBox.SetActive(true); } else { // 小于1mb不提示 m_AskSureUpdate = false; m_uiWarningBox.SetActive(false); } // 等待按钮改变这个值 while (m_AskSureUpdate) { yield return(new WaitForEndOfFrame()); } // 初始化线程管理器 Utils.Add <ThreadManager>(gameObject); // 开始更新 bool isNeedUpdate = false; foreach (var updateInfo in m_szNeedUpdateFileDict) { isNeedUpdate = true; m_uiText.text = Localization.text(404); LogUtil.GetInstance().WriteGame("<Download>" + "[name]:" + updateInfo.Key + "|[size]:" + updateInfo.Value.size); bool downloadFinish = false; while (!downloadFinish) { // 启动下载文件 DownloadFile(updateResUrl + "/", updateInfo.Key); // 此处轮询检查这个文件时候已经下载 while (!m_downloadFiles.Contains(updateInfo.Key)) { yield return(new WaitForEndOfFrame()); } // 刚刚下载完成的文件 string curr_updateFile = PathUtil.PatchDownloadPath() + updateInfo.Key; // 没这个文件 if (!File.Exists(curr_updateFile)) { LogUtil.GetInstance().WriteGame("<Download Miss>" + "[path]:" + curr_updateFile); m_downloadFiles.Remove(updateInfo.Key); updateInfo.Value.BytesReceived = 0; continue; } // 检查下载成功的文件 LogUtil.GetInstance().WriteGame("<Download MD5 Check>" + "[path]:" + curr_updateFile); string curr_md5 = Utils.md5file(curr_updateFile); if (updateInfo.Value.md5.Equals(curr_md5)) { LogUtil.GetInstance().WriteGame("<Download MD5 Succesed>" + "[path]:" + curr_updateFile); downloadFinish = true; } else { // 下载失败,重新下载 LogUtil.GetInstance().WriteGame("<Download Failed>" + "[path]:" + curr_updateFile + "[web]:" + updateInfo.Value.md5 + "[local]:" + curr_md5); m_downloadFiles.Remove(updateInfo.Key); updateInfo.Value.BytesReceived = 0; } } } // 更新完毕之后将临时补丁文件夹内容拷贝到正式本地目录 if (isNeedUpdate) { m_uiText.text = Localization.text(405); LogUtil.GetInstance().WriteGame("update success"); // 拷贝所有文件 FileUtil.CopyDir(PathUtil.PatchDownloadPath(), PathUtil.LocalPath()); Directory.Delete(PathUtil.PatchDownloadPath(), true); // 更新程序资源版本文件 File.Copy(PathUtil.LocalPath() + m_szResverTxt, PathUtil.ConfigPath() + m_szResverTxt, true); // 重读本地资源版本文件 m_pLocalResverIni.OpenFromTXT(PathUtil.ConfigPath() + m_szResverTxt); } else { //m_uiText.text = Localization.text( 403 ); m_uiText.text = ""; LogUtil.GetInstance().WriteGame("Has been the latest version"); } OnInited(); yield break; }
/// <summary> /// 打包 /// </summary> public static void BuildAssets(BuildTarget target) { // StreamingAssets 目录 string streamingAssetsPath = Application.dataPath + "/StreamingAssets/"; string StreamingAssetsPathUpload = Application.dataPath + "/../StreamingAssetsUpload/"; // 没有StreamingAssets就创建 if (!Directory.Exists(streamingAssetsPath)) { Directory.CreateDirectory(streamingAssetsPath); } if (!Directory.Exists(StreamingAssetsPathUpload)) { Directory.CreateDirectory(StreamingAssetsPathUpload); } // 清空StreamingAssets目录 clearDirectory(streamingAssetsPath); clearDirectory(StreamingAssetsPathUpload); //if ( Const.ResourceMode == "assetbundle" ) //{ BuildPipeline.BuildAssetBundles(StreamingAssetsPathUpload, BuildAssetBundleOptions.ChunkBasedCompression, target); //} //else // UnityEngine.Debug.Log( "Const.ResourceMode = " + Const.ResourceMode ); FileInfo fi = new FileInfo(StreamingAssetsPathUpload + "StreamingAssetsUpload"); fi.MoveTo(StreamingAssetsPathUpload + "StreamingAssets"); fi = new FileInfo(StreamingAssetsPathUpload + "StreamingAssetsUpload.manifest"); fi.MoveTo(StreamingAssetsPathUpload + "StreamingAssets.manifest"); // -------------------------------------- 资源版本文件部分 ------------------------------------------- // 修改app配置的版本号,每次打包+1 IniUtil resverIni = new IniUtil(); resverIni.OpenFromTXT(Application.dataPath + "/../Config/resver.txt"); int new_resource_version = Convert.ToInt32(resverIni.ReadValue("RESOURCE_VERSION", "0")) + 1; resverIni.WriteValue("RESOURCE_VERSION", new_resource_version); File.Copy(Application.dataPath + "/../Config/resver.txt", StreamingAssetsPathUpload + "resver.txt", true); // -------------------------------------- 配置文件部分 ------------------------------------------- // 配置文件在StreamingAssets文件夹中的路径 string targetTxtPath = StreamingAssetsPathUpload + "/Data/"; if (Directory.Exists(targetTxtPath)) { Directory.Delete(targetTxtPath, true); } Directory.CreateDirectory(targetTxtPath); paths.Clear(); files.Clear(); // 配置文件源路径 string sourceTxtPath = Application.dataPath + "/Resources/PackAssets/Data/"; // 递归遍历所有文件文件夹 Recursive(sourceTxtPath); // 遍历所有文件并复制 foreach (string f in files) { if (f.EndsWith(".meta") || f.EndsWith(".DS_Store")) { continue; } string newfile = f.Replace(sourceTxtPath, ""); if (newfile.Equals("user.txt")) { continue; } string newpath = targetTxtPath + newfile; string path = Path.GetDirectoryName(newpath); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } File.Copy(f, newpath, true); } // -------------------------------------- lua脚本部分 ------------------------------------------- // lua脚本在StreamingAssets文件夹中的路径 string luaPath = StreamingAssetsPathUpload + "Lua/"; if (Directory.Exists(luaPath)) { Directory.Delete(luaPath, true); } Directory.CreateDirectory(luaPath); paths.Clear(); files.Clear(); // lua脚本源路径 string luaDataPath = Application.dataPath + "/Lua/"; // 递归遍历所有文件文件夹 Recursive(luaDataPath); // 遍历所有文件并复制 foreach (string f in files) { if (!f.EndsWith(".lua")) { continue; } string newfile = f.Replace(luaDataPath, ""); string newpath = luaPath + newfile; string path = Path.GetDirectoryName(newpath); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } File.Copy(f, newpath, true); // if ( target == BuildTarget.StandaloneWindows || target == BuildTarget.StandaloneOSXUniversal ) // File.Copy( f, newpath, true ); // else //#if UNITY_STANDALONE_WIN // Execute( Application.dataPath + "/../../Public/ghlua.exe", f + " " + newpath, 0 ); //#else // Execute(Application.dataPath+"/../../Public/ghlua", f + " " + newpath, 0); //#endif //Execute(Application.dataPath+"/../../Public/luajit/luajit.exe", " -b " + f + " " + newpath, 0); //Execute(Application.dataPath + "/../../Public/luac/Luac.exe", " -o " + newpath + " " + f, 0); } // -------------------------------------- 所有文件列表部分 ------------------------------------------- // 文件列表 string newFilePath = StreamingAssetsPathUpload + "files.txt"; if (target == BuildTarget.Android) { newFilePath = StreamingAssetsPathUpload + "android_files.txt"; } else if (target == BuildTarget.iOS) { newFilePath = StreamingAssetsPathUpload + "ios_files.txt"; } else if (target == BuildTarget.StandaloneWindows) { newFilePath = StreamingAssetsPathUpload + "windows_files.txt"; } else if (target == BuildTarget.StandaloneOSXUniversal) { newFilePath = StreamingAssetsPathUpload + "osx_files.txt"; } // 如果文件存在删除文件 if (File.Exists(newFilePath)) { File.Delete(newFilePath); } paths.Clear(); files.Clear(); // 递归遍历所有文件文件夹 Recursive(StreamingAssetsPathUpload); // 创建文件列表 FileStream fs = new FileStream(newFilePath, FileMode.CreateNew); StreamWriter sw = new StreamWriter(fs); for (int i = 0; i < files.Count; i++) { string file = files[i]; string ext = Path.GetExtension(file); if (ext.Equals(".meta") || ext.Equals(".manifest") || ext.Equals(".DS_Store")) { continue; } // md5 值 string md5 = Utils.md5file(file); // 文件大小 FileInfo fileInfo = new FileInfo(file); long size = fileInfo.Length; // 文件相对路径 string value = file.Replace(StreamingAssetsPathUpload, string.Empty); sw.WriteLine(value + "|" + md5 + "|" + size); } sw.Close(); fs.Close(); // ------------------------------------------------------------------------------------------------------------------------------------------------------------ // -------------------------------------- 完毕以后,把StreamingAssetsUpload里的文件拷贝到StreamingAssets,刨去需要过滤的 ------------------------------------------- if (target == BuildTarget.Android || target == BuildTarget.StandaloneWindows) { foreach (string f in files) { //string filename = Path.GetFileName( f ); //if ( filename.Equals( "android_files.txt" ) ) // continue; //if ( filename.Equals( "ui_background" ) ) // continue; //if ( filename.Equals( "ui_background.manifest" ) ) // continue; //if ( filename.Equals( "ui_building" ) ) // continue; //if ( filename.Equals( "ui_building.manifest" ) ) // continue; //if ( filename.Equals( "ui_dialog" ) ) // continue; //if ( filename.Equals( "ui_dialog.manifest" ) ) // continue; //if ( filename.Equals( "ui_film" ) ) // continue; //if ( filename.Equals( "ui_film.manifest" ) ) // continue; //if ( filename.Equals( "ui_pre" ) ) // continue; //if ( filename.Equals( "ui_pre.manifest" ) ) // continue; //if ( filename.Equals( "tiled2unity" ) ) // continue; //if ( filename.Equals( "tiled2unity.manifest" ) ) // continue; //if ( filename.Equals( "mapthumb" ) ) // continue; //if ( filename.Equals( "mapthumb.manifest" ) ) // continue; //if ( filename.Equals( "mapcity" ) ) // continue; //if ( filename.Equals( "mapcity.manifest" ) ) // continue; //if ( filename.Equals( "building" ) ) // continue; //if ( filename.Equals( "building.manifest" ) ) // continue; //if ( filename.Equals( "char_1" ) ) // continue; //if ( filename.Equals( "char_1.manifest" ) ) // continue; //if ( filename.Equals( "city_0" ) ) // continue; //if ( filename.Equals( "city_0.manifest" ) ) // continue; //if ( filename.Equals( "effect_0" ) ) // continue; //if ( filename.Equals( "effect_0.manifest" ) ) // continue; //if ( filename.Equals( "effect_2" ) ) // continue; //if ( filename.Equals( "effect_2.manifest" ) ) // continue; string newfile = f.Replace("../StreamingAssetsUpload", "StreamingAssets"); string path = Path.GetDirectoryName(newfile); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } File.Copy(f, newfile, true); } } else if (target == BuildTarget.iOS) { foreach (string f in files) { string filename = Path.GetFileName(f); if (filename.Equals("ios_files.txt")) { continue; } string newfile = f.Replace("../StreamingAssetsUpload", "StreamingAssets"); string path = Path.GetDirectoryName(newfile); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } File.Copy(f, newfile, true); } } newFilePath = newFilePath.Replace("../StreamingAssetsUpload", "StreamingAssets"); // 如果文件存在删除文件 if (File.Exists(newFilePath)) { File.Delete(newFilePath); } paths.Clear(); files.Clear(); // 递归遍历所有文件文件夹 Recursive(streamingAssetsPath); // 从新创建文件列表 fs = new FileStream(newFilePath, FileMode.CreateNew); sw = new StreamWriter(fs); for (int i = 0; i < files.Count; i++) { string file = files[i]; string ext = Path.GetExtension(file); if (ext.Equals(".meta") || ext.Equals(".manifest") || ext.Equals(".DS_Store")) { continue; } // md5 值 string md5 = Utils.md5file(file); // 文件大小 FileInfo fileInfo = new FileInfo(file); long size = fileInfo.Length; // 文件相对路径 string value = file.Replace(streamingAssetsPath, string.Empty); sw.WriteLine(value + "|" + md5 + "|" + size); } sw.Close(); fs.Close(); AssetDatabase.Refresh(); //ZipProxy.compless(resPath, "z.zip"); }
public static void Save() { IniUtil.saveMethod(); }