申请会员ID:cheeyeah777
1、申 请 I D:cheeyeah777
2、个人邮箱:cheeyeah@qq.com
3、原创技术文章:受过前后端技术培训,会JAVA,php,C,JSp等语言。
拿破仑全面战争的模组管理器,方便用来切换大型模组NTW3 和 ACW 2.5。用耳朵VS2013 使用c# bat语言。
源代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace listview
{
public partial class Form1 : Form
{
Boolean open_ok = false;
string[] mod = { "ACW 2.5", "NTW3", "vanilla" };
string fullpath, fileName, dir;
string userPath = "C:\\Users\\Asus\\AppData\\Roaming\\The Creative Assembly\\Napoleon\\scripts";
System.Collections.ArrayList alst = null;
private void ACWon_bat()
{
// Console.WriteLine("打开了ACWon_bat!!!");
string diR;
diR = Path.GetDirectoryName(textBox1.Text);
string bat = "cd " + diR + "\\data\\ACW";
bat += "\r\n " + "move ./acw*.pack ../ ";
bat += "\r\n " + "cd ../ ";
bat += "\r\n " + "move boot.pack./ACW " ;
bat += "\r\n " + "cd" + userPath ;
bat += "\r\n " +"echo %cd% " ;
bat += "\r\n " + "dir ";
// "if exist 23.txt ( \n"+
//"echo 11 ; )\n "+
bat += "\r\n " + "if existacw_user.script.txt (";
bat += "\r\n " + "renacw_user.script.txtuser.script.txt ";
bat += "\r\n " + ") else copy " + "\"" + diR + "\\data\\ACW\\user.script.txt" + "\"" + " \"%cd%\" " + " \r\n ";
//特别注意:if else 语句必须注意格式if ( 同行,)和else 必须同行,不能都在一行。注意路径必须用双引号引用,转义符为\"。
// Console.WriteLine("dir= "+diR);
// string testbat = "dir \r\ncopy " +"\"" +diR + "\\data\\ACW\\3.txt"+"\""+" d:\\ "+" \r\npause";
// string bat = "@echo off\r\n echo Hello world!\r\necho 测试中文\r\npause>nul\r\n";
//File.WriteAllText("test.bat", bat, Encoding.GetEncoding(936));
File.WriteAllText("teston.bat", bat);
Process.Start("teston.bat");
}
private void ACWoff_bat()
{
string dir = Path.GetDirectoryName(textBox1.Text);
string bat = "cd " + dir + "\\data\n " +
"move ./acw*.pack ./ACW \n" +
"cd " + userPath + "\n" +
"renuser.script.txtacw_user.script.txt \n" +
"cd " + dir + "\\data\\ACW \n " +
"moveboot.pack../\n";
// "pause \n";
File.WriteAllText("testoff.bat", bat, Encoding.GetEncoding(936));
Process.Start("testoff.bat");
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
textBox1.Text = Application.StartupPath;
checkBox1.Enabled = false;
textBox1.ReadOnly = true;
textBox2.ReadOnly = true;
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = Application.StartupPath;
openFileDialog.Filter = "All files(*.*)|*.*|pack files (*.pack)|*.pack";
openFileDialog.RestoreDirectory = true;
openFileDialog.FilterIndex = 1;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
fullpath = openFileDialog.FileName;
fileName = Path.GetFileName(fullpath);
textBox1.Text = fullpath;
// MessageBox.Show(fileName, "222");
dir = Path.GetDirectoryName(fullpath);
// string s1 = Path.Combine(s,"3.txt"); }
if (File.Exists(fullpath) && fileName == "Napoleon.exe")
{
open_ok = true;
checkBox1.Enabled = true;
MessageBox.Show("目录位置" + dir + "\n 目录正确!", "即将读取pack文件列表...");
// files = Directory.GetFiles(dir + @"/data");
}
else
{
MessageBox.Show(" 读取错误!请重新选择exe文件 !", "正在读取pack文件列表...");
}
showlist();
}
}
private void showlist()
{
Boolean isNtw = false, isAcw = false, isVani = false;
listView1.Clear(); //清除所有项和列
listView1.View = View.Details;
listView1.Columns.Add("编号");
listView1.Columns.Add("文件名");
listView1.Columns.Width = 60;
listView1.Columns.Width = 200;
string newdir;
string[] newfiles = null;
if (!(textBox1.Text == ""))
{
newdir = Path.GetDirectoryName(textBox1.Text);
newfiles = Directory.GetFiles(newdir + @"/data");
}
ListViewItem item = null;
FileVersionInfo info = null;
int id = 1;
foreach (String file in newfiles)
{
string exname = file.Substring(file.LastIndexOf(".") + 1);//得到后缀名
if (".pack".IndexOf(file.Substring(file.LastIndexOf(".") + 1)) > -1)//如果后缀名为.pack文件
{
item = new ListViewItem(id.ToString());
item.SubItems.Add(Path.GetFileName(file));
string filename = Path.GetFileNameWithoutExtension(file);
string firstname_fix = filename.Substring(0, 3);//得到 文件名前三位字符串
// Console.WriteLine(filename);
// Console.WriteLine(firstname_fix);
if (firstname_fix.ToLower() == "ntw")//如果后缀名为.txt文件
{
isNtw = true;
}
else
if (firstname_fix.ToLower() == "acw")//如果后缀名为.txt文件
{
isAcw = true;
}
item.SubItems.Add(file);
info = FileVersionInfo.GetVersionInfo(file);
item.SubItems.Add(info.FileVersion);
listView1.Items.Add(item);
id++;
}
}
if (!isNtw && !isAcw)
{
isVani = true;
}
if (isNtw)
{
textBox2.Text = mod;
MessageBox.Show("检查到 NTW3 的模组文件 !", "提示");
}else if (isAcw)
{
textBox2.Text = mod;
checkBox1.Checked = true;
MessageBox.Show("已安装 ACW 的模组文件 !", "提示");
}
else if (isVani)
{
textBox2.Text = mod;
MessageBox.Show(" 已还原到原版 !", "提示");
checkBox1.Checked = false;
}
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void label3_Click(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
}
private void button4_Click(object sender, EventArgs e)
{
DialogResult dr = MessageBox.Show("确认进入游戏吗?\n请加载好模组准备开始!!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (dr == DialogResult.OK)
{
if (open_ok)
{
if (textBox2.Text == mod)
{
MessageBox.Show(" 进入原版游戏 !", "提示");
System.Diagnostics.Process.Start(fullpath);
}
else if (textBox2.Text == mod)
{
MessageBox.Show(" 进入NTW3 !", "提示");
System.Diagnostics.Process.Start(Path.GetDirectoryName(textBox1.Text) + "\\data\\NTW3\\Version80\\Launcher\\Napoleonic Total War III 8.2.exe");
}
else if (textBox2.Text == mod)
{
MessageBox.Show(" 进入ACW 2.5 !", "提示");
System.Diagnostics.Process.Start(fullpath);
}
}
else
{
MessageBox.Show(" 请选择正确的游戏路径 !", "提示");
}
}
}
private void button2_Click(object sender, EventArgs e)
{
if (!open_ok)
{
MessageBox.Show(" 请选择正确的游戏路径 !", "提示");
}
else
{
// ACWon_bat();
System.Diagnostics.Process.Start(dir + @"/data/ACW/acw_setup.bat");
MessageBox.Show(" 请点击刷新按钮!", "提示");
}
}
private void button3_Click(object sender, EventArgs e)
{
if (!open_ok)
{
MessageBox.Show(" 请选择正确的游戏路径 !", "提示");
}
else
{
//System.Diagnostics.Process.Start(dir + "/data/ACW/acw_uninstall.bat");
ACWoff_bat();
MessageBox.Show(" 请点击刷新按钮!", "提示");
}
}
private void button5_Click(object sender, EventArgs e)
{
ACWon_bat();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button5_Click_1(object sender, EventArgs e)
{
if (!open_ok)
{
MessageBox.Show(" 请选择正确的游戏路径 !", "提示");
}
else
{
showlist();
}
}
private void label5_Click(object sender, EventArgs e)
{
}
private void textBox2_TextChanged_1(object sender, EventArgs e)
{
}
private void button8_Click(object sender, EventArgs e)
{
}
private void button6_Click(object sender, EventArgs e)
{
if (!open_ok)
{
MessageBox.Show(" 请选择正确的游戏路径 !", "提示");
}
else
{
string dir = Path.GetDirectoryName(textBox1.Text);
System.Diagnostics.Process.Start(dir + "\\data\\NTW3\\Version80\\Launcher\\Napoleonic Total War III 8.2.exe");
}
}
private void button7_Click(object sender, EventArgs e)
{
if (!open_ok)
{
MessageBox.Show(" 请选择正确的游戏路径 !", "提示");
}
else
{
Process.Start(Path.GetDirectoryName(textBox1.Text) + "\\data\\NTW3\\Version80\\Launcher\\Napoleonic Total War III 8.2.exe");
}
}
private void button9_Click(object sender, EventArgs e)
{
if (!open_ok)
{
MessageBox.Show(" 请选择正确的游戏路径 !", "提示");
}
else
{
System.Diagnostics.Process.Start(fullpath);
}
}
private void checkBox1_CheckedChanged_1(object sender, EventArgs e)
{
if (!open_ok)
{
checkBox1.Enabled = false;
MessageBox.Show(" 请选择正确的游戏路径 !", "提示"); }
else {
checkBox1.Enabled = true;
if (checkBox1.Checked)
{
ACWon_bat();
// System.Diagnostics.Process.Start(dir + @"/data/ACW/acw_setup.bat");
MessageBox.Show(" 请点击刷新按钮!", "提示");
}
else
{
//System.Diagnostics.Process.Start(dir + "/data/ACW/acw_uninstall.bat");
ACWoff_bat();
MessageBox.Show(" 请点击刷新按钮!", "提示");
}
}
}
private void button2_Click_1(object sender, EventArgs e)
{
if (!open_ok)
{ MessageBox.Show(" 请选择正确的游戏路径 !", "提示"); }
else { System.Diagnostics.Process.Start(Path.GetDirectoryName(textBox1.Text) + "/data/NTW3/Version80/Launcher/Napoleonic Total War III 8.2.exe"); }
string bat = "pushd" +dir + "\\data\\NTW3\\Version80\\Launcher\r\n"+
"start\"\" \"Napoleonic Total War III 8.2.exe\"popd \n"
;
File.WriteAllText("testoff.bat", bat, Encoding.GetEncoding(936));
Process.Start("testoff.bat");
}
}
}
抱歉,未能达到申请要求,申请不通过,可以关注论坛官方微信(吾爱破解论坛),等待开放注册通知。
页:
[1]