弄了个自动提示有没有版本的
放在Load事件里
//检查有没有版本
if (listBox1.Items.Count == 0)
{
MessageBoxButtons messButton = MessageBoxButtons.OKCancel;
DialogResult dr = MessageBox.Show("检测到没有版本,是否前往下载中心下载?", "启动器提示", messButton, MessageBoxIcon.Information);
if (dr == DialogResult.OK)//如果点击“确定”按钮
{
Settings st = new Settings();
st.纯净版下载();//要在Settings窗体写进下面附件①里的代码
st.LoadForm
st.Show();
Setting();//直达“设置”//纯属把设置弄到主页面的,不用写
}
else//如果点击“取消”按钮
{
Setting();//直达“设置”//纯属把设置弄到主页面的,不用写
}
}
附件:
①:
public void 纯净版下载 ()
{
if (File.Exists(Application.StartupPath + "\\tmp.json"))//如果临时文件存在
{
File.Delete(Application.StartupPath + "\\tmp.json");//删掉
}
wc.DownloadFile("
https://launchermeta.mojang.com/mc/game/version_manifest.json", Application.StartupPath + "\\tmp.json");//下载版本列表文件
rtxt = File.ReadAllText(Application.StartupPath + "\\tmp.json").Replace("\n", "").Replace(" ", "");//读取版本列表
File.Delete(Application.StartupPath + "\\tmp.json");//删除临时文件
int tmp = rtxt.IndexOf("versions") + "versions".Length + 3;//读取objects数组数据
String versions_S = rtxt.Substring(tmp, rtxt.LastIndexOf("]", rtxt.Length - 1) - tmp);//同上
String[] versions = versions_S.Replace("},{", "$").Split("$".ToCharArray());//分割数组
String tmu = "";//声明并初始化tmu
listBox1.Items.Clear();//清空列表
foreach (String vi in versions)
{//为每个项循环
tmp = vi.IndexOf("id") + "id".Length + 3;//读取id
tmu = vi.Substring(tmp, vi.IndexOf("\"", tmp) - tmp);//同上
tmp = vi.IndexOf("url") + "url".Length + 3;//读取url
String tmua = vi.Substring(tmp, vi.IndexOf("\"", tmp) - tmp);//同上
listBox1.Items.Add(tmu + " " + tmua);//添加项
}
button3.Text = "下载";
}
好吧其实可以弄个简单点的,不过会让Settings.Designer.cs出错