/// <summary> /// 保存存档 /// </summary> /// <param name="datas"></param> /// <param name="stream"></param> public void Save(T datas, string path) { using (Stream stream = new FileStream(path, FileMode.Create)) { if (datas == null) { throw new System.ArgumentNullException("datas"); } GameDatas = datas; using (MemoryStream ms = BaseFileUtils.SerializeToMemoryStream(GameDatas)) { byte[] uncompressed = ms.ToArray(); Content = BaseFileUtils.GZCompressToBytes(uncompressed); Header.PlayTime = GameDatas.PlayTime; Header.Version = _curVersion; Header.IsHide = _isHide; Header.ContentLength = Content.Length; Header.SaveTimeTicks = DateTime.Now.Ticks; Header.ContentHash = BaseFileUtils.Hash(Content); Header.IsCompressed = true; string headerStr = JsonUtility.ToJson(Header); using (BinaryWriter writer = new BinaryWriter(stream)) { writer.Write(headerStr); writer.Write(Content); writer.Close(); } } stream.Close(); } }
void Present_Explorer() { EditorGUILayout.BeginVertical(VerticalStyle); if (BuildLocalConfig.Ins.Fold_Present_Explorer = EditorGUILayout.Foldout(BuildLocalConfig.Ins.Fold_Present_Explorer, "链接", true)) { EditorGUILayout.LabelField(Application.persistentDataPath); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Persistent")) { BaseFileUtils.OpenExplorer(Application.persistentDataPath); } else if (GUILayout.Button("删除 Persistent")) { BaseFileUtils.DeletePath(Application.persistentDataPath); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Project File")) { BaseFileUtils.OpenExplorer(BaseConstMgr.Path_Project); } else if (GUILayout.Button("Bin")) { BaseFileUtils.OpenExplorer(BaseConstMgr.Path_Build); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); OnDrawPresentExplorer(); EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); }
/// <summary> /// 确保标准项目文件夹存在 /// </summary> public static void EnsureProjectFiles() { BaseFileUtils.EnsureDirectory(BaseConstMgr.Path_Arts); BaseFileUtils.EnsureDirectory(BaseConstMgr.Path_Bundles); BaseFileUtils.EnsureDirectory(BaseConstMgr.Path_NoBundles); BaseFileUtils.EnsureDirectory(BaseConstMgr.Path_NoBundlesScene); //BaseFileUtils.EnsureDirectory(BaseConstansMgr.Path_TargetNativeDLC); BaseFileUtils.EnsureDirectory(BaseConstMgr.Path_Resources); //BaseFileUtils.EnsureDirectory(BaseConstansMgr.Path_ResourcesDLC); BaseFileUtils.EnsureDirectory(BaseConstMgr.Path_ResourcesConfig); BaseFileUtils.EnsureDirectory(BaseConstMgr.Path_ScriptTemplate); BaseFileUtils.EnsureDirectory(BaseConstMgr.Path_Funcs); BaseFileUtils.EnsureDirectory(Path.Combine(BaseConstMgr.Path_Funcs, "Editor")); BaseFileUtils.EnsureDirectory(Path.Combine(BaseConstMgr.Path_Funcs, "GlobalMgr")); BaseFileUtils.EnsureDirectory(Path.Combine(BaseConstMgr.Path_Funcs, "GlobalMono")); BaseFileUtils.EnsureDirectory(Path.Combine(BaseConstMgr.Path_Funcs, "TableDatas")); BaseFileUtils.EnsureDirectory(Path.Combine(BaseConstMgr.Path_Funcs, "UI")); BaseFileUtils.EnsureDirectory(Path.Combine(BaseConstMgr.Path_Funcs, "UnitMgr")); BaseFileUtils.EnsureDirectory(Path.Combine(BaseConstMgr.Path_Funcs, "UnitMono")); BaseFileUtils.EnsureDirectory(Path.Combine(BaseConstMgr.Path_Funcs, "Utils")); BaseFileUtils.EnsureDirectory(BaseConstMgr.Path_Tests); BaseFileUtils.EnsureDirectory(BaseConstMgr.Path_Gizmos); BaseFileUtils.EnsureDirectory(BaseConstMgr.Path_Editor); BaseFileUtils.EnsureDirectory(BaseConstMgr.Path_StreamingAssets); BaseFileUtils.EnsureDirectory(BaseConstMgr.Path_NativeDLC); Utile.XenoTemplateTool.RefreshTemplates(BaseConstMgr.Path_Editor, false); }
public static void SaveJson(string path, object obj, bool prettyPrint = true) { string dir = Path.GetDirectoryName(path); BaseFileUtils.EnsureDirectory(dir); SaveFile(path, JsonUtility.ToJson(obj, prettyPrint)); }
/// <summary> /// 保存 /// </summary> public void Save() { //var temp =; using (Stream stream = new FileStream(BaseConstMgr.Path_Settings, FileMode.Create) /*Storage.OpenWrite (SettingsPath)*/) { BaseFileUtils.SaveJson(stream, Settings); stream.Close(); } }
public virtual IEnumerator Load() { string[] directories = Directory.GetDirectories(DLCAssetMgr.GetDLCRootPath()); foreach (var directoryPath in directories) { DLCAssetMgr.LoadDLC(BaseFileUtils.GetFinalDirectoryName(directoryPath)); yield return(new WaitForEndOfFrame()); } }
public void Load() { string data = BaseFileUtils.LoadFile(BaseConstMgr.Path_Shortcuts); if (data == null) { return; } InputAsset.LoadFromJson(data); }
public override void PostBuilder() { //if (BuildConfig.CurTarget.Architecture == Architecture.x64) //{ // BaseFileUtils.CopyFileToDir("steam_api64.dll", BuildConfig.DirPath); //} //else if (BuildConfig.CurTarget.Architecture == Architecture.x86) //{ // BaseFileUtils.CopyFileToDir("steam_api.dll", BuildConfig.DirPath); //} //else if (BuildConfig.CurTarget.Architecture == Architecture.Universal) //{ //} BaseFileUtils.CopyFileToDir("steam_api64.dll", BuildConfig.DirPath); BaseFileUtils.CopyFileToDir("steam_api.dll", BuildConfig.DirPath); BaseFileUtils.CopyFileToDir("steam_appid.txt", BuildConfig.DirPath); }
public override void OnBeAdded(IMono mono) { base.OnBeAdded(mono); if (IsEnableDevSetting) { DevSettings = BaseFileUtils.LoadJsonOrDefault(BaseConstMgr.Path_DevSettings, CreateDefaultDevSettings()); } else { DevSettings = CreateDefaultDevSettings(); } string fullpath = BaseConstMgr.Path_Settings; TDBSetting settings = default(TDBSetting); if (File.Exists(fullpath)) { using (Stream stream = File.OpenRead(fullpath)) { if (stream != null) { try { settings = BaseFileUtils.LoadJson <TDBSetting>(stream); } catch (Exception e) { settings = default(TDBSetting); CLog.Error("载入settings出错{0}", e); } } } } if (settings == null) { IsFirstCreateSettings = true; settings = new TDBSetting(); Save(); } SetSettings(settings); }
/// <summary> /// 载入存档 /// </summary> /// <param name="stream"></param> /// <param name="name"></param> /// <param name="curVersion"></param> /// <param name="isReadContent"></param> /// <param name="fileTime"></param> /// <returns></returns> public void Load(string path, string name, int curVersion, bool isReadContent, DateTime fileTime) { ArchiveFile <T> archive = this; archive.Name = name; archive._curVersion = curVersion; archive.FileTime = fileTime; using (Stream stream = File.OpenRead(path)) { try { BinaryReader reader = new BinaryReader(stream); string headerStr = null; //使用try防止无效的存档 headerStr = reader.ReadString(); if (string.IsNullOrEmpty(headerStr)) { archive.IsBroken = true; } else { archive.Header = JsonUtility.FromJson <ArchiveHeader>(headerStr); int contentSize = archive.Header.ContentLength; if (contentSize <= 0) { archive.IsBroken = true; } else { archive.Content = reader.ReadBytes(contentSize); if (!string.IsNullOrEmpty(archive.Header.ContentHash)) { // 内容损坏 if (archive.Header.ContentHash != BaseFileUtils.Hash(archive.Content)) { archive.IsBroken = true; return; } } if (isReadContent && archive.IsCompatible && contentSize > 0) { byte[] toBeDeserialized = null; if (archive.Header.IsCompressed) { toBeDeserialized = BaseFileUtils.GZDecompressToBytes(archive.Content); } else { toBeDeserialized = archive.Content; } using (MemoryStream ms = new MemoryStream(toBeDeserialized)) { archive.GameDatas = BaseFileUtils.DeSerializeStream <T>(ms); } } } } reader.Close(); } catch (Exception e) { archive.IsBroken = true; CLog.Error("读取存档{0}时出现异常:{1}, 因此认为是损坏的存档。", archive.Name, e.Message); } } return; }
void Present_Main() { EditorGUILayout.BeginVertical(VerticalStyle); if (BuildLocalConfig.Ins.Fold_Present_Main = EditorGUILayout.Foldout(BuildLocalConfig.Ins.Fold_Present_Main, "构建", true)) { BuildConfig.Platform = (Platform)EditorGUILayout.Popup("目标", (int)BuildConfig.Platform, Enum.GetNames(typeof(Platform))); BuildConfig.Distribution = (Distribution)EditorGUILayout.EnumPopup("发布平台", BuildConfig.Distribution); EditorGUILayout.LabelField(string.Format("版本号预览:{0}", BuildConfig)); EditorGUILayout.LabelField(string.Format("完整版本号预览:{0}", BuildConfig.FullVersionName)); BuildConfig.Name = EditorGUILayout.TextField("名称", BuildConfig.Name); BuildConfig.SubTitle = EditorGUILayout.TextField("副标题", BuildConfig.SubTitle); BuildConfig.Major = EditorGUILayout.IntField("主版本", BuildConfig.Major); BuildConfig.Minor = EditorGUILayout.IntField("副版本", BuildConfig.Minor); BuildConfig.Data = EditorGUILayout.IntField("数据库版本", BuildConfig.Data); BuildConfig.Prefs = EditorGUILayout.IntField("Prefs", BuildConfig.Prefs); EditorGUILayout.BeginHorizontal(); BuildConfig.Tag = (VersionTag)EditorGUILayout.EnumPopup("后缀", BuildConfig.Tag); BuildConfig.Suffix = EditorGUILayout.IntField(BuildConfig.Suffix); EditorGUILayout.EndHorizontal(); BuildConfig.BuildType = (BuildType)EditorGUILayout.EnumPopup("打包版本", BuildConfig.BuildType); BuildConfig.IgnoreChecker = EditorGUILayout.Toggle("忽略检查", BuildConfig.IgnoreChecker); bool preDevelopmentBuild = BuildConfig.IsUnityDevelopmentBuild; BuildConfig.IsUnityDevelopmentBuild = EditorGUILayout.Toggle("UnityDevBuild", BuildConfig.IsUnityDevelopmentBuild); if (preDevelopmentBuild != BuildConfig.IsUnityDevelopmentBuild) { EditorUserBuildSettings.development = BuildConfig.IsUnityDevelopmentBuild; } if (PlayerSettings.bundleVersion != BuildConfig.ToString()) { PlayerSettings.bundleVersion = BuildConfig.ToString(); } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("构建Manifest")) { Builder.BuildManifest(Native); } if (GUILayout.Button("构建AB")) { Builder.BuildBundle(Native); } if (GUILayout.Button("构建EXE")) { if (CheckEorr()) { return; } if (!CheckDevBuildWarring()) { return; } if (!CheckAuthority()) { return; } Builder.BuildEXE(); } if (GUILayout.Button("构建AB&EXE")) { if (CheckEorr()) { return; } if (!CheckDevBuildWarring()) { return; } if (!CheckAuthority()) { return; } Builder.BuildBundleAndEXE(Native); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("运行游戏")) { BaseFileUtils.OpenFile(BuildConfig.ExePath); CLog.Info("Run:{0}", BuildConfig.ExePath); } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndVertical(); }
protected virtual void OnDrawPresentExplorer() { DrawButton("LogTag", () => SafeOpenJsonFile(BaseConstMgr.Path_LoggerTag, CLog.CreateDefaultData())); DrawButton("Language", () => BaseFileUtils.OpenExplorer(BaseConstMgr.Path_NativeDLCLLanguage, true)); DrawButton("Lua", () => BaseFileUtils.OpenExplorer(BaseConstMgr.Path_NativeDLCLuaScript, true)); }
public void Init(string path) { BasePath = path; BaseFileUtils.EnsureDirectory(path); }
protected static void SafeOpenJsonFile <T>(string path, T data) where T : class { BaseFileUtils.UpdateFile(path, data); BaseFileUtils.OpenFile(path); }
void Present_ExpressSetup() { EditorGUILayout.BeginVertical(VerticalStyle); if (BuildLocalConfig.Ins.Fold_Present_ExpressSetup = EditorGUILayout.Foldout(BuildLocalConfig.Ins.Fold_Present_ExpressSetup, "平台", true)) { string path = BuildConfig.CurDistributionSetupPath; Rect dragAreaRect = new Rect(); //获得一个长300的框 dragAreaRect = EditorGUILayout.GetControlRect(/*GUILayout.Width(600)*/ true, 18); //将上面的框作为文本输入框 BuildConfig.CurDistributionSetupPath = EditorGUI.TextField(dragAreaRect, "路径", BuildConfig.CurDistributionSetupPath); //如果鼠标正在拖拽中或拖拽结束时,并且鼠标所在位置在文本输入框内 if ((Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragExited) && dragAreaRect.Contains(Event.current.mousePosition)) { //改变鼠标的外表 DragAndDrop.visualMode = DragAndDropVisualMode.Generic; if (DragAndDrop.paths != null && DragAndDrop.paths.Length > 0) { BuildConfig.CurDistributionSetupPath = DragAndDrop.paths[0]; } } EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("安装到本地")) { if (BuildConfig.CurDistributionSetupPath != null) { BaseFileUtils.DeletePath(BuildConfig.CurDistributionSetupPath); BaseFileUtils.EnsureDirectory(BuildConfig.CurDistributionSetupPath); BaseFileUtils.CopyDir(BuildConfig.DirPath, BuildConfig.CurDistributionSetupPath); } } if (GUILayout.Button("打开安装目录")) { if (BuildConfig.CurDistributionSetupPath != null) { BaseFileUtils.OpenExplorer(BuildConfig.CurDistributionSetupPath); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginVertical(); BuildConfig.Username = EditorGUILayout.TextField("用户名", BuildConfig.Username); BuildConfig.Password = EditorGUILayout.PasswordField("密码", BuildConfig.Password); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("上传")) { if (string.IsNullOrEmpty(BuildConfig.Username) || string.IsNullOrEmpty(BuildConfig.Password)) { EditorUtility.DisplayDialog("错误", "请先输入用户名密码", "好的"); } else { if (EditorUtility.DisplayDialog("重要操作", "确定要上传吗.", "上传", "取消")) { BuildConfig.GetBuildData(BuildConfig.Distribution).Upload(); } } } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); } EditorGUILayout.EndVertical(); }
/// <summary> /// 得到所有文件 /// </summary> /// <param name="path"></param> /// <returns></returns> public string[] GetFiles() { return(BaseFileUtils.GetFiles(BasePath, "*" + BaseConstMgr.Extention_Save, SearchOption.AllDirectories)); }
public void Save() { BaseFileUtils.SaveJson(BaseConstMgr.Path_Shortcuts, InputAsset.ToJson()); }