天津投入产出系统后端
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.
 
 
 
 
 
 

228 lines
5.8 KiB

using Microsoft.Win32;
using System;
using System.Globalization;
namespace Globale_Variablen.Global
{
public class XNRegistry
{
protected bool m_bOpen;
protected RegistryKey m_key;
protected string m_StrBase;
public XNRegistry()
{
this.m_bOpen = false;
}
public XNRegistry(string key)
{
this.m_bOpen = false;
this.OpenHKLM(key);
}
public double GetVal(string section, string entry, double stdval)
{
if (!this.m_bOpen)
{
return stdval;
}
try
{
CultureInfo info = new CultureInfo("");
string defaultValue = Convert.ToString(stdval, info.NumberFormat);
double num = stdval;
RegistryKey key = this.OpenKey(section, false);
if (key == null)
{
return stdval;
}
num = Convert.ToDouble(key.GetValue(entry, defaultValue).ToString(), info.NumberFormat);
key.Close();
return num;
}
catch
{
return stdval;
}
}
public object GetVal(string section, string entry, object stdval)
{
if (!this.m_bOpen)
{
return stdval;
}
try
{
RegistryKey key = this.OpenKey(section, false);
if (key == null)
{
return stdval;
}
object obj2 = key.GetValue(entry, stdval);
key.Close();
return obj2;
}
catch
{
return stdval;
}
}
public float GetVal(string section, string entry, float stdval)
{
if (!this.m_bOpen)
{
return stdval;
}
try
{
CultureInfo info = new CultureInfo("");
string defaultValue = Convert.ToString(stdval, info.NumberFormat);
float num = stdval;
RegistryKey key = this.OpenKey(section, false);
if (key == null)
{
return stdval;
}
num = Convert.ToSingle(key.GetValue(entry, defaultValue).ToString(), info.NumberFormat);
key.Close();
return num;
}
catch
{
return stdval;
}
}
public bool IsOpen()
{
return this.m_bOpen;
}
public bool OpenHKCU(string key)
{
this.m_key = Registry.CurrentUser;
return this.m_bOpen;
}
public bool OpenHKLM(string key)
{
this.m_key = Registry.LocalMachine;
this.m_StrBase = @"SOFTWARE\" + key;
try
{
this.m_key.CreateSubKey(this.m_StrBase);
this.m_bOpen = true;
}
catch
{
this.m_bOpen = false;
}
return this.m_bOpen;
}
public RegistryKey OpenKey(string key, bool bWrite)
{
if (!this.m_bOpen)
{
return null;
}
RegistryKey key2 = null;
try
{
string strBase = this.m_StrBase;
if (key.Length != 0)
{
strBase = strBase + @"\" + key;
}
if (bWrite)
{
return this.m_key.CreateSubKey(strBase);
}
key2 = this.m_key.OpenSubKey(strBase);
}
catch
{
return null;
}
return key2;
}
public bool SetVal(string section, string entry, double val)
{
if (!this.m_bOpen)
{
return false;
}
try
{
CultureInfo info = new CultureInfo("");
string str = Convert.ToString(val, info.NumberFormat);
RegistryKey key = this.OpenKey(section, true);
if (key == null)
{
return false;
}
key.SetValue(entry, str);
key.Close();
return true;
}
catch
{
return false;
}
}
public bool SetVal(string section, string entry, object val)
{
if (!this.m_bOpen)
{
return false;
}
try
{
RegistryKey key = this.OpenKey(section, true);
if (key == null)
{
return false;
}
key.SetValue(entry, val);
key.Close();
return true;
}
catch
{
return false;
}
}
public bool SetVal(string section, string entry, float val)
{
if (!this.m_bOpen)
{
return false;
}
try
{
CultureInfo info = new CultureInfo("");
string str = Convert.ToString(val, info.NumberFormat);
RegistryKey key = this.OpenKey(section, true);
if (key == null)
{
return false;
}
key.SetValue(entry, str);
key.Close();
return true;
}
catch
{
return false;
}
}
}
}