You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
190 lines
7.6 KiB
190 lines
7.6 KiB
using Container.Common;
|
|
using Container.Services;
|
|
using Microsoft.Win32;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Shapes;
|
|
|
|
namespace Container.ChildWindows
|
|
{
|
|
/// <summary>
|
|
/// GetUrl.xaml 的交互逻辑
|
|
/// </summary>
|
|
public partial class GetUrl : Window
|
|
{
|
|
App app = ((App)System.Windows.Application.Current);
|
|
Class_Config config = new Class_Config();
|
|
Class_Log log = new Class_Log();
|
|
public GetUrl()
|
|
{
|
|
InitializeComponent();
|
|
this.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
|
|
}
|
|
|
|
private void Button_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
lab_msg.Visibility = System.Windows.Visibility.Hidden;
|
|
if (string.IsNullOrEmpty(this.Text_RegKey.Text))
|
|
{
|
|
lab_msg.Content = "请填写商场激活码。";
|
|
lab_msg.Visibility = System.Windows.Visibility.Visible;
|
|
return;
|
|
}
|
|
//if (string.IsNullOrEmpty(this.Text_HttpUrl.Text))
|
|
//{
|
|
// lab_msg.Content = "请填写Http地址。";
|
|
// lab_msg.Visibility = System.Windows.Visibility.Visible;
|
|
// return;
|
|
//}
|
|
//if (string.IsNullOrEmpty(this.Text_WsUrl.Text))
|
|
//{
|
|
// lab_msg.Content = "请填写Websocket地址。";
|
|
// lab_msg.Visibility = System.Windows.Visibility.Visible;
|
|
// return;
|
|
//}
|
|
if (string.IsNullOrEmpty(this.Text_ExePath.Text))
|
|
{
|
|
//if (MessageBox.Show("确认不填写应用程序路径?", "提示", MessageBoxButton.YesNo) == MessageBoxResult.No)
|
|
//{
|
|
// lab_msg.Content = "请填写应用程序路径。";
|
|
// lab_msg.Visibility = System.Windows.Visibility.Visible;
|
|
// return;
|
|
//}
|
|
}
|
|
|
|
else if (!File.Exists(this.Text_ExePath.Text.ToString()) && !this.Text_ExePath.Text.ToString().Contains("http"))
|
|
{
|
|
lab_msg.Content = "未找到应用程序,请确认路径是否正确。";
|
|
lab_msg.Visibility = System.Windows.Visibility.Visible;
|
|
return;
|
|
}
|
|
app.mallRegKey = this.Text_RegKey.Text.ToString();
|
|
//app.configurl = this.Text_HttpUrl.Text.ToString();
|
|
//app.HttpUrl = this.Text_HttpUrl.Text.ToString();
|
|
//app.configwebsocket = this.Text_WsUrl.Text.ToString();
|
|
app.configstartexe = this.Text_ExePath.Text.ToString();
|
|
HttpMessage httpclient = new HttpMessage();
|
|
string Errorlog = string.Empty;
|
|
string mallCode = string.Empty;
|
|
var flag = httpclient.CheckMallRegKey(app.mallRegKey, ref mallCode, ref Errorlog);
|
|
if (!flag)
|
|
{
|
|
lab_msg.Content = Errorlog;
|
|
lab_msg.Visibility = System.Windows.Visibility.Visible;
|
|
}
|
|
else
|
|
{
|
|
lab_msg.Visibility = System.Windows.Visibility.Hidden;
|
|
app.mallCode = mallCode;
|
|
config.WriteToInitialConfig();
|
|
ServiceInfo info = new ServiceInfo();
|
|
this.ButtonOK.Visibility = System.Windows.Visibility.Hidden;
|
|
info.ShowDialog();
|
|
if (info.DialogResult == true)
|
|
{
|
|
this.DialogResult = info.DialogResult;
|
|
}
|
|
else
|
|
{
|
|
this.ButtonOK.Visibility = System.Windows.Visibility.Visible;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
log.WriteLogFile(ex.ToString(), "GetUrlErrorLog");
|
|
}
|
|
}
|
|
|
|
private void Services_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
//this.Text_HttpUrl.Text = app.HttpUrl;
|
|
this.Text_RegKey.Text = app.mallRegKey;
|
|
//this.Text_WsUrl.Text = app.configwebsocket;
|
|
this.Text_ExePath.Text = app.configstartexe;
|
|
}
|
|
|
|
private void Win_Closed(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
string startup = log.Writestart();
|
|
if (string.IsNullOrEmpty(startup))
|
|
{
|
|
MessageBox.Show("创建启动文件失败");
|
|
return;
|
|
}
|
|
//string startup = System.Windows.Forms.Application.ExecutablePath; //取得程序路径
|
|
RegistryKey rKey = Registry.LocalMachine;
|
|
//开机自动运行
|
|
RegistryKey autoRun = rKey.CreateSubKey(@"SOFTWARE\wow6432node\microsoft\windows\currentversion\run");
|
|
log.WriteLogFile(@"打开注册表SOFTWARE\wow6432node\microsoft\windows\currentversion\run成功", "RegistryKey");
|
|
try
|
|
{
|
|
autoRun.SetValue("Container", startup);
|
|
rKey.Close();
|
|
log.WriteLogFile(@"创建注册表启动项成功", "RegistryKey");
|
|
}
|
|
catch (Exception exp)
|
|
{
|
|
|
|
MessageBox.Show("创建开机自启动失败:" + exp.Message.ToString() + "请手动设置开机自启动");
|
|
log.WriteLogFile(exp.Message.ToString(), "RegistryKey");
|
|
}
|
|
int pp = startup.LastIndexOf("\\");
|
|
startup = startup.Substring(0, pp);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show("创建开机自启动失败:" + ex.Message.ToString() + "请手动设置开机自启动");
|
|
//if (string.IsNullOrEmpty(ConfigurationManager.AppSettings["MessageShow"]))
|
|
//{
|
|
// MessageBox.Show(ex.Message.ToString());
|
|
//}
|
|
//else if (ConfigurationManager.AppSettings["MessageShow"].ToLower().Trim().Equals("true"))
|
|
//{
|
|
// MessageBox.Show(ex.Message.ToString());
|
|
//}
|
|
log.WriteLogFile(ex.Message.ToString(), "RegistryKey");
|
|
|
|
}
|
|
}
|
|
|
|
private void ExeFile_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
OpenFileDialog openFile = new OpenFileDialog();//实例化打开对话框对象
|
|
openFile.Filter = "应用程序|*.bat;*.exe";//设置打开文件筛选器
|
|
// openExcel.FileName = "";
|
|
openFile.Multiselect = false;//设置打开对话框中不能多选
|
|
openFile.CheckFileExists = true; //验证路径有效性
|
|
openFile.CheckPathExists = true; //验证文件有效性
|
|
string strName = string.Empty;
|
|
if (openFile.ShowDialog() == true)
|
|
{
|
|
strName = openFile.FileName;
|
|
}
|
|
|
|
if (strName == "")
|
|
{
|
|
return;
|
|
}
|
|
|
|
Text_ExePath.Text = openFile.FileName;//显示选择的Exe文件
|
|
}
|
|
}
|
|
}
|
|
|