// 修改setting.tjs static void ModifySetting(string dataPath, string title, int sw, int sh, int dh, int dw) { // 更新setting string settingFile = Path.Combine(dataPath, WizardConfig.UI_SETTING); // 临时创建一个属性对象用于读取setting ProjectProperty info = new ProjectProperty(); info.LoadSetting(settingFile); TjsDict setting = info.setting; if (setting != null) { setting.SetString("title", title); setting.SetNumber("width", dw); setting.SetNumber("height", dh); // 修正缩略图宽度 int tw = info.thumbnailwidth; if (tw > 0) { tw = tw * dw / sw; setting.SetValue("savedata/thumbnailwidth", new TjsString(tw.ToString())); } setting.Save(settingFile, Encoding.Unicode); } }
// 修改config.tjs static void ModifyConfig(string dataPath, string title, int sw, int sh, int dh, int dw) { // 更新config string configFile = Path.Combine(dataPath, WizardConfig.UI_CONFIG); if (File.Exists(configFile)) { Regex regTitle = new Regex(@"\s*;\s*System.title\s*="); Regex regW = new Regex(@"\s*;\s*scWidth\s*="); Regex regH = new Regex(@"\s*;\s*scHeight\s*="); Regex regThumb = new Regex(@"\s*;\s*thumbnailWidth\s*="); StringBuilder buf = new StringBuilder(); using (StreamReader r = new StreamReader(configFile)) { while (!r.EndOfStream) { string line = r.ReadLine(); if (regTitle.IsMatch(line)) { buf.AppendLine(string.Format(";System.title = \"{0}\";", title)); } else if (regW.IsMatch(line)) { buf.AppendLine(string.Format(";scWidth = {0};", dw)); } else if (regH.IsMatch(line)) { buf.AppendLine(string.Format(";scHeight = {0};", dh)); } else if (regThumb.IsMatch(line)) { // 临时创建一个属性对象用于读取setting string settingFile = Path.Combine(dataPath, WizardConfig.UI_SETTING); ProjectProperty info = new ProjectProperty(); info.LoadSetting(settingFile); // 修正缩略图 int tw = info.thumbnailwidth; if (tw > 0) { buf.AppendLine(string.Format(";thumbnailWidth = {0};", tw)); } } else { buf.AppendLine(line); } } } using (StreamWriter w = new StreamWriter(configFile, false, Encoding.Unicode)) { w.Write(buf.ToString()); } } }
// 从Data目录下读取属性 private ProjectProperty ReadInfo(string dataFolder, string setting) { // 直接返回上一次读取的值 if (this._info != null) { return(this._info); } ProjectProperty info = new ProjectProperty(); this._info = info; // 读取readme文件作为显示内容 try { string readmefile = Path.Combine(dataFolder, UI_README); if (File.Exists(readmefile)) { using (StreamReader r = new StreamReader(readmefile)) { info.readme = r.ReadToEnd(); } } else { string configfile = Path.Combine(dataFolder, UI_CONFIG); if (File.Exists(configfile)) { using (StreamReader r = new StreamReader(configfile)) { info.readme = r.ReadToEnd(); } } } } catch (System.Exception e) { // 出错的不保留 this._info = null; info.readme = e.Message; } // 读取设置文件 try { info.LoadSetting(setting); } catch (System.Exception e) { // 出错的不保留 this._info = null; info.readme = e.Message; } return(info); }
// 读取基础模板的配置 public ProjectProperty ReadBaseTemplateInfo() { // 如果选的是默认的主题,则返回主题属性 if (this.IsDefaultTheme) { return(this.ThemeInfo); } // 这里就不读readme了,也不做保存,每次调用都从文件读一次 string file = Path.Combine(this.BaseTemplateFolder + DATA_FOLDER, UI_SETTING); ProjectProperty info = new ProjectProperty(); try { info.LoadSetting(file); } catch (System.Exception e) { info.readme = e.Message; } return(info); }