private void Form1_Load(object sender, EventArgs e) { using (dpz3.File.ConfFile cfg = new dpz3.File.ConfFile()) { // 读取命令行参数 StringBuilder sbArgs = new StringBuilder(); for (int i = 0; i < args.Length; i++) { if (sbArgs.Length > 0) { sbArgs.Append(" "); } sbArgs.Append("\""); sbArgs.Append(args[i]); sbArgs.Append("\""); } // 设置执行文件和命令行参数 var cfgDefault = cfg["Default"]; cfgDefault["FilePath"] = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; cfgDefault["WorkPath"] = System.IO.Directory.GetCurrentDirectory(); cfgDefault["Args"] = sbArgs.ToString(); // 设置环境变量 var cfgEnvir = cfg["Envir"]; var envirs = Environment.GetEnvironmentVariables(); foreach (var key in envirs.Keys) { cfgEnvir[key.ToString()] = envirs[key].ToString(); } this.textBox1.Text = cfg.ToString(); } }
/// <summary> /// 对象实例化 /// </summary> /// <param name="dir"></param> public Manager(string dir) { _dir = dir.Replace("\\", "/"); if (!_dir.EndsWith("/")) { _dir += "/"; } _conf_path = $"{_dir}list.config"; _conf = new File.ConfFile(_conf_path); _group = _conf["default"]; idxer = _group["indexer"].ToLong(); }
// 打开一个目录进行编辑 private void OpenFolder() { // 判断当前是否有项目已经打开 if (!workPath.IsNoneOrNull()) { if (MessageBox.Show("是否退出当前的工作目录,并打开一个新的?", "工作目录切换提醒", MessageBoxButtons.YesNo) == DialogResult.No) { return; } } // 加载历史记录 string lastPath = null; using (dpz3.File.ConfFile conf = new dpz3.File.ConfFile(localPath + Path_Config)) { var group = conf["History"]; lastPath = group["WorkPath"]; if (lastPath.IsNoneOrNull()) { lastPath = localPath; } using (FolderBrowserDialog f = new FolderBrowserDialog()) { f.SelectedPath = lastPath; if (f.ShowDialog() == DialogResult.OK) { // 存储历史记录 group["WorkPath"] = f.SelectedPath; conf.Save(); // 设置工作目录 this.SetWorkPath(f.SelectedPath); //workPath = f.SelectedPath; // 设置资源管理器 //frmSetting.LoadSetting(workPath); } else { return; } } } }
/// <summary> /// 应用配置 /// </summary> /// <param name="path"></param> /// <param name="options"></param> public static void DeployConfig(string path, Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerOptions options) { // 当文件不存在时,执行初始化创建 if (!System.IO.File.Exists(path)) { using (dpz3.File.ConfFile file = new dpz3.File.ConfFile(path)) { // 建立HTTP配置 var httpGroup = file["HTTP"]; httpGroup["Enable"] = "no"; httpGroup["Port"] = "80"; // 建立HTTPS配置 var httpsGroup = file["HTTPS"]; httpsGroup["Enable"] = "no"; httpsGroup["Port"] = "443"; httpsGroup["Pfx.Path"] = "/ssl/ssl.pfx"; httpsGroup["Pfx.Password"] = "******"; //文件保存 file.Save(); } } // 读取配置 using (dpz3.File.ConfFile file = new dpz3.File.ConfFile(path)) { // 读取HTTP配置 var httpGroup = file["HTTP"]; if (httpGroup["Enable"] == "yes") { // 填入配置中的监听端口 options.Listen(IPAddress.Any, httpGroup["Port"].ToInteger()); } // 读取HTTPS配置 var httpsGroup = file["HTTPS"]; if (httpsGroup["Enable"] == "yes") { // 填入配置中的监听端口 options.Listen(IPAddress.Any, httpsGroup["Port"].ToInteger(), listenOptions => { // 填入配置中的pfx文件路径和指定的密码 listenOptions.UseHttps(httpsGroup["Pfx.Path"], httpsGroup["Pfx.Password"]); }); } } }
private void Form1_Load(object sender, EventArgs e) { // 定位配置文件 string path = System.Environment.CurrentDirectory; if (!path.EndsWith("\\")) { path += "\\"; } string configFilePath = path + "config.ini"; // 判断配置文件是否存在 if (!System.IO.File.Exists(configFilePath)) { MessageBox.Show("未发现配置文件"); Application.Exit(); } using (dpz3.File.ConfFile cfg = new dpz3.File.ConfFile(configFilePath)) { this.textBox1.Text = cfg.ToString(); } }
/// <summary> /// 设置工作目录 /// </summary> /// <param name="path"></param> public void SetWorkPath(string path) { workPath = path; if (workPath.EndsWith("\\")) { workPath = workPath.Substring(0, workPath.Length - 1); } this.Text = $"{Application.ProductName} Ver:{Application.ProductVersion} - [{workPath}]"; // 创建工作文件夹 if (!System.IO.Directory.Exists(workPath + Path_WorkFolder)) { System.IO.Directory.CreateDirectory(workPath + Path_WorkFolder); } workCfg = new dpz3.File.ConfFile(workPath + Path_WorkFolder + Path_WorkConfig); var workGroup = workCfg["XOrm"]; if (workGroup["Url"].IsNoneOrNull()) { workGroup["Url"] = "https://dev.lywos.com/Orm/Xml2"; workGroup["SettingPath"] = "/Setting.xml"; workGroup["VersionPath"] = "/Version.xml"; workCfg.Save(); } var workBuildGroup = workCfg["Build"]; if (workBuildGroup["PagePath"].IsNoneOrNull()) { workBuildGroup["PagePath"] = "\\wwwroot\\pages"; workBuildGroup["ClassPath"] = "\\Orm"; workBuildGroup["NameSpace"] = "Entity.Orm"; workCfg.Save(); } this.LoadTree(); }
private void button1_Click(object sender, EventArgs e) { // 定位配置文件 string path = System.Environment.CurrentDirectory; if (!path.EndsWith("\\")) { path += "\\"; } string configFilePath = path + "config.ini"; // 判断配置文件是否存在 if (!System.IO.File.Exists(configFilePath)) { MessageBox.Show("未发现配置文件"); Application.Exit(); } // 在线程中处理启动 var task = new Task(() => { using (dpz3.File.ConfFile cfg = new dpz3.File.ConfFile(configFilePath)) { // 实例化一个进程启动器 var proStartInfo = new System.Diagnostics.ProcessStartInfo(); var pro = new System.Diagnostics.Process(); // 设置执行文件和命令行参数 var cfgDefault = cfg["Default"]; proStartInfo.UseShellExecute = false; proStartInfo.WorkingDirectory = cfgDefault["WorkPath"]; string filePath = cfgDefault["FilePath"]; // 判断是否进行游戏程序复制 if (this.checkBox1.Checked) { string newPath = filePath + "." + Guid.NewGuid().ToString() + ".exe"; System.IO.File.Copy(filePath, newPath); filePath = newPath; } proStartInfo.FileName = filePath; proStartInfo.Arguments = cfgDefault["Args"]; // 设置环境变量 var cfgEnvir = cfg["Envir"]; foreach (var key in cfgEnvir.Keys) { proStartInfo.Environment.Add(key, cfgEnvir[key]); } // 启动游戏客户端 pro.StartInfo = proStartInfo; pro.Start(); pro.WaitForExit(); // 如存在副本,则清理副本 if (this.checkBox1.Checked) { System.IO.File.Delete(filePath); } } }); task.Start(); }
static void Test01() { string a = "abc"; string b = "123"; Console.WriteLine($"int a={a.ToInteger()}"); Console.WriteLine($"int b={b.ToInteger()}"); using (dpz3.Json.JsonObject json = new dpz3.Json.JsonObject()) { json["obj"].Str["a"] = "abc"; json["obj"].Num["b"] = 123; Console.WriteLine(json.ToJsonString()); } using (dpz3.File.ConfFile file = new dpz3.File.ConfFile(@"X:\Projects\modular\core\ModularCore\bin\Debug\netcoreapp3.1\conf\kestrel.cfg")) { var group = file["Server"]; Console.WriteLine($"Server.Enable={group["Enable"]}"); } People p1 = new People(); p1.Name.Value = "张三"; p1.Age.Value = 18; p1.Sex.Value = "Man"; byte[] arr = p1.ToBytes(); for (int i = 0; i < arr.Length; i++) { Console.Write($"{arr[i]} "); } Console.WriteLine(); People p2 = new People(); p2.SetValue(arr); p2.Name.Value = "李四"; Console.WriteLine(p2.Sex); var arr2 = p2.ToBytes(); for (int i = 0; i < arr2.Length; i++) { Console.Write($"{arr2[i]} "); } Console.WriteLine(); for (int i = 0; i < arr.Length; i++) { Console.Write($"{arr[i]} "); } //byte[] arr2 = new ArraySegment<byte>(arr, 0, 5).Array; Console.WriteLine(); // 测试对象序列化 dpz3.Serializable.Double db = 12; Console.WriteLine($"Double {db.ToString()} {db.Size} {db.ToBytes().Length}"); dpz3.Serializable.Single sgl = 12; Console.WriteLine($"Single {sgl.ToString()} {sgl.Size} {sgl.ToBytes().Length}"); dpz3.Serializable.Int8 i8 = 12; Console.WriteLine($"Int8 {i8.ToString()} {i8.Size} {i8.ToBytes().Length}"); dpz3.Serializable.Int16 i16 = 12; Console.WriteLine($"Int16 {i16.ToString()} {i16.Size} {i16.ToBytes().Length}"); dpz3.Serializable.Int32 i32 = 12; Console.WriteLine($"Int32 {i32.ToString()} {i32.Size} {i32.ToBytes().Length}"); dpz3.Debug.WriteLine("123456"); //string a = "123456"; int n = a.ToInteger(); string md5 = a.GetMD5(); Console.WriteLine($"n={n}"); Console.WriteLine($"md5={md5}"); string str = dpz3.File.UTF8File.ReadAllText(@"X:\Projects\modular\core\ModularCore\bin\Debug\netcoreapp3.1\packages\simple-home\1.0.1912.4\modular.json"); Console.WriteLine(str); var obj = dpz3.Json.Parser.ParseJson("{}"); Console.WriteLine(obj.ToJsonString()); //string md = dpz3.File.UTF8File.ReadAllText(@"X:\Temp\temp.md"); //using (var doc = dpz3.Markdown.Parser.GetDocument(md)) { // Console.WriteLine("String:"); // Console.WriteLine(doc.ToString()); // Console.WriteLine("Markdown:"); // Console.WriteLine(doc.ToMarkdown()); // Console.WriteLine("HTML:"); // Console.WriteLine(doc.ToHtml()); // // 输出到HTML文件 // StringBuilder sb = new StringBuilder(); // sb.Append("<html>"); // sb.Append("<head>"); // sb.Append("<title>Markdown测试</title>"); // sb.Append("</head>"); // sb.Append("<body>"); // sb.Append(doc.ToHtml()); // sb.Append("</body>"); // sb.Append("</html>"); // dpz3.File.UTF8File.WriteAllText(@"X:\Temp\temp.html", sb.ToString()); //} }