Commit 346dfc10 authored by keyongyu's avatar keyongyu

const

parent 1a300ffb
This diff is collapsed.
...@@ -18,51 +18,54 @@ namespace DataEditorX ...@@ -18,51 +18,54 @@ namespace DataEditorX
/// </summary> /// </summary>
public static class CheckUpdate public static class CheckUpdate
{ {
static CheckUpdate() static CheckUpdate()
{ {
ServicePointManager.DefaultConnectionLimit=255; ServicePointManager.DefaultConnectionLimit = 255;
} }
public static string URL=""; public static string URL = "";
static string HEAD="[DataEditorX]",HEAD2="[URL]"; static string HEAD = "[DataEditorX]", HEAD2 = "[URL]";
public static bool isOK=false; public static bool isOK = false;
#region 检查版本
public static string Check(string VERURL) public static string Check(string VERURL)
{ {
string urlver="0.0.0.0"; string urlver = "0.0.0.0";
string html=GetHtmlContentByUrl(VERURL); string html = GetHtmlContentByUrl(VERURL);
if(!string.IsNullOrEmpty(html)) if (!string.IsNullOrEmpty(html))
{ {
int t,w; int t, w;
t=html.IndexOf(HEAD); t = html.IndexOf(HEAD);
w=(t>0)?html.IndexOf(HEAD,t+HEAD.Length):0; w = (t > 0) ? html.IndexOf(HEAD, t + HEAD.Length) : 0;
if(w>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); t = html.IndexOf(HEAD2);
w=(t>0)?html.IndexOf(HEAD2,t+HEAD2.Length):0; w = (t > 0) ? html.IndexOf(HEAD2, t + HEAD2.Length) : 0;
if(w>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; return urlver;
} }
#endregion
#region 获取网址内容 #region 获取网址内容
public static string GetHtmlContentByUrl(string url) public static string GetHtmlContentByUrl(string url)
{ {
string htmlContent = string.Empty; string htmlContent = string.Empty;
try { try
{
HttpWebRequest httpWebRequest = HttpWebRequest httpWebRequest =
(HttpWebRequest)WebRequest.Create(url); (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.Timeout = 15000; httpWebRequest.Timeout = 15000;
using(HttpWebResponse httpWebResponse = using (HttpWebResponse httpWebResponse =
(HttpWebResponse)httpWebRequest.GetResponse()) (HttpWebResponse)httpWebRequest.GetResponse())
{ {
using(Stream stream = httpWebResponse.GetResponseStream()) using (Stream stream = httpWebResponse.GetResponseStream())
{ {
using(StreamReader streamReader = using (StreamReader streamReader =
new StreamReader(stream, Encoding.UTF8)) new StreamReader(stream, Encoding.UTF8))
{ {
htmlContent = streamReader.ReadToEnd(); htmlContent = streamReader.ReadToEnd();
...@@ -74,13 +77,15 @@ public static string GetHtmlContentByUrl(string url) ...@@ -74,13 +77,15 @@ public static string GetHtmlContentByUrl(string url)
} }
return htmlContent; return htmlContent;
} }
catch{ catch
{
} }
return ""; return "";
} }
#endregion #endregion
#region 下载文件
public static bool DownLoad(string filename) public static bool DownLoad(string filename)
{ {
try try
...@@ -88,9 +93,9 @@ public static bool DownLoad(string filename) ...@@ -88,9 +93,9 @@ public static bool DownLoad(string filename)
HttpWebRequest Myrq = (HttpWebRequest)System.Net.HttpWebRequest.Create(URL); HttpWebRequest Myrq = (HttpWebRequest)System.Net.HttpWebRequest.Create(URL);
HttpWebResponse myrp = (HttpWebResponse)Myrq.GetResponse(); HttpWebResponse myrp = (HttpWebResponse)Myrq.GetResponse();
long totalBytes = myrp.ContentLength; long totalBytes = myrp.ContentLength;
Stream st = myrp.GetResponseStream(); 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; long totalDownloadedByte = 0;
byte[] by = new byte[2048]; byte[] by = new byte[2048];
int osize = st.Read(by, 0, (int)by.Length); int osize = st.Read(by, 0, (int)by.Length);
...@@ -103,14 +108,15 @@ public static bool DownLoad(string filename) ...@@ -103,14 +108,15 @@ public static bool DownLoad(string filename)
} }
so.Close(); so.Close();
st.Close(); st.Close();
File.Move(filename+".tmp", filename); File.Move(filename + ".tmp", filename);
} }
catch (System.Exception) catch (System.Exception)
{ {
isOK= false; isOK = false;
} }
isOK=true; isOK = true;
return isOK; return isOK;
} }
#endregion
} }
} }
...@@ -68,5 +68,24 @@ public static string Combine(params string[] paths) ...@@ -68,5 +68,24 @@ public static string Combine(params string[] paths)
return builder.ToString(); 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 ...@@ -11,6 +11,13 @@ namespace DataEditorX.Config
/// </summary> /// </summary>
public class CodeConfig 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 成员 #region 成员
public CodeConfig() public CodeConfig()
{ {
......
...@@ -16,9 +16,17 @@ namespace DataEditorX.Config ...@@ -16,9 +16,17 @@ namespace DataEditorX.Config
/// </summary> /// </summary>
public class DataConfig 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() public DataConfig()
{ {
InitMember(MyPath.Combine(Application.StartupPath, MyConfig.FILE_INFO)); InitMember(MyPath.Combine(Application.StartupPath, FILE_INFO));
} }
public DataConfig(string conf) public DataConfig(string conf)
{ {
...@@ -40,13 +48,13 @@ public void InitMember(string conf) ...@@ -40,13 +48,13 @@ public void InitMember(string conf)
} }
//提取内容 //提取内容
string text = File.ReadAllText(conf); string text = File.ReadAllText(conf);
dicCardRules = DataManager.Read(text, MyConfig.TAG_RULE); dicCardRules = DataManager.Read(text, TAG_RULE);
dicSetnames = DataManager.Read(text, MyConfig.TAG_SETNAME); dicSetnames = DataManager.Read(text, TAG_SETNAME);
dicCardTypes = DataManager.Read(text, MyConfig.TAG_TYPE); dicCardTypes = DataManager.Read(text, TAG_TYPE);
dicCardcategorys = DataManager.Read(text, MyConfig.TAG_CATEGORY); dicCardcategorys = DataManager.Read(text, TAG_CATEGORY);
dicCardAttributes = DataManager.Read(text, MyConfig.TAG_ATTRIBUTE); dicCardAttributes = DataManager.Read(text, TAG_ATTRIBUTE);
dicCardRaces = DataManager.Read(text, MyConfig.TAG_RACE); dicCardRaces = DataManager.Read(text, TAG_RACE);
dicCardLevels = DataManager.Read(text, MyConfig.TAG_LEVEL); dicCardLevels = DataManager.Read(text, TAG_LEVEL);
} }
......
...@@ -15,6 +15,11 @@ namespace DataEditorX.Config ...@@ -15,6 +15,11 @@ namespace DataEditorX.Config
public class ImageSet 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; bool isInit;
public ImageSet(){ public ImageSet(){
isInit=false; isInit=false;
...@@ -24,20 +29,20 @@ public void Init() ...@@ -24,20 +29,20 @@ public void Init()
if(isInit) if(isInit)
return; return;
isInit=true; 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.w = ints[0];
this.h = ints[1]; this.h = ints[1];
this.W = ints[2]; this.W = ints[2];
this.H = ints[3]; 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 quilty;
public int w,h,W,H; public int w,h,W,H;
......
...@@ -37,16 +37,16 @@ public class MSEConfig ...@@ -37,16 +37,16 @@ public class MSEConfig
public const string TAG_MONSTER = "monster"; public const string TAG_MONSTER = "monster";
public const string TAG_PENDULUM = "pendulum"; public const string TAG_PENDULUM = "pendulum";
public const string TAG_SPELL_TRAP = "spelltrap"; 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) public MSEConfig(string path)
{ {
Iscn2tw=false; Iscn2tw=false;
_path=path;
regx_monster="(\\s\\S*?)"; regx_monster="(\\s\\S*?)";
regx_pendulum="(\\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)) if (File.Exists(file))
{ {
string content = File.ReadAllText(file, Encoding.UTF8); string content = File.ReadAllText(file, Encoding.UTF8);
...@@ -56,8 +56,8 @@ public MSEConfig(string path) ...@@ -56,8 +56,8 @@ public MSEConfig(string path)
spelltrap = DataManager.subString(content, TAG_SPELL_TRAP); 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>(); replaces=new List<RegStr>();
if(File.Exists(tmp)) if(File.Exists(tmp))
...@@ -80,7 +80,7 @@ public MSEConfig(string path) ...@@ -80,7 +80,7 @@ public MSEConfig(string path)
else if(line.StartsWith("maxcount")) else if(line.StartsWith("maxcount"))
int.TryParse(getValue(line),out maxcount); int.TryParse(getValue(line),out maxcount);
else if(line.StartsWith("imagepath")) else if(line.StartsWith("imagepath"))
imagepath = CheckDir(getValue(line)); imagepath = MyPath.CheckDir(getValue(line), MyPath.Combine(path, "Images"));
else if(line.StartsWith("replace")){ else if(line.StartsWith("replace")){
string word=getValue(line); string word=getValue(line);
int t=word.IndexOf(" "); int t=word.IndexOf(" ");
...@@ -103,25 +103,6 @@ public MSEConfig(string path) ...@@ -103,25 +103,6 @@ public MSEConfig(string path)
Iscn2tw=false; 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) string getRegex(string word)
{ {
return word.Replace("\\n","\n").Replace("\\t","\t"); return word.Replace("\\n","\n").Replace("\\t","\t");
......
...@@ -12,38 +12,16 @@ class MyConfig ...@@ -12,38 +12,16 @@ class MyConfig
public const int MAX_HISTORY = 0x10; public const int MAX_HISTORY = 0x10;
public const string TAG_DATA = "data"; public const string TAG_DATA = "data";
public const string TAG_LANGUAGE = "language"; 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_LANGUAGE = "language.txt";
public const string FILE_TEMP = "open.tmp"; public const string FILE_TEMP = "open.tmp";
public const string FILE_HISTORY = "history.txt"; 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_FUNCTION = "_functions.txt";
public const string FILE_CONSTANT = "constant.lua"; public const string FILE_CONSTANT = "constant.lua";
public const string FILE_STRINGS = "strings.conf"; public const string FILE_STRINGS = "strings.conf";
public const string TAG_SOURCE_URL = "sourceURL";
public const string TAG_RULE = "rule"; public const string TAG_UPDATE_URL = "updateURL";
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 static string readString(string key) public static string readString(string key)
{ {
......
This diff is collapsed.
...@@ -53,7 +53,7 @@ public void SetLanguage(string language) ...@@ -53,7 +53,7 @@ public void SetLanguage(string language)
//文件路径 //文件路径
conflang = MyPath.Combine(datapath, MyConfig.FILE_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的数据
YGOUtil.SetConfig(datacfg); 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