2025-03-28 09:49:56 +08:00

82 lines
2.2 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace AutoUpdateEx
{
public class SetUpHelper
{
//openpath 删除
//servername 等于当前计算机名称
public string GetValue(string Name)
{
string strLine = "";
try
{
FileStream aFile = new FileStream("setup.ini", FileMode.Open);
StreamReader sr = new StreamReader(aFile);
strLine = sr.ReadLine();
while (strLine != null)
{
if (strLine.ToLower().Contains(Name))
{
sr.Close();
return strLine.Replace(Name, "");
}
strLine = sr.ReadLine();
}
sr.Close();
}
catch
{
return "";
}
return "";
}
public static bool SetReplaceValue(string Name, string Value)
{
try
{
string[] LinesText = System.IO.File.ReadAllLines("setup.ini",Encoding.Default);
for (int i = 0; i < LinesText.Length; i++)
{
if (LinesText[i].Split('=')[0].ToLower() == Name)
{
LinesText[i] = Name + "=" + Value;
}
}
using (System.IO.StreamWriter file = new System.IO.StreamWriter("setup.ini", false, Encoding.Default))
{
foreach (string line in LinesText)
{
file.WriteLine(line);// 直接追加文件末尾,换行
}
}
return true;
}
catch
{
return false;
}
}
public static string GetMachineName()
{
try
{
return System.Environment.MachineName;
}
catch (Exception e)
{
return "";
}
}
}
}