Commit 346dfc10 authored by keyongyu's avatar keyongyu

const

parent 1a300ffb
This diff is collapsed.
......@@ -18,51 +18,54 @@ namespace DataEditorX
/// </summary>
public static class CheckUpdate
{
static CheckUpdate()
{
ServicePointManager.DefaultConnectionLimit=255;
}
public static string URL="";
static string HEAD="[DataEditorX]",HEAD2="[URL]";
public static bool isOK=false;
static CheckUpdate()
{
ServicePointManager.DefaultConnectionLimit = 255;
}
public static string URL = "";
static string HEAD = "[DataEditorX]", HEAD2 = "[URL]";
public static bool isOK = false;
#region 检查版本
public static string Check(string VERURL)
{
string urlver="0.0.0.0";
string html=GetHtmlContentByUrl(VERURL);
if(!string.IsNullOrEmpty(html))
string urlver = "0.0.0.0";
string html = GetHtmlContentByUrl(VERURL);
if (!string.IsNullOrEmpty(html))
{
int t,w;
t=html.IndexOf(HEAD);
w=(t>0)?html.IndexOf(HEAD,t+HEAD.Length):0;
if(w>0)
int t, w;
t = html.IndexOf(HEAD);
w = (t > 0) ? html.IndexOf(HEAD, t + HEAD.Length) : 0;
if (w > 0)
{
urlver=html.Substring(t+HEAD.Length,w-t-HEAD.Length);
urlver = html.Substring(t + HEAD.Length, w - t - HEAD.Length);
}
t=html.IndexOf(HEAD2);
w=(t>0)?html.IndexOf(HEAD2,t+HEAD2.Length):0;
if(w>0)
t = html.IndexOf(HEAD2);
w = (t > 0) ? html.IndexOf(HEAD2, t + HEAD2.Length) : 0;
if (w > 0)
{
URL=html.Substring(t+HEAD2.Length,w-t-HEAD2.Length);
URL = html.Substring(t + HEAD2.Length, w - t - HEAD2.Length);
}
}
return urlver;
}
#endregion
#region 获取网址内容
public static string GetHtmlContentByUrl(string url)
{
string htmlContent = string.Empty;
try {
try
{
HttpWebRequest httpWebRequest =
(HttpWebRequest)WebRequest.Create(url);
httpWebRequest.Timeout = 15000;
using(HttpWebResponse httpWebResponse =
using (HttpWebResponse httpWebResponse =
(HttpWebResponse)httpWebRequest.GetResponse())
{
using(Stream stream = httpWebResponse.GetResponseStream())
using (Stream stream = httpWebResponse.GetResponseStream())
{
using(StreamReader streamReader =
using (StreamReader streamReader =
new StreamReader(stream, Encoding.UTF8))
{
htmlContent = streamReader.ReadToEnd();
......@@ -74,13 +77,15 @@ public static string GetHtmlContentByUrl(string url)
}
return htmlContent;
}
catch{
catch
{
}
return "";
}
#endregion
#region 下载文件
public static bool DownLoad(string filename)
{
try
......@@ -88,9 +93,9 @@ public static bool DownLoad(string filename)
HttpWebRequest Myrq = (HttpWebRequest)System.Net.HttpWebRequest.Create(URL);
HttpWebResponse myrp = (HttpWebResponse)Myrq.GetResponse();
long totalBytes = myrp.ContentLength;
Stream st = myrp.GetResponseStream();
Stream so = new System.IO.FileStream(filename+".tmp", FileMode.Create);
Stream so = new System.IO.FileStream(filename + ".tmp", FileMode.Create);
long totalDownloadedByte = 0;
byte[] by = new byte[2048];
int osize = st.Read(by, 0, (int)by.Length);
......@@ -103,14 +108,15 @@ public static bool DownLoad(string filename)
}
so.Close();
st.Close();
File.Move(filename+".tmp", filename);
File.Move(filename + ".tmp", filename);
}
catch (System.Exception)
{
isOK= false;
isOK = false;
}
isOK=true;
isOK = true;
return isOK;
}
#endregion
}
}
......@@ -68,5 +68,24 @@ public static string Combine(params string[] paths)
return builder.ToString();
}
}
//检查目录是否合法
public static string CheckDir(string dir,string defalut)
{
DirectoryInfo fo;
try
{
fo = new DirectoryInfo(MyPath.GetFullPath(dir));
}
catch
{
//路径不合法
fo = new DirectoryInfo(defalut);
}
if (!fo.Exists)
fo.Create();
dir = fo.FullName;
return dir;
}
}
}
......@@ -11,6 +11,13 @@ namespace DataEditorX.Config
/// </summary>
public class CodeConfig
{
public const string TAG_FONT_NAME = "fontname";
public const string TAG_FONT_SIZE = "fontsize";
public const string TAG_IME = "IME";
public const string TAG_WORDWRAP = "wordwrap";
public const string TAG_TAB2SPACES = "tabisspace";
#region 成员
public CodeConfig()
{
......
......@@ -16,9 +16,17 @@ namespace DataEditorX.Config
/// </summary>
public class DataConfig
{
public const string FILE_INFO = "card-info.txt";
public const string TAG_RULE = "rule";
public const string TAG_RACE = "race";
public const string TAG_ATTRIBUTE = "attribute";
public const string TAG_LEVEL = "level";
public const string TAG_CATEGORY = "category";
public const string TAG_TYPE = "type";
public const string TAG_SETNAME = "setname";
public DataConfig()
{
InitMember(MyPath.Combine(Application.StartupPath, MyConfig.FILE_INFO));
InitMember(MyPath.Combine(Application.StartupPath, FILE_INFO));
}
public DataConfig(string conf)
{
......@@ -40,13 +48,13 @@ public void InitMember(string conf)
}
//提取内容
string text = File.ReadAllText(conf);
dicCardRules = DataManager.Read(text, MyConfig.TAG_RULE);
dicSetnames = DataManager.Read(text, MyConfig.TAG_SETNAME);
dicCardTypes = DataManager.Read(text, MyConfig.TAG_TYPE);
dicCardcategorys = DataManager.Read(text, MyConfig.TAG_CATEGORY);
dicCardAttributes = DataManager.Read(text, MyConfig.TAG_ATTRIBUTE);
dicCardRaces = DataManager.Read(text, MyConfig.TAG_RACE);
dicCardLevels = DataManager.Read(text, MyConfig.TAG_LEVEL);
dicCardRules = DataManager.Read(text, TAG_RULE);
dicSetnames = DataManager.Read(text, TAG_SETNAME);
dicCardTypes = DataManager.Read(text, TAG_TYPE);
dicCardcategorys = DataManager.Read(text, TAG_CATEGORY);
dicCardAttributes = DataManager.Read(text, TAG_ATTRIBUTE);
dicCardRaces = DataManager.Read(text, TAG_RACE);
dicCardLevels = DataManager.Read(text, TAG_LEVEL);
}
......
......@@ -15,6 +15,11 @@ namespace DataEditorX.Config
public class ImageSet
{
public const string TAG_IMAGE_OTHER = "image_other";
public const string TAG_IMAGE_XYZ = "image_xyz";
public const string TAG_IMAGE_PENDULUM = "image_pendulum";
public const string TAG_IMAGE_SIZE = "image";
public const string TAG_IMAGE_QUILTY = "image_quilty";
bool isInit;
public ImageSet(){
isInit=false;
......@@ -24,20 +29,20 @@ public void Init()
if(isInit)
return;
isInit=true;
this.normalArea = MyConfig.readArea(MyConfig.TAG_IMAGE_OTHER);
this.normalArea = MyConfig.readArea(TAG_IMAGE_OTHER);
this.xyzArea = MyConfig.readArea(MyConfig.TAG_IMAGE_XYZ);
this.xyzArea = MyConfig.readArea(TAG_IMAGE_XYZ);
this.pendulumArea = MyConfig.readArea(MyConfig.TAG_IMAGE_PENDULUM);
this.pendulumArea = MyConfig.readArea(TAG_IMAGE_PENDULUM);
int[] ints = MyConfig.readIntegers(MyConfig.TAG_IMAGE_SIZE, 4);
int[] ints = MyConfig.readIntegers(TAG_IMAGE_SIZE, 4);
this.w = ints[0];
this.h = ints[1];
this.W = ints[2];
this.H = ints[3];
this.quilty = MyConfig.readInteger(MyConfig.TAG_IMAGE_QUILTY, 95);
this.quilty = MyConfig.readInteger(TAG_IMAGE_QUILTY, 95);
}
public int quilty;
public int w,h,W,H;
......
......@@ -37,16 +37,16 @@ public class MSEConfig
public const string TAG_MONSTER = "monster";
public const string TAG_PENDULUM = "pendulum";
public const string TAG_SPELL_TRAP = "spelltrap";
public const string FILE_CONFIG = "mse-config.txt";
public const string FILE_TEMPLATE = "mse-template.txt";
string _path;
public MSEConfig(string path)
{
Iscn2tw=false;
_path=path;
regx_monster="(\\s\\S*?)";
regx_pendulum="(\\s\\S*?)";
string file = MyPath.Combine(path, MyConfig.TAG_MSE_TEMPLATE);
string file = MyPath.Combine(path, FILE_TEMPLATE);
if (File.Exists(file))
{
string content = File.ReadAllText(file, Encoding.UTF8);
......@@ -56,8 +56,8 @@ public MSEConfig(string path)
spelltrap = DataManager.subString(content, TAG_SPELL_TRAP);
}
string tmp=Path.Combine(path, "mse-config.txt");
string tmp = MyPath.Combine(path, FILE_CONFIG);
replaces=new List<RegStr>();
if(File.Exists(tmp))
......@@ -80,7 +80,7 @@ public MSEConfig(string path)
else if(line.StartsWith("maxcount"))
int.TryParse(getValue(line),out maxcount);
else if(line.StartsWith("imagepath"))
imagepath = CheckDir(getValue(line));
imagepath = MyPath.CheckDir(getValue(line), MyPath.Combine(path, "Images"));
else if(line.StartsWith("replace")){
string word=getValue(line);
int t=word.IndexOf(" ");
......@@ -103,25 +103,6 @@ public MSEConfig(string path)
Iscn2tw=false;
}
}
string CheckDir(string dir)
{
DirectoryInfo fo;
try
{
fo=new DirectoryInfo(MyPath.GetFullPath(dir));
}
catch
{
//路径不合法
dir=MyPath.Combine(_path,"Images");
fo=new DirectoryInfo(dir);
}
if(!fo.Exists)
fo.Create();
dir=fo.FullName;
return dir;
}
string getRegex(string word)
{
return word.Replace("\\n","\n").Replace("\\t","\t");
......
......@@ -12,38 +12,16 @@ class MyConfig
public const int MAX_HISTORY = 0x10;
public const string TAG_DATA = "data";
public const string TAG_LANGUAGE = "language";
public const string TAG_IMAGE_OTHER = "image_other";
public const string TAG_IMAGE_XYZ = "image_xyz";
public const string TAG_IMAGE_PENDULUM = "image_pendulum";
public const string TAG_IMAGE_SIZE = "image";
public const string TAG_IMAGE_QUILTY = "image_quilty";
public const string TAG_FONT_NAME = "fontname";
public const string TAG_FONT_SIZE = "fontsize";
public const string TAG_IME = "IME";
public const string TAG_WORDWRAP = "wordwrap";
public const string TAG_TAB2SPACES = "tabisspace";
public const string TAG_SOURCE_URL = "sourceURL";
public const string TAG_UPDATE_URL = "updateURL";
public const string FILE_LANGUAGE = "language.txt";
public const string FILE_TEMP = "open.tmp";
public const string FILE_HISTORY = "history.txt";
public const string FILE_INFO = "card-info.txt";
public const string FILE_FUNCTION = "_functions.txt";
public const string FILE_CONSTANT = "constant.lua";
public const string FILE_STRINGS = "strings.conf";
public const string TAG_RULE = "rule";
public const string TAG_RACE = "race";
public const string TAG_ATTRIBUTE = "attribute";
public const string TAG_LEVEL = "level";
public const string TAG_CATEGORY = "category";
public const string TAG_TYPE = "type";
public const string TAG_SETNAME = "setname";
public const string TAG_MSE_CONFIG = "mse-config.txt";
public const string TAG_MSE_TEMPLATE ="mse-template.txt";
public const string TAG_SOURCE_URL = "sourceURL";
public const string TAG_UPDATE_URL = "updateURL";
public static string readString(string key)
{
......
This diff is collapsed.
......@@ -53,7 +53,7 @@ public void SetLanguage(string language)
//文件路径
conflang = MyPath.Combine(datapath, MyConfig.FILE_LANGUAGE);
//游戏数据
datacfg = new DataConfig(MyPath.Combine(datapath, MyConfig.FILE_INFO));
datacfg = new DataConfig(MyPath.Combine(datapath, DataConfig.FILE_INFO));
//初始化YGOUtil的数据
YGOUtil.SetConfig(datacfg);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment