/// <summary> /// 下载完成. /// </summary> /// <param name="iTargetID">目标ID.</param> /// <param name="iFileType">文件类型.</param> public void DownloadCompleted(string iTargetID, TUploadFileType iFileType) { lock (_targetUpdateLock) { DownloadTargetInfo downloadInfo = null; if (this.isTargetExist(iTargetID, iFileType, out downloadInfo) == true) { if (downloadInfo == null) { return; } downloadInfo.Downloaded = true; if (this._progressCounter != null) { this._progressCounter.UpdateCompletedCount(); long dataSize = (string.IsNullOrEmpty(downloadInfo.DataSize) == true) ? 0 : Convert.ToInt64(downloadInfo.DataSize); this._progressCounter.UpdateCompletedDataSize(dataSize); UtilsLog.Info("DownloadCompleted", "Count({0}/{1}) DataSize({2}/{3})", this._progressCounter.DidCount, this._progressCounter.TotalCount, this._progressCounter.DidDatasize, this._progressCounter.TotalDatasize); } } } }
/// <summary> /// 追加宏. /// </summary> /// <param name="iAddNewDefine">新追加的宏.</param> private void AddDefine(string iName, bool iAndroid, bool iIOS) { if ((true == string.IsNullOrEmpty(iName)) || (null == this.Defines)) { return; } bool isExist = false; foreach (DefineInfo define in this.Data.Defines) { if (true == string.IsNullOrEmpty(define.Name)) { continue; } if (true == iName.Equals(define.Name)) { define.Android = iAndroid; define.iOS = iIOS; isExist = true; break; } } if (false == isExist) { DefineInfo _define = new DefineInfo(iName, iAndroid, iIOS); this.Defines.Add(_define); } // 按名字排序 this.Defines.Sort((x, y) => (x.Name.CompareTo(y.Name))); UtilsLog.Info("DefinesWindow", "AddDefine -> Name:{0} Andorid:{1} iOS:{2}", iName, iAndroid, iIOS); }
/// <summary> /// 添加对象. /// </summary> /// <param name="iTarget">上传目标.</param> public void AddTarget(UploadItem iTarget) { DownloadTargetInfo target = null; if (false == isTargetExist(iTarget.ID, iTarget.FileType, out target)) { target = new DownloadTargetInfo(); this.Targets.Add(target); target.No = iTarget.No; target.ID = iTarget.ID; target.BundleType = iTarget.BundleType; target.FileType = iTarget.FileType; target.DataSize = iTarget.DataSize; target.CheckCode = iTarget.CheckCode; target.Downloaded = false; UtilsLog.Info("AddTarget", "New:{0}", iTarget.toString()); } else { // 变更的场合 if (false == iTarget.CheckCode.Equals(target.CheckCode)) { target.DataSize = iTarget.DataSize; target.CheckCode = iTarget.CheckCode; target.Downloaded = false; UtilsLog.Info("AddTarget", "Changed:{0}", iTarget.toString()); } } }
public static string ProcessBaseURL(string baseURL, UrlMode currentMode) { string result = ""; switch (currentMode) { case UrlMode.Local: { result = baseURL.Replace("<BundleVersion>", BundleVersion).Replace("<ServerRoot>", LocalServerRoot).Replace("<Platform>", Platform).Replace("<ConfigType>", ConfigType).Replace("<BuildTag>", BuildTag).Replace("<MarketVersion>", MarketVersion); } break; case UrlMode.Default: { result = baseURL.Replace("<BundleVersion>", BundleVersion).Replace("<ServerRoot>", PublicServerRoot).Replace("<Platform>", Platform).Replace("<ConfigType>", ConfigType).Replace("<BuildTag>", BuildTag).Replace("<MarketVersion>", MarketVersion); } break; default: { result = baseURL.Replace("<BundleVersion>", BundleVersion).Replace("<ServerRoot>", PublicServerRoot).Replace("<Platform>", Platform).Replace("<ConfigType>", ConfigType).Replace("<BuildTag>", BuildTag).Replace("<MarketVersion>", MarketVersion); } break; } UtilsLog.Info("AssetBundleConst", "ProcessBaseURL()::result:{0}", result); return(result); }
/// <summary> /// 设定宏. /// </summary> /// <param name="iDefines">宏.</param> /// <param name="iTargetGroup">目标组.</param> public static void SetDefines(DefineInfo[] iDefines, BuildTargetGroup iTargetGroup) { if ((null == iDefines) || (0 >= iDefines.Length)) { return; } string _defines = null; foreach (DefineInfo define in iDefines) { if (true == string.IsNullOrEmpty(define.Name)) { continue; } if (true == string.IsNullOrEmpty(_defines)) { _defines = define.Name; } else { _defines = string.Format("{0};{1}", _defines, define.Name); } } if (false == string.IsNullOrEmpty(_defines)) { PlayerSettings.SetScriptingDefineSymbolsForGroup(iTargetGroup, _defines); UtilsLog.Info("DefinesSetting", "SetDefines -> Target:{0} Defines:{1}", iTargetGroup, _defines); BuildLogger.LogMessage("DefinesSetting()::Defines({0}):{1}", iTargetGroup.ToString(), _defines); } }
/// <summary> /// 根据检测模式检测已下载的文件. /// </summary> /// <returns><c>true</c>, OK, <c>false</c> NG.</returns> /// <param name="iTarget">目标信息.</param> /// <param name="iDownloadFileFullPath">已经下载到本地的路径.</param> private bool CheckFileByCheckMode(DownloadTargetInfo iTarget, string iDownloadFileFullPath) { if (File.Exists(iDownloadFileFullPath) == false) { return(false); } bool isCheckOK = true; switch (UploadList.GetInstance().CheckMode) { case TCheckMode.Unity3d_Hash128: { UtilsLog.Info("CheckFileByCheckMode", "The Unity3d_Hash128 of check mode has not been supported yet!!!"); isCheckOK = false; } break; case TCheckMode.Custom_Md5: { string md5 = UploadList.GetFileMD5(iDownloadFileFullPath); if ((true == string.IsNullOrEmpty(md5)) || (false == md5.Equals(iTarget.CheckCode))) { isCheckOK = false; } } break; default: break; } return(isCheckOK); }
public static void RestoreFinished() { UtilsLog.Info("IAPMsgSwitch", "[RestoreFinished]"); if ((null != IAPInstance) && (null != IAPInstance.OnRestoreFinished)) { IAPInstance.OnRestoreFinished(); } }
public static void IAPFailed(IAPErrorCode iErrorCode, Int32 iErrorDetailCode, string iErrorDetailInfo) { UtilsLog.Info("IAPMsgSwitch", "[IAPFailed] ErrorCode::{0} ErrorDetailCode::{1} ErrorDetail::{2}", iErrorCode, iErrorDetailCode, iErrorDetailInfo); if ((null != IAPInstance) && (null != IAPInstance.OnFailed)) { IAPInstance.OnFailed(iErrorCode, iErrorDetailCode, iErrorDetailInfo); } }
/// <summary> /// 初始化. /// </summary> /// <param name="iTotalCount">I total count.</param> /// <param name="iTotalDatasize">I total datasize.</param> public void Init(int iTotalCount, long iTotalDatasize) { this.TotalCount = iTotalCount; this.DidCount = 0; this.TotalDatasize = iTotalDatasize; this.DidDatasize = 0; UtilsLog.Info("Init", "{0}/{1} {2}/{3}", this.DidCount, this.TotalCount, this.DidDatasize, this.TotalDatasize); }
public static void TransactionUpdated(string productID, TransactionState state, string transactionID, string receipt, Int32 quantity) { UtilsLog.Info("IAPMsgSwitch", "[TransactionUpdated] ProductID:{0}({1}) State:{2} TransactionID:{3} Receipt:{4}", ((true == string.IsNullOrEmpty(productID)) ? "null" : productID), quantity, state.ToString(), ((true == string.IsNullOrEmpty(transactionID)) ? "null" : transactionID), ((true == string.IsNullOrEmpty(receipt)) ? "null" : receipt)); switch (state) { case TransactionState.Purchasing: if ((null != IAPInstance) && (null != IAPInstance.OnTransactionPurchasing)) { IAPInstance.OnTransactionPurchasing(productID, quantity); } break; case TransactionState.Purchased: { if ((null != IAPInstance) && (null != IAPInstance.OnTransactionPurchased)) { IAPInstance.OnTransactionPurchased(productID, quantity, transactionID, receipt); } } break; case TransactionState.Canceled: { if ((null != IAPInstance) && (null != IAPInstance.OnTransactionCanceled)) { IAPInstance.OnTransactionCanceled(productID, quantity); } } break; case TransactionState.Restored: if (IAPVerifyTransaction(transactionID)) { if ((null != IAPInstance) && (null != IAPInstance.OnTransactionRestored)) { IAPInstance.OnTransactionRestored(productID, quantity, transactionID, receipt); } } break; case TransactionState.Deferred: { if ((null != IAPInstance) && (null != IAPInstance.OnTransactionDeferred)) { IAPInstance.OnTransactionDeferred(productID); } } break; } }
/// <summary> /// 初始化Asset. /// </summary> public override bool InitAsset() { DownloadRootDir = Application.temporaryCachePath; UtilsLog.Info("InitAsset", "DownloadRootDir:{0}", DownloadRootDir); // 下载目录 DownloadDir = string.Format("{0}/Downloads", DownloadRootDir); UtilsLog.Info("InitAsset", "DownloadDir:{0}", DownloadDir); // 下载目录(Normal) DownloadDirOfNormal = string.Format("{0}/{1}", DownloadDir, UploadList.AssetBundleDirNameOfNormal); UtilsLog.Info("InitAsset", "DownloadDirOfNormal:{0}", DownloadDirOfNormal); // 下载目录(Scenes) DownloadDirOfScenes = string.Format("{0}/{1}", DownloadDir, UploadList.AssetBundleDirNameOfScenes); UtilsLog.Info("InitAsset", "DownloadDirOfScenes:{0}", DownloadDirOfScenes); // Bundles目录 BundlesDir = string.Format("{0}/Bundles", Application.persistentDataPath); UtilsLog.Info("InitAsset", "BundlesDir:{0}", BundlesDir); // Bundles目录(Normal) BundlesDirOfNormal = string.Format("{0}/{1}", BundlesDir, UploadList.AssetBundleDirNameOfNormal); UtilsLog.Info("InitAsset", "BundlesDirOfNormal:{0}", BundlesDirOfNormal); // Scene BundlesDirOfScenes = string.Format("{0}/{1}", BundlesDir, UploadList.AssetBundleDirNameOfScenes); UtilsLog.Info("InitAsset", "BundlesDirOfScenes:{0}", BundlesDirOfScenes); // 解压缩 DecompressedDir = string.Format("{0}/Decompressed", DownloadRootDir); UtilsLog.Info("InitAsset", "DecompressedDir:{0}", DecompressedDir); // 解压缩(Normal) DecompressedDirOfNormal = string.Format("{0}/{1}", DecompressedDir, UploadList.AssetBundleDirNameOfNormal); UtilsLog.Info("InitAsset", "DecompressedDirOfNormal:{0}", DecompressedDirOfNormal); // 解压缩(Scenes) DecompressedDirOfScenes = string.Format("{0}/{1}", DecompressedDir, UploadList.AssetBundleDirNameOfScenes); UtilsLog.Info("InitAsset", "DecompressedDirOfScenes:{0}", DecompressedDirOfScenes); UtilsAsset.SetAssetDirty(this); return(base.InitAsset()); }
/// <summary> /// 检测下载用的目录. /// </summary> /// <param name="iDir">检测目录.</param> private void CheckDownloadDirs(string iDir) { if (string.IsNullOrEmpty(iDir) == true) { return; } if (false == Directory.Exists(iDir)) { Directory.CreateDirectory(iDir); UtilsLog.Info("CheckDownloadDirs", " Create Dir:{0}", iDir); if (false == Directory.Exists(iDir)) { UtilsLog.Error("CheckDownloadDirs", " Create Dir Failed!! Dir:{0}", iDir); } } }
/// <summary> /// 下载完毕拷贝文件. /// </summary> public void CopyTargetWhenDownloadCompleted() { string copyFrom = null; string copyTo = null; switch (this.BundleType) { case TBundleType.Scene: { copyFrom = ServersConf.DownloadDirOfScenes; copyTo = ServersConf.BundlesDirOfScenes; } break; case TBundleType.Normal: { copyFrom = ServersConf.DownloadDirOfNormal; copyTo = ServersConf.BundlesDirOfNormal; } break; default: { copyFrom = ServersConf.DownloadDir; copyTo = ServersConf.BundlesDir; } break; } string fileName = UploadList.GetLocalBundleFileName(this.ID, this.FileType); copyFrom = string.Format("{0}/{1}", copyFrom, fileName); copyTo = string.Format("{0}/{1}", copyTo, fileName); if (true == File.Exists(copyFrom)) { File.Copy(copyFrom, copyTo, true); UtilsLog.Info("CopyTargetWhenDownloadCompleted", "Copy File:{0} -> {1}", copyFrom, copyTo); } if (false == File.Exists(copyTo)) { UtilsLog.Error("CopyTargetWhenDownloadCompleted", "Failed!! FileName:{0} -> {1}", copyFrom, copyTo); } File.Delete(copyFrom); UtilsLog.Info("CopyTargetWhenDownloadCompleted", "Delete File -> {0}", copyFrom); }
/// <summary> /// 在Ftp服务器上创建文件夹. /// </summary> /// <param name="iUrl">URL.</param> /// <param name="iAccountId">账户.</param> /// <param name="iPwd">密码.</param> private TDirState CreateDirOnFtpServer( string iUrl, string iAccountId, string iPwd) { FtpWebRequest ftpRequest = null; FtpWebResponse response = null; TDirState state = TDirState.None; try { Uri targetURI = new Uri(iUrl); ftpRequest = (FtpWebRequest)FtpWebRequest.Create(targetURI); ftpRequest.Credentials = new NetworkCredential(iAccountId, iPwd); ftpRequest.KeepAlive = false; ftpRequest.Method = WebRequestMethods.Ftp.MakeDirectory; ftpRequest.UseBinary = true; response = ftpRequest.GetResponse() as FtpWebResponse; state = TDirState.Created; UtilsLog.Info("CreateDirOnFtpServer", "Successed Url:{0}", iUrl); } catch (WebException exp) { UtilsLog.Exception("CreateDirOnFtpServer", "Failed!!! Url:{0} \n WebException: \n {1}", iUrl, exp.Message); state = TDirState.Exception; } catch (IOException exp) { UtilsLog.Exception("CreateDirOnFtpServer", "Failed!!! Url:{0} \n IOException: \n {1}", iUrl, exp.Message); state = TDirState.Exception; } catch (Exception exp) { UtilsLog.Exception("CreateDirOnFtpServer", "Failed!!! Url:{0} \n Exception: \n {1}", iUrl, exp.Message); state = TDirState.Exception; } finally { if (response != null) { response.Close(); } } return(state); }
/// <summary> /// 上传成功委托. /// </summary> /// <param name="iUploader">上传器.</param> /// <param name="iTargetInfo">下载目标信息.</param> /// <param name="iIsManifest">manifest标志位.</param> /// <param name="iRetries">剩余重试次数.</param> public void OnUploadSuccessed(Uploader iUploader, UploadItem iTargetInfo, int iRetries) { UtilsLog.Info("OnUploadSuccessed", "No:{0} State:{1} Retries:{2}", iTargetInfo.toString(), this._State, iRetries); UploadList.GetInstance().UploadCompleted(iTargetInfo.ID, iTargetInfo.FileType); if (null != iUploader) { iUploader.Dispose(); GC.Collect(); } lock (_uploaderCountLock) { --this.UploaderCount; } }
/// <summary> /// 删除宏. /// </summary> /// <param name="iDelDefine">删除的宏索引.</param> private void DelDefine(int iDelDefineIdx) { if ((-1 >= iDelDefineIdx) || (null == this.Defines)) { return; } isPause = true; DefineInfo _delDefine = this.Defines[iDelDefineIdx]; this.Defines.RemoveAt(iDelDefineIdx); // 按名字排序 this.Defines.Sort((x, y) => (x.Name.CompareTo(y.Name))); UtilsLog.Info(this.ClassName, "DelDefine -> Name:{0} Andorid:{1} iOS:{2}", _delDefine.Name, _delDefine.Android, _delDefine.iOS); isPause = false; }
/// <summary> /// 拷贝库资源文件. /// </summary> public void CopyResources() { string CopyFromDir = GetAndroidCopyFromDir(); string CopyToDir = GetAndroidCopyToDir(); // Libs string[] files = Directory.GetFiles(CopyFromDir); foreach (string file in files) { if (true == file.EndsWith("AndroidManifest.xml")) { continue; } if (true == file.EndsWith(".meta")) { continue; } int lastIndex = file.LastIndexOf("/"); string fileName = file.Substring(lastIndex + 1); if (true == string.IsNullOrEmpty(fileName)) { continue; } string copyToFile = string.Format("{0}/{1}", CopyToDir, fileName); if (true == File.Exists(copyToFile)) { File.Delete(copyToFile); } UtilsLog.Info("CopyResources", "Copy Libs : {0} -> {1}", file, copyToFile); File.Copy(file, copyToFile); } // res string CopyRes = string.Format("{0}/res", CopyFromDir); if (true == Directory.Exists(CopyRes)) { UtilsAsset.CopyDirectory(CopyRes, CopyToDir); } }
/// <summary> /// 追加宏. /// </summary> /// <param name="iAddNewDefine">新追加的宏.</param> public void AddDefines(string[] iNames, bool iAndroid, bool iIOS) { if ((null == iNames) || (0 >= iNames.Length) || (null == this.Defines)) { return; } foreach (string defineName in iNames) { bool isExist = false; foreach (DefineInfo define in this.Defines) { if (true == string.IsNullOrEmpty(define.Name)) { continue; } if (true == defineName.Equals(define.Name)) { if (true == iAndroid) { define.Android = iAndroid; } if (true == iIOS) { define.iOS = iIOS; } isExist = true; break; } } if (false == isExist) { DefineInfo _define = new DefineInfo(defineName, iAndroid, iIOS); this.Defines.Add(_define); UtilsLog.Info("DefinesData", "AddDefine -> Name:{0} Andorid:{1} iOS:{2}", defineName, iAndroid, iIOS); } } // 按名字排序 this.Defines.Sort((x, y) => (x.Name.CompareTo(y.Name))); }
/// <summary> /// 初始化窗口尺寸信息. /// </summary> /// <param name="iDisplayRect">表示范围.</param> protected override void InitWindowSizeInfo(Rect iDisplayRect) { base.InitWindowSizeInfo(iDisplayRect); Rect _ScrollViewRect = iDisplayRect; // 标题行 _ScrollViewRect.y += LineHeight; _ScrollViewRect.height -= LineHeight; // 输入框 _ScrollViewRect.height -= LineHeight; // 清空,导入,导出按钮行 _ScrollViewRect.height -= LineHeight * 1.5f; ScrollViewRect = _ScrollViewRect; UtilsLog.Info(this.ClassName, "InitWindowSizeInfo ScrollViewRect(X:{0} Y:{1} Width:{2} Height:{3})", ScrollViewRect.x, ScrollViewRect.y, ScrollViewRect.width, ScrollViewRect.height); }
/// <summary> /// 更新本地信息,为下一步下载做准备. /// </summary> public void UpdateLocalInfoForDownload() { // bundles目录 string bundlesDir = ServersConf.BundlesDir; // 导入Bundle包依赖关系 BundlesMap.GetInstance().ImportFromJsonFile(bundlesDir, true); // 导入已经有下载信息 DownloadList.GetInstance().ImportFromJsonFile(bundlesDir, true); // 将已经下载的最新依赖列表文件更新本地依赖列表 string downloadDir = ServersConf.DownloadDir; // 不清空本地 BundlesMap.GetInstance().ImportFromJsonFile(downloadDir, false); // 从最新的上传列表更新下载信息 // 抽出条件 // 1)上传完毕 // 2)没有被废弃 UploadItem[] targets = this.Targets .Where(o => ( (false == o.Scraped))) .OrderBy(o => o.No) .ToArray(); if ((targets == null) || (targets.Length <= 0)) { UtilsLog.Info("UpdateLocalInfoForDownload", "There is no target to download!!!"); return; } UtilsLog.Info("UpdateLocalInfoForDownload", "Targets Count:{0}", targets.Length.ToString()); foreach (UploadItem Loop in targets) { DownloadList.GetInstance().AddTarget(Loop); } // 初始化进度计数器 DownloadList.GetInstance().InitProgressCounter(); }
private void Log(string message, TLogType iType = TLogType.kInfo) { System.Console.WriteLine(message); if (BuildParameters.IsBuildInCI == false) { switch (iType) { case TLogType.kInfo: { UtilsLog.Info("ConsoleBuildLogger", message); } break; case TLogType.kWarning: { UtilsLog.Warning("ConsoleBuildLogger", message); } break; case TLogType.kError: { UtilsLog.Error("ConsoleBuildLogger", message); } break; case TLogType.kException: { UtilsLog.Exception("ConsoleBuildLogger", message); } break; default: break; } } }
public static void CreateProduct(string title, string description, string identifier, float price, string priceString, string currency, string code, string locale, string iCountryCode) { UtilsLog.Info("IAPMsgSwitch", "[CreateProduct] Title:{0} Description:{1} Identifier:{2} Price:{3} PriceString:{4} Currency:{5} Code:{6} Locale:{7} CountryCode:{8}", title, description, identifier, price.ToString(), priceString, currency, code, locale, iCountryCode); if (string.IsNullOrEmpty(identifier) == false) { // this is an actual product info Product received = new Product { ProductID = identifier, Title = title, Description = description, Price = (decimal)price, PriceAsString = priceString, CurrencySymbol = currency, CurrencyCode = code, LocaleIdentifier = locale, CountryCode = iCountryCode }; if (null != IAPInstance) { IAPInstance.AddProduct(received); } } else { // special case to mark the end of the product list or a validation error if (string.IsNullOrEmpty(description) == true) { if (null != IAPInstance) { IAPInstance.OnProductsValidationFinished(); } } // description contains error message, and price contains error code else { if ((null != IAPInstance) && (null != IAPInstance.OnProductsValidationFailed)) { IAPInstance.OnProductsValidationFailed(description, (Int32)price); } } } }
/// <summary> /// 下载成功回调函数. /// </summary> /// <param name="iDownloadInfo">下载信息.</param> /// <param name="iRetries">重试次数.</param> public void OnDownloadSuccessed(DownloaderBase iDownloader, DownloadTargetInfo iDownloadInfo, int iRetries) { UtilsLog.Info("OnDownloadSuccessed", "Download Successed. {0} Retries:{1}", iDownloadInfo.toString(), iRetries); DownloadList.GetInstance().DownloadCompleted(iDownloadInfo.ID, iDownloadInfo.FileType); if (true == iDownloadInfo.Downloaded) { // 文件拷贝 iDownloadInfo.CopyTargetWhenDownloadCompleted(); if (iDownloader != null) { iDownloader.Dispose(); GC.Collect(); } lock (_downloaderCountLock) { --this.DownloaderCount; } } }
/// <summary> /// 上传上传列表列表信息. /// </summary> /// <param name="iServerInfo">服务器信息.</param> private string UploadUploadListFile(UploadServerInfo iServerInfo) { // 导出Json文件,保存至(Resources/Conf) string inputFilePath = UploadList.GetInstance().ExportToJsonFile(); UtilsLog.Info("UploadUploadListFile", "ExportToJsonFile(Path:{0})", inputFilePath); // 打包信息URL string uploadUrl = ServersConf.GetUploadListBaseUrl(iServerInfo); if (File.Exists(inputFilePath) == true) { int lastIndex = inputFilePath.LastIndexOf("/"); string fileName = inputFilePath.Substring(lastIndex + 1); uploadUrl = string.Format("{0}/{1}", uploadUrl, fileName); // 上传Bundles列表信息文件 this._State = UpLoadFileToFtpServer( uploadUrl, inputFilePath, iServerInfo.AccountId, iServerInfo.Pwd); if (TRunState.OK != this._State) { UtilsLog.Error("UploadUploadListFile", "Upload Failed!!! \n {0} -> {1}", inputFilePath, uploadUrl); return(null); } else { this._uploadState = string.Format("[Upload] {0}", fileName); return(inputFilePath); } } else { UtilsLog.Error("UploadUploadListFile", "Upload Failed!!! \n Upload file is not exist!!!(Path:{0})", inputFilePath); return(null); } }
/// <summary> /// 备份文件. /// </summary> /// <param name="iBackupFilePath">备份文件路径.</param> /// <param name="iSubDir">备份文件子目录.</param> private bool BackupFile(string iBackupFilePath, string iSubDir = null) { // 上传文件列表 if ((string.IsNullOrEmpty(iBackupFilePath) == false) && (File.Exists(iBackupFilePath) == true)) { // 移到备份目录 string backupDir = this.GetBundleBackDir(UploadList.GetInstance().AppVersion, iSubDir); int lastIndex = iBackupFilePath.LastIndexOf("/"); string fileName = iBackupFilePath.Substring(lastIndex + 1); string backUpFileFullPath = string.Format("{0}/{1}", backupDir, fileName); UtilsLog.Info("BackupFile", "Successed. {0} -> {1}", iBackupFilePath, backUpFileFullPath); File.Copy(iBackupFilePath, backUpFileFullPath, true); if (File.Exists(backUpFileFullPath) == false) { UtilsLog.Error("BackupFile", "Failed!!! {0} -> {1}", iBackupFilePath, backUpFileFullPath); return(false); } this._uploadState = string.Format("[BackUp] -> {0}", fileName); } return(true); }
public static void OnPostprocessiOSBuild(BuildTarget target, string iBuiltProjectPath) { UtilsLog.Info("PostProcessor", "OnPostprocessiOSBuild()::Target:{0} ProPath:{1}", target.ToString(), iBuiltProjectPath); #if UNITY_EDITOR if (target != BuildTarget.iOS) { return; } const string funcBlock = "PostProcessor.OnPostprocessiOSBuild()"; BuildLogger.OpenBlock(funcBlock); const string TargetProjectName = "Unity-iPhone"; BuildSettings _buildSetting = BuildSettings.GetInstance(BuildSettings.AssetFileDir); if (null == _buildSetting) { return; } // 取得设定情报列表 XCSettingItem[] settings = _buildSetting.GetXCSettingInfo(TargetProjectName); if ((settings == null) || (settings.Length <= 0)) { BuildLogger.CloseBlock(); return; } string pbxprojPath = PBXProject.GetPBXProjectPath(iBuiltProjectPath); PBXProject project = new PBXProject(); project.ReadFromString(File.ReadAllText(pbxprojPath)); string targetGUID = project.TargetGuidByName(TargetProjectName); // BuildMode(debug/release/store) string debugConfigGUID = project.BuildConfigByName(targetGUID, "Debug"); string releaseConfigGUID = project.BuildConfigByName(targetGUID, "Release"); foreach (XCSettingItem item in settings) { switch (item.Type) { case TXCSettingInfoType.ReplaceSource: { foreach (string value in item.Value.LValue) { ReplaceSource(iBuiltProjectPath, value); BuildLogger.LogMessage("Replace Source {0} -> {1}", value, iBuiltProjectPath); } } break; case TXCSettingInfoType.FrameWorks: { foreach (string frameWork in item.Value.LValue) { #if UNITY_2017_1_OR_NEWER if (project.ContainsFramework(targetGUID, frameWork) == false) { #else if (project.HasFramework(frameWork) == false) { #endif project.AddFrameworkToProject(targetGUID, frameWork, false); BuildLogger.LogMessage("Add FrameWork -> {0}", frameWork); } } } break; case TXCSettingInfoType.Libraries: { foreach (string library in item.Value.LValue) { string fileGuid = project.AddFile("usr/lib/" + library, "Frameworks/" + library, PBXSourceTree.Sdk); project.AddFileToBuild(targetGUID, fileGuid); BuildLogger.LogMessage("Add Library -> {0}", library); } } break; case TXCSettingInfoType.IncludeFiles: { foreach (string file in item.Value.LValue) { string addFilePath = null; PreSetFileToProject(iBuiltProjectPath, file, ref addFilePath); if (string.IsNullOrEmpty(addFilePath) == false) { string fileGUID = project.AddFile(addFilePath, addFilePath, PBXSourceTree.Source); project.AddFileToBuild(targetGUID, fileGUID); BuildLogger.LogMessage("Add File -> {0}", file); } } } break; case TXCSettingInfoType.IncludeFolders: { foreach (string folder in item.Value.LValue) { string copyTo = null; string addDirReference = null; PreSetFolderToProject(iBuiltProjectPath, folder, ref copyTo, ref addDirReference); if ((string.IsNullOrEmpty(copyTo) == false) && (string.IsNullOrEmpty(addDirReference) == false)) { project.AddFolderReference(copyTo, addDirReference, PBXSourceTree.Source); BuildLogger.LogMessage("Add Folder -> {0}", folder); } } } break; case TXCSettingInfoType.Bool: { // Debug if (TXCBool.Yes == item.Debug.BValue) { project.SetBuildPropertyForConfig(debugConfigGUID, item.Key, "YES"); } else { project.SetBuildPropertyForConfig(debugConfigGUID, item.Key, "NO"); } BuildLogger.LogMessage("Add Bool(Debug) -> Key:{0} Value:{1}", item.Key, item.Debug.BValue.ToString()); // Release if (TXCBool.Yes == item.Release.BValue) { project.SetBuildPropertyForConfig(releaseConfigGUID, item.Key, "YES"); } else { project.SetBuildPropertyForConfig(releaseConfigGUID, item.Key, "NO"); } BuildLogger.LogMessage("Add Bool(Release) -> Key:{0} Value:{1}", item.Key, item.Release.BValue.ToString()); } break; case TXCSettingInfoType.String: { // Debug project.SetBuildPropertyForConfig(debugConfigGUID, item.Key, item.Debug.SValue); BuildLogger.LogMessage("Add String(Debug) -> Key:{0} Value:{1}", item.Key, item.Debug.SValue); // Release project.SetBuildPropertyForConfig(releaseConfigGUID, item.Key, item.Release.SValue); BuildLogger.LogMessage("Add String(Release) -> Key:{0} Value:{1}", item.Key, item.Release.SValue); } break; case TXCSettingInfoType.List: { // Debug foreach (string value in item.Debug.LValue) { project.AddBuildPropertyForConfig(debugConfigGUID, item.Key, value); BuildLogger.LogMessage("Add List(Debug) -> Key:{0} Item:{1}", item.Key, value); } // Release foreach (string value in item.Release.LValue) { project.AddBuildPropertyForConfig(releaseConfigGUID, item.Key, value); BuildLogger.LogMessage("Add List(Release) -> Key:{0} Item:{1}", item.Key, value); } } break; default: break; } } File.WriteAllText(pbxprojPath, project.WriteToString()); BuildLogger.CloseBlock(); #endif }
/// <summary> /// 下载文件(Http). /// </summary> /// <returns>运行状态.</returns> /// <param name="iParentUrl">下载父Url.</param> /// <param name="iFileName">下载文件名.</param> protected IEnumerator DownloadFileByWWW(string iParentUrl, string iFileName) { // 下载被打断 if (DownloadManager.isCanceled == true) { this.State = TRunState.Canceled; } WWW www = null; if (TRunState.OK == this.State) { string downloadUrl = string.Format("{0}/{1}", iParentUrl, iFileName); www = new WWW(downloadUrl); // 设置下载权限 www.threadPriority = UnityEngine.ThreadPriority.Normal; yield return(www); if (www.error != null) { this.State = TRunState.Error; ErrorDetail error = new ErrorDetail(); error.Type = TErrorType.WWWError; error.State = this.State; error.Detail = www.error; error.Retries = this.Retries; } } yield return(new WaitForEndOfFrame()); // 下载被打断 if (DownloadManager.isCanceled == true) { this.State = TRunState.Canceled; } if ((www != null) && (TRunState.OK == this.State)) { string filePath = null; try { // 字节 byte[] bytes = www.bytes; string fileName = Path.GetFileNameWithoutExtension(www.url.Replace("%20", " ")); string fileExtension = Path.GetExtension(www.url); string[] strUrl = fileExtension.Split('?'); filePath = string.Format("{0}/{1}{2}", this.DownloadDir, fileName, strUrl [0]); filePath = filePath.Replace("%20", " "); if (File.Exists(filePath) == true) { File.Delete(filePath); } // 生成并写入文件 File.WriteAllBytes(filePath, bytes); #if UNITY_IOS UnityEngine.iOS.Device.SetNoBackupFlag(filePath); #endif } catch (Exception exp) { this.State = TRunState.Exception; ErrorDetail error = new ErrorDetail(); error.Type = TErrorType.SysException; error.State = this.State; error.Detail = string.Format("System Exception Type:{0} Detail:{0}", exp.GetType().ToString(), exp.Message); error.Retries = this.Retries; this._errors.Add(error); } finally { if ((TRunState.OK == this.State) && (this._target != null)) { // 检测文件 if (false == this.CheckFileByCheckMode(this._target, filePath)) { // 删除文件 if (File.Exists(filePath) == true) { File.Delete(filePath); } this.State = TRunState.Error; ErrorDetail error = new ErrorDetail(); error.Type = TErrorType.FileCheckFailed; error.State = this.State; error.Detail = string.Format("File Check Failed!!!"); error.Retries = this.Retries; this._errors.Add(error); UtilsLog.Error("DownloadFileByWWW", "File Check -> NG (File:{0} Retries:{1})", iFileName, this.Retries); } else { UtilsLog.Info("DownloadFileByWWW", "File Check -> OK (File:{0} Retries:{1})", iFileName, this.Retries); } } } } yield return(new WaitForEndOfFrame()); }
/// <summary> /// 下载文件(Http). /// </summary> /// <returns>运行状态.</returns> /// <param name="iParentUrl">下载父Url.</param> /// <param name="iFileName">下载文件名.</param> protected TRunState DownloadFileByHttp(string iParentUrl, string iFileName) { HttpWebRequest request = null; HttpWebResponse response = null; FileStream fs = null; Stream stream = null; string filePath = null; TRunState stateTmp = TRunState.OK; try { // 取得下载文件名 string downloadUrl = string.Format("{0}/{1}", iParentUrl, iFileName); filePath = string.Format("{0}/{1}", this.DownloadDir, iFileName); // 使用流操作文件 fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write); // 获取文件现在的长度 long fileLength = fs.Length; // 获取下载文件的总长度 long totalLength = -1; stateTmp = this.GetFileDataSize(downloadUrl, ref totalLength); if (TRunState.OK == stateTmp) { // 下载被打断或者取消 if (DownloadManager.isCanceled == true) { stateTmp = TRunState.Canceled; } } // 断点续传 if (TRunState.OK == stateTmp) { // 如果没下载完 if (fileLength < totalLength) { // 断点续传核心,设置本地文件流的起始位置 fs.Seek(fileLength, SeekOrigin.Begin); Uri _url = new Uri(downloadUrl); request = WebRequest.Create(_url) as HttpWebRequest; if (null == request) { UtilsLog.Error("DownloaderBase", "DownloadFileByHttp:HttpWebRequest Create Failed!!!"); } request.Timeout = this.TimeOut; request.ReadWriteTimeout = this.TimeOut; request.ContentType = "application/octet-stream"; request.KeepAlive = false; // 断点续传核心,设置远程访问文件流的起始位置 request.AddRange((int)fileLength); response = request.GetResponse() as HttpWebResponse; if (response == null) { ErrorDetail error = new ErrorDetail(); error.Type = TErrorType.HttpError; error.State = this.State; error.Detail = string.Format("The HttpWebRequest is null or created failed(Url:{0})", downloadUrl); error.Retries = this.Retries; this._errors.Add(error); stateTmp = TRunState.Error; } else { if ((HttpStatusCode.OK != response.StatusCode) && (HttpStatusCode.PartialContent != response.StatusCode)) { ErrorDetail error = new ErrorDetail(); error.Type = TErrorType.HttpError; error.State = TRunState.Error; error.Detail = string.Format("HttpStatusCode:{0} Detail:{1}", response.StatusCode, response.StatusDescription); error.Retries = this.Retries; this._errors.Add(error); stateTmp = TRunState.Error; response.Close(); response = null; } } // 下载被打断或者取消 if (TRunState.OK == stateTmp) { // 下载被打断或者取消 if (DownloadManager.isCanceled == true) { stateTmp = TRunState.Canceled; } } if ((TRunState.OK == stateTmp) && (null != response)) { stream = response.GetResponseStream(); // 初始化下载缓存大小 byte[] buffer = new byte[_downloadBufferSize]; // 使用流读取内容到buffer中 // 注意方法返回值代表读取的实际长度 int length = stream.Read(buffer, 0, buffer.Length); while (length > 0) { // 下载被打断 if (DownloadManager.isCanceled == true) { stateTmp = TRunState.Canceled; break; } // 将缓存内容再写入本地文件中 fs.Write(buffer, 0, length); fs.Flush(); // 计算进度 fileLength += length; progress = (float)fileLength / (float)totalLength; progress = (progress >= 1.0f) ? 1.0f : progress; // 继续读取,直至读取完毕 length = stream.Read(buffer, 0, buffer.Length); } } else { progress = 1.0f; } } } } catch (Exception exp) { ErrorDetail error = new ErrorDetail(); error.Type = TErrorType.SysException; error.State = TRunState.Exception; error.Detail = string.Format("Type:{0} Msg:{1} StackTrace:{2}", exp.GetType().ToString(), exp.Message, exp.StackTrace); error.Retries = this.Retries; this._errors.Add(error); stateTmp = TRunState.Exception; if (null != request) { request.Abort(); } } finally { if (null != response) { try { response.Close(); response = null; } catch { request.Abort(); } } // 关闭&释放文件对象 if (fs != null) { fs.Close(); fs.Dispose(); fs = null; UtilsLog.Info("DownloaderBase", "DownloadFileByHttp:File Close -> File:{0}", iFileName); } if (stream != null) { stream.Close(); stream.Dispose(); stream = null; UtilsLog.Info("DownloaderBase", "DownloadFileByHttp:Stream Close -> File:{0}", iFileName); } if ((TRunState.OK == this.State) && (this._target != null)) { // 检测文件 if (false == this.CheckFileByCheckMode(this._target, filePath)) { // 删除文件 if (File.Exists(filePath) == true) { File.Delete(filePath); } stateTmp = TRunState.Error; ErrorDetail error = new ErrorDetail(); error.Type = TErrorType.FileCheckFailed; error.State = stateTmp; error.Detail = string.Format("File Check Failed!!!"); error.Retries = this.Retries; this._errors.Add(error); UtilsLog.Error("DownloaderBase", "DownloadFileByHttp:File Check -> NG (File:{0} Retries:{1})", iFileName, this.Retries); } else { UtilsLog.Info("DownloaderBase", "DownloadFileByHttp:File Check -> OK (File:{0} Retries:{1})", iFileName, this.Retries); } } } return(stateTmp); }
/// <summary> /// 往Ftp服务器上传文件. /// </summary> /// <param name="iUrl">URL.</param> /// <param name="iAccountId">账户.</param> /// <param name="iPwd">密码.</param> private TRunState UpLoadFileToFtpServer( string iUploadUrl, string iInputPath, string iAccountId, string iPwd) { FtpWebRequest ftpRequest = null; FtpWebResponse response = null; FileStream fileStream = null; Stream ftpStream = null; TRunState state = TRunState.OK; try { Uri targetURI = new Uri(iUploadUrl); ftpRequest = (FtpWebRequest)FtpWebRequest.Create(targetURI); ftpRequest.Credentials = new NetworkCredential(iAccountId, iPwd); ftpRequest.KeepAlive = false; ftpRequest.Method = WebRequestMethods.Ftp.UploadFile; ftpRequest.UseBinary = true; // 读取文件 fileStream = File.OpenRead(iInputPath); byte[] buffer = new byte[fileStream.Length]; fileStream.Read(buffer, 0, buffer.Length); // 写入请求 ftpStream = ftpRequest.GetRequestStream(); ftpStream.Write(buffer, 0, buffer.Length); // 发出请求 response = ftpRequest.GetResponse() as FtpWebResponse; UtilsLog.Info("UpLoadFileToFtpServer", "Successed. UploadUrl:{0} \n InputPath:{1}", iUploadUrl, iInputPath); } catch (WebException exp) { UtilsLog.Exception("UpLoadFileToFtpServer", "Failed!!! Retries:{0} \n UploadUrl:{1} \n InputPath:{2} \n WebException: \n {3}", this.Retries, iUploadUrl, iInputPath, exp.Message); state = TRunState.Exception; } catch (IOException exp) { UtilsLog.Exception("UpLoadFileToFtpServer", "Failed!!! Retries:{0} \n UploadUrl:{1} \n InputPath:{2} \n WebException: \n {3}", this.Retries, iUploadUrl, iInputPath, exp.Message); state = TRunState.Exception; } catch (Exception exp) { UtilsLog.Exception("UpLoadFileToFtpServer", "Failed!!! Retries:{0} \n UploadUrl:{1} \n InputPath:{2} \n WebException: \n {3}", this.Retries, iUploadUrl, iInputPath, exp.Message); state = TRunState.Exception; } finally { if (fileStream != null) { fileStream.Close(); } if (ftpStream != null) { ftpStream.Close(); } if (response != null) { response.Close(); } } return(state); }
/// <summary> /// 获取下载文件的总大小 /// </summary> /// <returns>下载文件的总大小.</returns> /// <param name="iDownloadUrl">下载地址.</param> /// <param name="iFileSize">文件大小.</param> protected TRunState GetFileDataSize(string iDownloadUrl, ref long iFileSize) { TRunState ret = TRunState.OK; if (null != this._target) { iFileSize = Convert.ToInt64(this._target.DataSize); } else { HttpWebResponse response = null; HttpWebRequest request = null; try { Uri _url = new Uri(iDownloadUrl); request = WebRequest.Create(_url) as HttpWebRequest; if (null == request) { UtilsLog.Error("DownloaderBase", "GetFileDataSize:HttpWebRequest Create Failed!!!"); } if (TRunState.OK == ret) { request.Timeout = this.TimeOut; request.ReadWriteTimeout = this.TimeOut; request.Method = "HEAD"; request.ContentType = "application/octet-stream"; request.KeepAlive = false; response = request.GetResponse() as HttpWebResponse; if (response.StatusCode != HttpStatusCode.OK) { ErrorDetail error = new ErrorDetail(); error.Type = TErrorType.HttpError; error.State = TRunState.GetFileSizeFromServerFailed; error.Detail = string.Format("GetFileDataSize Failed!!(File:{0} StatusCode:{1})", iDownloadUrl, response.StatusCode.ToString()); error.Retries = this.Retries; iFileSize = -1; response.Close(); response = null; return(TRunState.GetFileSizeFromServerFailed); } else { iFileSize = response.ContentLength; } } } catch (Exception exp) { UtilsLog.Exception("DownloaderBase", "GetFileDataSize Type:{0} Message:{1} StackTrace:{2}", exp.GetType().ToString(), exp.Message, exp.StackTrace); ErrorDetail error = new ErrorDetail(); error.Type = TErrorType.HttpException; error.State = TRunState.Exception; error.Detail = string.Format("GetFileDataSize Failed!!(File:{0} exp:{1})", iDownloadUrl, exp.Message); error.Retries = this.Retries; iFileSize = -1; ret = TRunState.Exception; if (null != request) { request.Abort(); } } finally { if (null != response) { try { response.Close(); response = null; } catch { request.Abort(); } } } if (0 < iFileSize) { UtilsLog.Info("DownloaderBase", "GetFileDataSize Size:{0} ({1})", iFileSize.ToString(), iDownloadUrl); } } return(ret); }