public virtual void setLanguage(string language) { string languageFile = PStr.b( CLPathCfg.self.localizationPath, language, ".txt").e(); byte[] buff = null; #if UNITY_EDITOR if (CLCfgBase.self.isEditMode) { languageFile = PStr.b().a(CLPathCfg.persistentDataPath).a("/").a(languageFile).e(); languageFile = languageFile.Replace("/upgradeRes/", "/upgradeRes4Dev/"); buff = File.ReadAllBytes(languageFile); } else { #if UNITY_WEBGL languageFile = languageFile.Replace(".txt", ""); #endif buff = FileEx.readNewAllBytes(languageFile); } #else #if UNITY_WEBGL languageFile = languageFile.Replace(".txt", ""); #endif buff = FileEx.readNewAllBytes(languageFile); #endif Localization.Load(language, buff); }
// 时间格式化为:HH时mm分ss秒; public static string toStrCn(long ms) { int[] arr = getTimeArray(ms); int hour = arr[0] * 24 + arr[1]; String strHour = ""; String strMinute = ""; String strSecond = ""; if (hour > 0) { strHour = hour < 10 ? PStr.b().a("0").a(hour).e() : PStr.b().a(hour).a("").e(); strHour = PStr.b().a(strHour).a(Localization.Get("UIHour")).e(); } int minute = arr[2]; if (minute > 0) { strMinute = minute < 10 ? PStr.b().a("0").a(minute).e() : PStr.b().a(minute).a("").e(); strMinute = PStr.b().a(strMinute).a(Localization.Get("UIMinute")).e(); } int second = arr[3]; if (second >= 0) { strSecond = second < 10 ? PStr.b().a("0").a(second).e() : PStr.b().a(second).a("").e(); strSecond = PStr.b().a(strSecond).a(Localization.Get("UISecond")).e(); } return(PStr.b().a(strHour).a(strMinute).a(strSecond).e()); }
public override string getAssetPath(string name) { string path = PStr.b().a(CLPathCfg.self.basePath).a("/") .a(CLPathCfg.upgradeRes).a("/other/things").e(); return(wrapPath(path, name)); }
public void jump() { int len = orgStr.Length; if (len < 2) { return; } index++; if (index >= len) { index = 0; } string left = StrEx.Left(orgStr, index); string mid = StrEx.Mid(orgStr, index, 1); string right = StrEx.Right(orgStr, len - index - 1); string str = PStr.b() .a("[sub]") .a(left) .a("[/sup]") .a("[sup]").a(mid).a("[/sup]") .a("[sub]") .a(right) .a("[/sup]") .e(); base.text = str; timeCount = Time.time + speed; }
public static byte[] readBytesFromStreamingAssetsPath(string filepath) { byte[] buff = null; try { #if UNITY_ANDROID && !UNITY_EDITOR sbyte[] sbuff = null; string tempPath = filepath.Replace(PStr.b().a(Application.streamingAssetsPath).a("/").e(), ""); AndroidJavaObject obj = jcAssetMgr.CallStatic <AndroidJavaObject>("getBytes", tempPath); if (obj != null && obj.GetRawObject().ToInt32() != 0) { sbuff = AndroidJNIHelper.ConvertFromJNIArray <sbyte[]>(obj.GetRawObject()); } if (obj != null) { obj.Dispose(); obj = null; } buff = Array.ConvertAll <sbyte, byte>(sbuff, a => (byte)a); #else if (File.Exists(filepath)) { buff = File.ReadAllBytes(filepath); } #endif } catch (Exception e) { Debug.LogError(e); } return(buff); }
//-- 取得版本文件 static void getVerinfor(string fPath, string verVal) { //-- 注意是加了版本号的,可以使用cdn string url = PStr.b().a(baseUrl).a("/").a(fPath).a(".").a(verVal).e(); WWWEx.get(url, CLAssetType.bytes, (Callback)onGetVerinfor, (Callback)onGetVerinfor, fPath, true); }
public override void OnApplicationQuit() { base.OnApplicationQuit(); #if UNITY_EDITOR string atlasPath = PStr.b().a("Assets/").a(CLPathCfg.self.basePath).a("/upgradeRes4Dev/priority/atlas/atlasAllReal.prefab").e(); CLUIInit.self.emptAtlas.replacement = (UIAtlas)(AssetDatabase.LoadAssetAtPath(atlasPath, typeof(UIAtlas))); #endif }
static void checkVervers() { progress = 0; needUpgradeVerver.Clear(); isNeedUpgradePriority = false; string ver = null; ArrayList keysList = MapEx.keys2List(serververVer); int count = keysList.Count; string basePath = CLPathCfg.self.basePath; string key = ""; for (int i = 0; i < count; i++) { key = keysList[i] as string; ver = MapEx.getString(localverVer, key); //实际上这个时间localverVer是空的 if (ver == null || ver != MapEx.getString(serververVer, key)) { if (!key.Contains(PStr.b().a(basePath).a("/ui/panel").e()) && !key.Contains(PStr.b().a(basePath).a("/ui/cell").e()) && !key.Contains(PStr.b().a(basePath).a("/ui/other").e())) { MapEx.set(needUpgradeVerver, key, false); } } } keysList.Clear(); keysList = null; if (needUpgradeVerver.Count > 0) { if (progressCallback != null) { Utl.doCallback(progressCallback, needUpgradeVerver.Count, 0); } keysList = MapEx.keys2List(needUpgradeVerver); count = keysList.Count; key = ""; for (int i = 0; i < count; i++) { key = keysList[i] as string; getVerinfor(key, MapEx.getString(serververVer, key)); } keysList.Clear(); keysList = null; } else { loadPriorityVer(); loadOtherResVer(true); } }
static void onGetVerinfor(params object[] param) { byte[] content = param[0] as byte[]; object orgs = param[1]; if (content != null) { string fPath = orgs as string; progress = progress + 1; MapEx.set(localverVer, fPath, MapEx.getString(serververVer, fPath)); string fName = PStr.b().a(CLPathCfg.persistentDataPath).a("/").a(newestVerPath).a("/").a(fPath).e(); if (Path.GetFileName(fName) == "priority.ver") { //-- 优先更新需要把所有资源更新完后才记录 isNeedUpgradePriority = true; serverPriorityVer = CLVerManager.self.toMap(content); CLVerManager.self.localPriorityVer = serverPriorityVer; } else { otherResVerNew = CLVerManager.self.toMap(content); CLVerManager.self.otherResVerNew = otherResVerNew; } MapEx.set(needUpgradeVerver, fPath, true); if (progressCallback != null) { Utl.doCallback(progressCallback, needUpgradeVerver.Count, progress); } //-- if (isFinishAllGet()) then if (needUpgradeVerver.Count == progress) { if (!isNeedUpgradePriority) { //-- 说明没有优先资源需要更新,可以不做其它处理了 //--同步到本地 loadPriorityVer(); loadOtherResVer(true); } else { checkPriority(); //--处理优先资源更新 } } } else { initFailed(); } }
public static string nStrForLen(string str, int len) { try { string ret = ""; for (int i = 0; i < len - str.Length; i++) { ret = PStr.b().a(ret).a("0").e(); } return(PStr.b().a(ret).a(str).e()); } catch { return("0"); } }
public bool init() { clean(); #if !UNITY_EDITOR && !UNITY_WEBGL //取得最新的语言 Callback cb = onGetLocalize; StartCoroutine(FileEx.readNewAllBytesAsyn( PStr.b(CLPathCfg.self.localizationPath).a(Localization.language).a(".txt").e(), cb)); #endif return(initAtlas()); }
public static bool isNeedDownload(string roleName) { #if UNITY_EDITOR if (CLCfgBase.self.isEditMode) { return(false); } #endif string path = PStr.b().a(CLPathCfg.self.basePath).a("/") .a(CLPathCfg.upgradeRes).a("/other/roles").e(); path = wrapPath(path, roleName); return(CLVerManager.self.checkNeedDownload(path)); }
public static string ToTimeCost(long msec) { int day = 0, hour = 0, minute = 0, second = 0; string retstr = ""; long remainder; day = (int)(msec / 86400000); retstr = (day == 0) ? "" : PStr.b().a(day).a(Localization.Get("DayBefore")).e(); if (!string.IsNullOrEmpty(retstr)) { return(retstr); } remainder = msec % 86400000; if (remainder != 0) { hour = (int)remainder / 3600000; } // hour += day * 24; string hstr = ((retstr.Length > 0 || hour > 0) ? PStr.b().a(hour).a(Localization.Get("HourBefore")).e() : ""); retstr = PStr.b().a(retstr).a(hstr).e(); if (!string.IsNullOrEmpty(retstr)) { return(retstr); } remainder = remainder % 3600000; if (remainder != 0) { minute = (int)remainder / 60000; } // retstr += ((retstr.Length > 0 || minute > 0) ? (minute + Localization.Get("MinutesBefore")) : "0" + Localization.Get("MinutesBefore")); string mstr = ((retstr.Length > 0 || minute > 0) ? PStr.b().a(minute).a(Localization.Get("MinutesBefore")).e() : ""); retstr = PStr.b().a(retstr).a(mstr).e(); if (!string.IsNullOrEmpty(retstr)) { return(retstr); } second = (int)remainder % 60000; second = second / 1000; // retstr += (second < 10 ? "0" + second + Localization.Get("SecondBefore") : second + Localization.Get("SecondBefore")); retstr = PStr.b().a(retstr).a(second).a(Localization.Get("SecondBefore")).e(); return(retstr); }
static public string appendSpce(string str, int totalLen) { int i = 0; if (str == null || str == "") { str = ""; } i = str.Length; PStr ps = PStr.b(str); for (; i < totalLen; i++) { ps.a(" "); } return(ps.e()); }
public static string urlAddTimes(string url) { if (url.StartsWith("http://")) { if (url.Contains("?")) { url = PStr.b().a(url).a("&t_sign_flag___=").a(DateEx.nowMS).e(); } else { url = PStr.b().a(url).a("?t_sign_flag___=").a(DateEx.nowMS).e(); } #if CHL_NONE Debug.LogWarning(url); #endif } return(url); }
/// <summary> /// 获取文件大小 /// </summary> /// <param name="file">ip服务器下的相对路径</param> /// <returns>文件大小</returns> public int GetFileSize(string file, string host, string username, string password) { StringBuilder result = new StringBuilder(); try { string uri = PStr.b().a("ftp://").a(host).a(file).e(); request = (FtpWebRequest)FtpWebRequest.Create(new Uri(uri)); request.UseBinary = true; request.Credentials = new NetworkCredential(username, password); //设置用户名和密码 request.Method = WebRequestMethods.Ftp.GetFileSize; int dataLength = (int)request.GetResponse().ContentLength; return(dataLength); } catch (Exception ex) { Console.WriteLine("获取文件大小出错:" + ex.Message); return(-1); } }
public static string readTextFromStreamingAssetsPath(string filepath) { string buff = null; try { #if UNITY_ANDROID && !UNITY_EDITOR string tempPath = filepath.Replace(PStr.b().a(Application.streamingAssetsPath).a("/").e(), ""); buff = jcAssetMgr.CallStatic <string>("getString", tempPath); #else if (File.Exists(filepath)) { buff = File.ReadAllText(filepath); } #endif } catch (Exception e) { Debug.LogError(e); } return(buff); }
public static bool UploadDir(string localDir, string server, string username, string password, string remotePath, bool onlyCheckLastDir = false) { if (!Directory.Exists(localDir)) { Debug.LogError("There is no directory exist!"); return(false); } FTP ftp = new FTP(server, username, password); ftp.MakeFTPDir(remotePath, onlyCheckLastDir); string[] files = Directory.GetFiles(localDir); string file = ""; if (files != null) { FtpWebRequest request = null; for (int i = 0; i < files.Length; i++) { file = files [i]; // Debug.Log (file); ftp = new FTP(server, username, password); if (!ftp.Upload(file, remotePath)) { return(false); } } } string[] dirs = Directory.GetDirectories(localDir); if (dirs != null) { for (int i = 0; i < dirs.Length; i++) { // Debug.Log (PStr.b ().a (remotePath).a ("/").a (Path.GetFileName (dirs [i])).e ()); if (!UploadDir(dirs [i], server, username, password, PStr.b().a(remotePath).a("/").a(Path.GetFileName(dirs [i])).e(), true)) { return(false); } } } return(true); }
public static string ToTimeStr3(long msec) { // 将毫秒数换算成x天x时 int day = 0, hour = 0, minute = 0, second = 0; string retstr = ""; long remainder; day = (int)(msec / 86400000); retstr = (day == 0) ? "" : PStr.b().a(day).a(Localization.Get("UIDay")).e(); remainder = msec % 86400000; if (remainder != 0) { hour = (int)remainder / 3600000; } string hstr = ((retstr.Length > 0 || hour > 0) ? PStr.b().a(hour).a(Localization.Get("UIHour")).e() : ""); return(PStr.b().a(retstr).a(hstr).e()); }
public static string ToTimeStr2(long msec) { // 将毫秒数换算成x天x时x分x秒x毫秒 int day = 0, hour = 0, minute = 0, second = 0; string retstr = ""; long remainder; day = (int)(msec / 86400000); retstr = (day == 0) ? "" : PStr.b().a(day).a(Localization.Get("UIDay")).e(); remainder = msec % 86400000; if (remainder != 0) { hour = (int)remainder / 3600000; } // hour += day * 24; // retstr += ((retstr.Length > 0 || hour > 0) ? (hour < 10 ? "0" + hour + Localization.Get("UIHour") : hour + Localization.Get("UIHour")) : ""); string hstr = ((retstr.Length > 0 || hour > 0) ? PStr.b().a(hour).a(Localization.Get("UIHour")).e() : ""); retstr = PStr.b().a(retstr).a(hstr).e(); remainder = remainder % 3600000; if (remainder != 0) { minute = (int)remainder / 60000; } // retstr += ((retstr.Length > 0 || minute > 0) ? (minute < 10 ? "0" + minute + Localization.Get("UIMinute") : minute + Localization.Get("UIMinute")) : "00" + Localization.Get("UIMinute")); string mstr = ((retstr.Length > 0 || minute > 0) ? PStr.b().a(minute).a(Localization.Get("UIMinute")).e() : ""); retstr = PStr.b().a(retstr).a(mstr).e(); second = (int)remainder % 60000; second = second / 1000; retstr = PStr.b().a(retstr).a(second).a(Localization.Get("UISecond")).e(); return(retstr); }
public static string ToTimeStr(long msec) { // 将毫秒数换算成x天x时x分x秒x毫秒 int day = 0, hour = 0, minute = 0, second = 0; string retstr = ""; long remainder; day = (int)(msec / 86400000); retstr = (day == 0) ? "" : PStr.b().a(day).a(":").e(); remainder = msec % 86400000; if (remainder != 0) { hour = (int)remainder / 3600000; } hour += day * 24; string hstr = ((retstr.Length > 0 || hour > 0) ? (hour < 10 ? PStr.b().a("0").a(hour).a(":").e() : PStr.b().a(hour).a(":").e()) : ""); retstr = PStr.b().a(retstr).a(hstr).e(); remainder = remainder % 3600000; if (remainder != 0) { minute = (int)remainder / 60000; } string mstr = ((retstr.Length > 0 || minute > 0) ? (minute < 10 ? PStr.b().a("0").a(minute).a(":").e() : PStr.b().a(minute, ":").e()) : "00:"); retstr = PStr.b().a(retstr).a(mstr).e(); second = (int)remainder % 60000; second = second / 1000; string sstr = (second < 10 ? PStr.b().a("0", second).e() : PStr.b().a(second, "").e()); retstr = PStr.b().a(retstr).a(sstr).e(); return(retstr); }
public void MakeFTPDir(string pathToCreate, bool onlyCheckLastDir) { Uri address = null; FtpWebRequest request = null; Stream ftpStream = null; string[] subDirs = pathToCreate.Split('/'); if (subDirs.Length == 0) { return; } string currentDir = PStr.b().a("ftp://").a(host).e(); string subDir = ""; int i = 0; if (onlyCheckLastDir) { i = subDirs.Length - 1; currentDir = PStr.b().a(currentDir).a(Path.GetDirectoryName(pathToCreate)).e(); } else { i = 0; } for (; i < subDirs.Length; i++) { subDir = subDirs [i]; if (string.IsNullOrEmpty(subDir)) { continue; } try { currentDir = PStr.b().a(currentDir).a("/").a(subDir).e(); // Debug.Log("login==" + login); // Debug.Log("password==" + password); // Debug.Log("currentDir====" + currentDir); address = new Uri(currentDir); request = FtpWebRequest.Create(address) as FtpWebRequest; // Upload options: // Provide credentials request.Credentials = new NetworkCredential(user, password); // Set control connection to closed after command execution request.KeepAlive = false; // Specify command to be executed request.Method = WebRequestMethods.Ftp.MakeDirectory; // Specify data transfer type request.UseBinary = true; FtpWebResponse response = (FtpWebResponse)request.GetResponse(); ftpStream = response.GetResponseStream(); ftpStream.Close(); response.Close(); } catch (Exception ex) { //directory already exist I know that is weak but there is no way to check if a folder exist on ftp... // Debug.LogError(ex); // return false; } } }
public static byte[] myLuaLoader(ref string filepath) { byte[] bytes = null; string luaPath = ""; string strs = ""; try { if (!filepath.StartsWith(CLPathCfg.self.basePath)) { //说明是通过require进来的 filepath = filepath.Replace(".", "/"); filepath = PStr.b().a(CLPathCfg.self.basePath).a("/upgradeRes/priority/lua/").a(filepath).a(".lua").e(); } #if UNITY_EDITOR if (CLCfgBase.self.isEditMode) { filepath = filepath.Replace("/upgradeRes/", "/upgradeRes4Dev/"); luaPath = PStr.b().a(Application.dataPath).a("/").a(filepath).e(); bytes = MapEx.getBytes(FileBytesCacheMap, luaPath); if (bytes != null) { filepath = luaPath; return(bytes); } if (File.Exists(luaPath)) { strs = FileEx.getTextFromCache(luaPath); bytes = System.Text.Encoding.UTF8.GetBytes(strs); filepath = luaPath; return(bytes); } } #endif //======================================================= //1.first load from CLPathCfg.persistentDataPath; luaPath = PStr.b().a(CLPathCfg.persistentDataPath).a("/").a(filepath).e(); bytes = MapEx.getBytes(FileBytesCacheMap, luaPath); if (bytes != null) { filepath = luaPath; return(bytes); } if (File.Exists(luaPath)) { bytes = FileEx.getBytesFromCache(luaPath); if (bytes != null) { // bytes = System.Text.Encoding.UTF8.GetBytes(strs); bytes = deCodeLua(bytes); FileBytesCacheMap [luaPath] = bytes; filepath = luaPath; return(bytes); } } //======================================================= //2.second load from Application.streamingAssetsPath; luaPath = PStr.b().a(Application.streamingAssetsPath).a("/").a(filepath).e(); bytes = MapEx.getBytes(FileBytesCacheMap, luaPath); if (bytes != null) { filepath = luaPath; return(bytes); } bytes = FileEx.getBytesFromCache(luaPath); if (bytes != null) { // bytes = System.Text.Encoding.UTF8.GetBytes(strs); bytes = deCodeLua(bytes); FileBytesCacheMap [luaPath] = bytes; filepath = luaPath; return(bytes); } //======================================================= //3.third load from Resources.Load (); luaPath = filepath; bytes = MapEx.getBytes(FileBytesCacheMap, luaPath); if (bytes != null) { filepath = luaPath; return(bytes); } TextAsset text = Resources.Load <TextAsset> (filepath); if (text != null) { bytes = text.bytes; // System.Text.Encoding.UTF8.GetBytes(text.text); if (bytes != null) { bytes = deCodeLua(bytes); FileBytesCacheMap [luaPath] = bytes; filepath = luaPath; return(bytes); } } //========================== return(bytes); } catch (System.Exception e) { Debug.LogError(luaPath + ":" + e); return(null); } }
/// <summary> /// Uploads a file through FTP. /// </summary> /// <param name="filename">The path to the file to upload.</param> /// <param name="server">The server to use.</param> /// <param name="username">The username to use.</param> /// <param name="password">The password to use.</param> /// <param name="initialPath">The path on the server to upload to.</param> public bool Upload(string localFile, string server, string username, string password, string remotePath, ref float progress) { // MakeFTPDir (server, remotePath, username, password, onlyCheckLastDir); var file = new FileInfo(localFile); string url = PStr.b().a("ftp://").a(server).a(Path.Combine(remotePath, file.Name)).e(); // Debug.Log (localFile); Debug.Log(url); // Debug.Log (username); // Debug.Log (password); var address = new Uri(url); request = FtpWebRequest.Create(address) as FtpWebRequest; // Upload options: // Provide credentials request.Credentials = new NetworkCredential(username, password); // Set control connection to closed after command execution request.KeepAlive = false; // Specify command to be executed request.Method = WebRequestMethods.Ftp.UploadFile; // Specify data transfer type request.UseBinary = true; // Notify server about size of uploaded file request.ContentLength = file.Length; // Set buffer size to 2KB. var bufferLength = 2048; var buffer = new byte[bufferLength]; var contentLength = 0; int countLen = 0; // Open file stream to read file var fs = file.OpenRead(); Stream stream = null; try { // Stream to which file to be uploaded is written. stream = request.GetRequestStream(); // Read from file stream 2KB at a time. contentLength = fs.Read(buffer, 0, bufferLength); // Loop until stream content ends. while (contentLength != 0) { //Debug.Log("Progress: " + ((fs.Position / fs.Length) * 100f)); // Write content from file stream to FTP upload stream. stream.Write(buffer, 0, contentLength); contentLength = fs.Read(buffer, 0, bufferLength); countLen += contentLength; progress = ((float)countLen) / request.ContentLength; } // Close file and request streams stream.Close(); fs.Close(); } catch (Exception e) { if (stream != null) { stream.Close(); } if (fs != null) { fs.Close(); } Debug.LogError("Error uploading file: " + e); return(false); } Debug.Log("Upload successful."); return(true); }
public static string toHHMMSS(long ms) { int[] ss = getTimeArray(ms); return(PStr.b().a(ss[1]).a(":").a(ss[2]).a(":").a(ss[3]).e()); }
public static string toHHMMSS2(long ms) { int[] ss = getTimeArray(ms); return(PStr.b().a(ss[1]).a(Localization.Get("UIHour")).a(ss[2]).a(Localization.Get("UIMinute")).a(ss[3]).a(Localization.Get("UISecond")).e()); }