144 lines
4.1 KiB
C#
144 lines
4.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Windows.Forms;
|
|
|
|
namespace YLPublishTool.Forms
|
|
{
|
|
public partial class MainForm : Form
|
|
{
|
|
string _dir;
|
|
|
|
public MainForm()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Button1_Click(object sender, EventArgs e)
|
|
{
|
|
folderBrowserDialog1.SelectedPath = _dir;
|
|
|
|
if (_dir != textBox1.Text)
|
|
{
|
|
LoadFileViews(textBox1.Text);
|
|
}
|
|
else if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
|
|
{
|
|
LoadFileViews(folderBrowserDialog1.SelectedPath);
|
|
}
|
|
}
|
|
|
|
private void MainForm_Load(object sender, EventArgs e)
|
|
{
|
|
_dir = Path.Combine(AppContext.BaseDirectory, "data");
|
|
|
|
try
|
|
{
|
|
var dirFile = Path.Combine(_dir, "dir.text");
|
|
if (File.Exists(dirFile))
|
|
{
|
|
var path = File.ReadAllText(dirFile).Trim();
|
|
if (!string.IsNullOrWhiteSpace(path) && Directory.Exists(path))
|
|
{
|
|
_dir = path;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
NLog.LogManager.GetLogger("初始化").Error(ex, "读取配置文件出错");
|
|
}
|
|
|
|
LoadFileViews(_dir);
|
|
}
|
|
|
|
private void ParseMenu_Click(object sender, EventArgs e)
|
|
{
|
|
var sels = listView1.SelectedItems.Cast<ListViewItem>();
|
|
if (sels.Any())
|
|
{
|
|
new ParseForm() { ParseFilePath = sels.First().Tag.ToString() }.Show();
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("请选择一项");
|
|
}
|
|
}
|
|
|
|
private void ExecMenu_Click(object sender, EventArgs e)
|
|
{
|
|
RunScript(false);
|
|
}
|
|
|
|
private void EditMenu_Click(object sender, EventArgs e)
|
|
{
|
|
var sels = listView1.SelectedItems.Cast<ListViewItem>();
|
|
if (sels.Any())
|
|
{
|
|
System.Diagnostics.Process.Start(sels.First().Tag.ToString());
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("请选择一项");
|
|
}
|
|
}
|
|
|
|
private void LoadFileViews(string dir)
|
|
{
|
|
bool saveDir = dir != _dir;
|
|
_dir = textBox1.Text = dir;
|
|
listView1.Items.Clear();
|
|
var list = new List<string>(20) { dir };
|
|
list.AddRange(Directory.GetDirectories(dir));
|
|
var files = list.SelectMany(n => Directory.GetFiles(n, "*.ini"));
|
|
var items = files.Select(n =>
|
|
new ListViewItem(Path.GetFileName(n), 0) { Tag = n }).ToArray();
|
|
listView1.Items.AddRange(items);
|
|
if (saveDir)
|
|
{
|
|
var dirFile = Path.Combine(AppContext.BaseDirectory, "data\\dir.text");
|
|
File.WriteAllText(dirFile, _dir);
|
|
}
|
|
}
|
|
|
|
private void textBox1_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
LoadFileViews(textBox1.Text);
|
|
}
|
|
|
|
private void textBox1_MouseUp(object sender, MouseEventArgs e)
|
|
{
|
|
textBox1.SelectAll();
|
|
}
|
|
|
|
private void emptyRunMenu_Click(object sender, EventArgs e)
|
|
{
|
|
RunScript(true);
|
|
}
|
|
|
|
private void RunScript(bool emptyRun)
|
|
{
|
|
var sels = listView1.SelectedItems.Cast<ListViewItem>();
|
|
if (sels.Any())
|
|
{
|
|
foreach (var s in sels)
|
|
{
|
|
try
|
|
{
|
|
new Runner { EmptyRun = emptyRun }.Run(s.Tag.ToString());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
NLog.LogManager.GetLogger(s.Text).Error(ex, "执行失败");
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MessageBox.Show("请选择一项");
|
|
}
|
|
}
|
|
}
|
|
}
|