Commit 346dfc10 authored by keyongyu's avatar keyongyu

const

parent 1a300ffb
...@@ -28,7 +28,7 @@ namespace DataEditorX ...@@ -28,7 +28,7 @@ namespace DataEditorX
public partial class CodeEditForm : DockContent, IEditForm public partial class CodeEditForm : DockContent, IEditForm
{ {
#region Style #region Style
SortedDictionary<long,string> cardlist; SortedDictionary<long, string> cardlist;
MarkerStyle SameWordsStyle = new MarkerStyle(new SolidBrush(Color.FromArgb(40, Color.White))); MarkerStyle SameWordsStyle = new MarkerStyle(new SolidBrush(Color.FromArgb(40, Color.White)));
#endregion #endregion
...@@ -40,7 +40,7 @@ public partial class CodeEditForm : DockContent, IEditForm ...@@ -40,7 +40,7 @@ public partial class CodeEditForm : DockContent, IEditForm
string nowFile; string nowFile;
string title; string title;
string oldtext; string oldtext;
Dictionary<string,string> tooltipDic; Dictionary<string, string> tooltipDic;
bool tabisspaces = false; bool tabisspaces = false;
string nowcdb; string nowcdb;
public CodeEditForm() public CodeEditForm()
...@@ -49,10 +49,10 @@ public CodeEditForm() ...@@ -49,10 +49,10 @@ public CodeEditForm()
} }
void InitForm() void InitForm()
{ {
cardlist=new SortedDictionary<long, string>(); cardlist = new SortedDictionary<long, string>();
tooltipDic=new Dictionary<string, string>(); tooltipDic = new Dictionary<string, string>();
InitializeComponent(); InitializeComponent();
Font ft=new Font(fctb.Font.Name,fctb.Font.Size/1.2f,FontStyle.Regular); Font ft = new Font(fctb.Font.Name, fctb.Font.Size / 1.2f, FontStyle.Regular);
popupMenu = new FastColoredTextBoxNS.AutocompleteMenu(fctb); popupMenu = new FastColoredTextBoxNS.AutocompleteMenu(fctb);
popupMenu.MinFragmentLength = 2; popupMenu.MinFragmentLength = 2;
popupMenu.Items.Font = ft; popupMenu.Items.Font = ft;
...@@ -76,18 +76,18 @@ void InitForm() ...@@ -76,18 +76,18 @@ void InitForm()
popupMenu_find.Items.Font = ft; popupMenu_find.Items.Font = ft;
popupMenu_find.Items.MaximumSize = new System.Drawing.Size(200, 400); popupMenu_find.Items.MaximumSize = new System.Drawing.Size(200, 400);
popupMenu_find.Items.Width = 300; popupMenu_find.Items.Width = 300;
title=this.Text; title = this.Text;
string fontname = MyConfig.readString(MyConfig.TAG_FONT_NAME); string fontname = MyConfig.readString(CodeConfig.TAG_FONT_NAME);
float fontsize = MyConfig.readFloat(MyConfig.TAG_FONT_SIZE, 14); float fontsize = MyConfig.readFloat(CodeConfig.TAG_FONT_SIZE, 14);
fctb.Font=new Font(fontname,fontsize); fctb.Font = new Font(fontname, fontsize);
if(MyConfig.readBoolean(MyConfig.TAG_IME)) if (MyConfig.readBoolean(CodeConfig.TAG_IME))
fctb.ImeMode=ImeMode.On; fctb.ImeMode = ImeMode.On;
if (MyConfig.readBoolean(MyConfig.TAG_WORDWRAP)) if (MyConfig.readBoolean(CodeConfig.TAG_WORDWRAP))
fctb.WordWrap = true; fctb.WordWrap = true;
else else
fctb.WordWrap = false; fctb.WordWrap = false;
if (MyConfig.readBoolean(MyConfig.TAG_TAB2SPACES)) if (MyConfig.readBoolean(CodeConfig.TAG_TAB2SPACES))
tabisspaces = true; tabisspaces = true;
else else
tabisspaces = false; tabisspaces = false;
...@@ -95,7 +95,7 @@ void InitForm() ...@@ -95,7 +95,7 @@ void InitForm()
public void LoadXml(string xmlfile) public void LoadXml(string xmlfile)
{ {
fctb.DescriptionFile=xmlfile; fctb.DescriptionFile = xmlfile;
} }
#endregion #endregion
...@@ -119,19 +119,19 @@ public bool Create(string file) ...@@ -119,19 +119,19 @@ public bool Create(string file)
} }
public bool Open(string file) public bool Open(string file)
{ {
if(!string.IsNullOrEmpty(file)) if (!string.IsNullOrEmpty(file))
{ {
if(!File.Exists(file)) if (!File.Exists(file))
{ {
FileStream fs=new FileStream(file, FileMode.Create); FileStream fs = new FileStream(file, FileMode.Create);
fs.Close(); fs.Close();
} }
nowFile=file; nowFile = file;
string cdb=MyPath.Combine( string cdb = MyPath.Combine(
Path.GetDirectoryName(file),"../cards.cdb"); Path.GetDirectoryName(file), "../cards.cdb");
SetCardDB(cdb); SetCardDB(cdb);
fctb.OpenFile(nowFile, new UTF8Encoding(false)); fctb.OpenFile(nowFile, new UTF8Encoding(false));
oldtext=fctb.Text; oldtext = fctb.Text;
SetTitle(); SetTitle();
return true; return true;
} }
...@@ -140,11 +140,11 @@ public bool Open(string file) ...@@ -140,11 +140,11 @@ public bool Open(string file)
void HideMenu() void HideMenu()
{ {
if(this.MdiParent ==null) if (this.MdiParent == null)
return; return;
mainMenu.Visible=false; mainMenu.Visible = false;
menuitem_file.Visible=false; menuitem_file.Visible = false;
menuitem_file.Enabled=false; menuitem_file.Enabled = false;
} }
void CodeEditFormLoad(object sender, EventArgs e) void CodeEditFormLoad(object sender, EventArgs e)
...@@ -157,14 +157,16 @@ void CodeEditFormLoad(object sender, EventArgs e) ...@@ -157,14 +157,16 @@ void CodeEditFormLoad(object sender, EventArgs e)
#region doc map #region doc map
void ShowMapToolStripMenuItemClick(object sender, EventArgs e) void ShowMapToolStripMenuItemClick(object sender, EventArgs e)
{ {
if(menuitem_showmap.Checked) if (menuitem_showmap.Checked)
{ {
documentMap1.Visible=false; documentMap1.Visible = false;
menuitem_showmap.Checked=false; menuitem_showmap.Checked = false;
fctb.Width += documentMap1.Width; fctb.Width += documentMap1.Width;
}else{ }
documentMap1.Visible=true; else
menuitem_showmap.Checked=true; {
documentMap1.Visible = true;
menuitem_showmap.Checked = true;
fctb.Width -= documentMap1.Width; fctb.Width -= documentMap1.Width;
} }
} }
...@@ -173,21 +175,21 @@ void ShowMapToolStripMenuItemClick(object sender, EventArgs e) ...@@ -173,21 +175,21 @@ void ShowMapToolStripMenuItemClick(object sender, EventArgs e)
#region title #region title
void SetTitle() void SetTitle()
{ {
string str=title; string str = title;
if(string.IsNullOrEmpty(nowFile)) if (string.IsNullOrEmpty(nowFile))
str=title; str = title;
else else
str=nowFile+"-"+title; str = nowFile + "-" + title;
if(this.MdiParent !=null) if (this.MdiParent != null)
{ {
if(string.IsNullOrEmpty(nowFile)) if (string.IsNullOrEmpty(nowFile))
this.Text=title; this.Text = title;
else else
this.Text=Path.GetFileName(nowFile); this.Text = Path.GetFileName(nowFile);
this.MdiParent.Text=str; this.MdiParent.Text = str;
} }
else else
this.Text=str; this.Text = str;
} }
void CodeEditFormEnter(object sender, EventArgs e) void CodeEditFormEnter(object sender, EventArgs e)
...@@ -200,7 +202,7 @@ void CodeEditFormEnter(object sender, EventArgs e) ...@@ -200,7 +202,7 @@ void CodeEditFormEnter(object sender, EventArgs e)
public void InitTooltip(CodeConfig codeconfig) public void InitTooltip(CodeConfig codeconfig)
{ {
this.tooltipDic = codeconfig.TooltipDic; this.tooltipDic = codeconfig.TooltipDic;
List<AutocompleteItem> items=new List<AutocompleteItem>(); List<AutocompleteItem> items = new List<AutocompleteItem>();
items.AddRange(codeconfig.FunList); items.AddRange(codeconfig.FunList);
items.AddRange(codeconfig.ConList); items.AddRange(codeconfig.ConList);
popupMenu.Items.SetAutocompleteItems(items); popupMenu.Items.SetAutocompleteItems(items);
...@@ -210,15 +212,15 @@ public void InitTooltip(CodeConfig codeconfig) ...@@ -210,15 +212,15 @@ public void InitTooltip(CodeConfig codeconfig)
string FindTooltip(string word) string FindTooltip(string word)
{ {
string desc=""; string desc = "";
foreach(string v in tooltipDic.Keys) foreach (string v in tooltipDic.Keys)
{ {
int t=v.IndexOf("."); int t = v.IndexOf(".");
string k=v; string k = v;
if(t>0) if (t > 0)
k=v.Substring(t+1); k = v.Substring(t + 1);
if(word==k) if (word == k)
desc=tooltipDic[v]; desc = tooltipDic[v];
} }
return desc; return desc;
} }
...@@ -226,22 +228,23 @@ void FctbToolTipNeeded(object sender, ToolTipNeededEventArgs e) ...@@ -226,22 +228,23 @@ void FctbToolTipNeeded(object sender, ToolTipNeededEventArgs e)
{ {
if (!string.IsNullOrEmpty(e.HoveredWord)) if (!string.IsNullOrEmpty(e.HoveredWord))
{ {
long tl=0; long tl = 0;
string name=e.HoveredWord; string name = e.HoveredWord;
string desc=""; string desc = "";
if(!name.StartsWith("0x") && name.Length<=9) if (!name.StartsWith("0x") && name.Length <= 9)
{ {
name=name.Replace("c",""); name = name.Replace("c", "");
long.TryParse(name, out tl); long.TryParse(name, out tl);
} }
if(tl>0){ if (tl > 0)
if(cardlist.ContainsKey(tl)) {
desc=cardlist[tl]; if (cardlist.ContainsKey(tl))
desc = cardlist[tl];
} }
else else
desc=FindTooltip(e.HoveredWord); desc = FindTooltip(e.HoveredWord);
if(!string.IsNullOrEmpty(desc)) if (!string.IsNullOrEmpty(desc))
{ {
e.ToolTipTitle = e.HoveredWord; e.ToolTipTitle = e.HoveredWord;
e.ToolTipText = desc; e.ToolTipText = desc;
...@@ -258,7 +261,8 @@ void FctbKeyDown(object sender, KeyEventArgs e) ...@@ -258,7 +261,8 @@ void FctbKeyDown(object sender, KeyEventArgs e)
//forced show (MinFragmentLength will be ignored) //forced show (MinFragmentLength will be ignored)
popupMenu_fun.Show(true); popupMenu_fun.Show(true);
e.Handled = true; e.Handled = true;
}else if (e.KeyData == (Keys.T | Keys.Control)) }
else if (e.KeyData == (Keys.T | Keys.Control))
{ {
//forced show (MinFragmentLength will be ignored) //forced show (MinFragmentLength will be ignored)
popupMenu_con.Show(true); popupMenu_con.Show(true);
...@@ -272,14 +276,15 @@ void FctbKeyDown(object sender, KeyEventArgs e) ...@@ -272,14 +276,15 @@ void FctbKeyDown(object sender, KeyEventArgs e)
void Menuitem_showinputClick(object sender, EventArgs e) void Menuitem_showinputClick(object sender, EventArgs e)
{ {
if(menuitem_showinput.Checked) if (menuitem_showinput.Checked)
{ {
menuitem_showinput.Checked=false; menuitem_showinput.Checked = false;
tb_input.Visible=false; tb_input.Visible = false;
} }
else{ else
menuitem_showinput.Checked=true; {
tb_input.Visible=true; menuitem_showinput.Checked = true;
tb_input.Visible = true;
} }
} }
#endregion #endregion
...@@ -297,7 +302,7 @@ void Menuitem_replaceClick(object sender, EventArgs e) ...@@ -297,7 +302,7 @@ void Menuitem_replaceClick(object sender, EventArgs e)
bool savefile(bool saveas) bool savefile(bool saveas)
{ {
string alltext = fctb.Text; string alltext = fctb.Text;
if(!tabisspaces) if (!tabisspaces)
alltext = alltext.Replace(" ", "\t"); alltext = alltext.Replace(" ", "\t");
if (saveas) if (saveas)
{ {
...@@ -342,20 +347,20 @@ void QuitToolStripMenuItemClick(object sender, EventArgs e) ...@@ -342,20 +347,20 @@ void QuitToolStripMenuItemClick(object sender, EventArgs e)
void AboutToolStripMenuItemClick(object sender, EventArgs e) void AboutToolStripMenuItemClick(object sender, EventArgs e)
{ {
MyMsg.Show( MyMsg.Show(
LANG.GetMsg(LMSG.About)+"\t"+Application.ProductName+"\n" LANG.GetMsg(LMSG.About) + "\t" + Application.ProductName + "\n"
+LANG.GetMsg(LMSG.Version)+"\t1.1.0.0\n" + LANG.GetMsg(LMSG.Version) + "\t1.1.0.0\n"
+ LANG.GetMsg(LMSG.Author) + "\t柯永裕\n" + LANG.GetMsg(LMSG.Author) + "\t柯永裕\n"
+"Email:\t247321453@qq.com"); + "Email:\t247321453@qq.com");
} }
void Menuitem_openClick(object sender, EventArgs e) void Menuitem_openClick(object sender, EventArgs e)
{ {
using(OpenFileDialog sfdlg=new OpenFileDialog()) using (OpenFileDialog sfdlg = new OpenFileDialog())
{ {
sfdlg.Filter="Script(*.lua)|*.lua|All Files(*.*)|*.*"; sfdlg.Filter = "Script(*.lua)|*.lua|All Files(*.*)|*.*";
if(sfdlg.ShowDialog()==DialogResult.OK) if (sfdlg.ShowDialog() == DialogResult.OK)
{ {
nowFile=sfdlg.FileName; nowFile = sfdlg.FileName;
fctb.OpenFile(nowFile, new UTF8Encoding(false)); fctb.OpenFile(nowFile, new UTF8Encoding(false));
} }
} }
...@@ -366,18 +371,18 @@ void Menuitem_openClick(object sender, EventArgs e) ...@@ -366,18 +371,18 @@ void Menuitem_openClick(object sender, EventArgs e)
#region find #region find
void Tb_inputKeyDown(object sender, KeyEventArgs e) void Tb_inputKeyDown(object sender, KeyEventArgs e)
{ {
if(e.KeyCode==Keys.Enter) if (e.KeyCode == Keys.Enter)
{ {
// //
string key=tb_input.Text; string key = tb_input.Text;
List<AutocompleteItem> tlist=new List<AutocompleteItem>(); List<AutocompleteItem> tlist = new List<AutocompleteItem>();
foreach(string k in tooltipDic.Keys) foreach (string k in tooltipDic.Keys)
{ {
if(tooltipDic[k].IndexOf(key)>=0) if (tooltipDic[k].IndexOf(key) >= 0)
{ {
AutocompleteItem ai=new AutocompleteItem(k); AutocompleteItem ai = new AutocompleteItem(k);
ai.ToolTipTitle=k; ai.ToolTipTitle = k;
ai.ToolTipText=tooltipDic[k]; ai.ToolTipText = tooltipDic[k];
tlist.Add(ai); tlist.Add(ai);
} }
} }
...@@ -390,14 +395,17 @@ void Tb_inputKeyDown(object sender, KeyEventArgs e) ...@@ -390,14 +395,17 @@ void Tb_inputKeyDown(object sender, KeyEventArgs e)
#region close #region close
void CodeEditFormFormClosing(object sender, FormClosingEventArgs e) void CodeEditFormFormClosing(object sender, FormClosingEventArgs e)
{ {
if(!string.IsNullOrEmpty(oldtext)) if (!string.IsNullOrEmpty(oldtext))
{
if (fctb.Text != oldtext)
{ {
if(fctb.Text != oldtext){ if (MyMsg.Question(LMSG.IfSaveScript))
if(MyMsg.Question(LMSG.IfSaveScript))
Save(); Save();
} }
}else if(fctb.Text.Length>0){ }
if(MyMsg.Question(LMSG.IfSaveScript)) else if (fctb.Text.Length > 0)
{
if (MyMsg.Question(LMSG.IfSaveScript))
Save(); Save();
} }
} }
...@@ -406,20 +414,21 @@ void CodeEditFormFormClosing(object sender, FormClosingEventArgs e) ...@@ -406,20 +414,21 @@ void CodeEditFormFormClosing(object sender, FormClosingEventArgs e)
#region card tooltip #region card tooltip
public void SetCDBList(string[] cdbs) public void SetCDBList(string[] cdbs)
{ {
if(cdbs == null) if (cdbs == null)
return; return;
foreach(string cdb in cdbs) foreach (string cdb in cdbs)
{ {
ToolStripMenuItem tsmi=new ToolStripMenuItem(cdb); ToolStripMenuItem tsmi = new ToolStripMenuItem(cdb);
tsmi.Click+=MenuItem_Click; tsmi.Click += MenuItem_Click;
menuitem_setcard.DropDownItems.Add(tsmi); menuitem_setcard.DropDownItems.Add(tsmi);
} }
} }
void MenuItem_Click(object sender, EventArgs e) void MenuItem_Click(object sender, EventArgs e)
{ {
ToolStripMenuItem tsmi=sender as ToolStripMenuItem; ToolStripMenuItem tsmi = sender as ToolStripMenuItem;
if(tsmi!=null){ if (tsmi != null)
string file=tsmi.Text; {
string file = tsmi.Text;
SetCardDB(file); SetCardDB(file);
} }
} }
...@@ -450,7 +459,7 @@ public void SetCards(Card[] cards) ...@@ -450,7 +459,7 @@ public void SetCards(Card[] cards)
#region selection #region selection
void FctbSelectionChangedDelayed(object sender, EventArgs e) void FctbSelectionChangedDelayed(object sender, EventArgs e)
{ {
tb_input.Text=fctb.SelectedText; tb_input.Text = fctb.SelectedText;
fctb.VisibleRange.ClearStyle(SameWordsStyle); fctb.VisibleRange.ClearStyle(SameWordsStyle);
if (!fctb.Selection.IsEmpty) if (!fctb.Selection.IsEmpty)
return;//user selected diapason return;//user selected diapason
...@@ -462,7 +471,7 @@ void FctbSelectionChangedDelayed(object sender, EventArgs e) ...@@ -462,7 +471,7 @@ void FctbSelectionChangedDelayed(object sender, EventArgs e)
return; return;
//highlight same words //highlight same words
var ranges = fctb.VisibleRange.GetRanges("\\b" + text + "\\b"); var ranges = fctb.VisibleRange.GetRanges("\\b" + text + "\\b");
foreach(var r in ranges) foreach (var r in ranges)
r.SetStyle(SameWordsStyle); r.SetStyle(SameWordsStyle);
} }
#endregion #endregion
...@@ -474,10 +483,10 @@ void FctbMouseClick(object sender, MouseEventArgs e) ...@@ -474,10 +483,10 @@ void FctbMouseClick(object sender, MouseEventArgs e)
string text = fragment.Text; string text = fragment.Text;
if (text.Length == 0) if (text.Length == 0)
return; return;
if(e.Button == MouseButtons.Left && Control.ModifierKeys == Keys.Control) if (e.Button == MouseButtons.Left && Control.ModifierKeys == Keys.Control)
{ {
List<int> linenums=fctb.FindLines(@"function\s+?\S+?\."+text+@"\(",RegexOptions.Singleline); List<int> linenums = fctb.FindLines(@"function\s+?\S+?\." + text + @"\(", RegexOptions.Singleline);
if(linenums.Count>0) if (linenums.Count > 0)
{ {
fctb.Navigate(linenums[0]); fctb.Navigate(linenums[0]);
//MessageBox.Show(linenums[0].ToString()); //MessageBox.Show(linenums[0].ToString());
......
...@@ -20,49 +20,52 @@ public static class CheckUpdate ...@@ -20,49 +20,52 @@ 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
...@@ -90,7 +95,7 @@ public static bool DownLoad(string filename) ...@@ -90,7 +95,7 @@ public static bool DownLoad(string filename)
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);
...@@ -57,7 +57,7 @@ public MSEConfig(string path) ...@@ -57,7 +57,7 @@ public MSEConfig(string path)
} }
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)
{ {
......
...@@ -21,7 +21,8 @@ ...@@ -21,7 +21,8 @@
namespace DataEditorX.Core namespace DataEditorX.Core
{ {
public enum MyTask{ public enum MyTask
{
NONE, NONE,
CheckUpdate, CheckUpdate,
ExportData, ExportData,
...@@ -34,22 +35,23 @@ public enum MyTask{ ...@@ -34,22 +35,23 @@ public enum MyTask{
/// </summary> /// </summary>
public class TaskHelper public class TaskHelper
{ {
private MyTask nowTask=MyTask.NONE; #region Member
private MyTask lastTask=MyTask.NONE; private MyTask nowTask = MyTask.NONE;
private MyTask lastTask = MyTask.NONE;
private Card[] cardlist; private Card[] cardlist;
private string[] mArgs; private string[] mArgs;
private ImageSet imgSet=new ImageSet(); private ImageSet imgSet = new ImageSet();
private MSE mseHelper; private MSE mseHelper;
private bool isCancel=false; private bool isCancel = false;
private bool isRun=false; private bool isRun = false;
private BackgroundWorker worker; private BackgroundWorker worker;
public TaskHelper(string datapath,BackgroundWorker worker, public TaskHelper(string datapath, BackgroundWorker worker,
Dictionary<long,string> typedic, Dictionary<long, string> typedic,
Dictionary<long,string> racedic) Dictionary<long, string> racedic)
{ {
this.worker=worker; this.worker = worker;
mseHelper=new MSE(datapath,typedic,racedic); mseHelper = new MSE(datapath, typedic, racedic);
imgSet.Init(); imgSet.Init();
} }
public bool IsRuning() public bool IsRuning()
...@@ -62,16 +64,34 @@ public bool IsCancel() ...@@ -62,16 +64,34 @@ public bool IsCancel()
} }
public void Cancel() public void Cancel()
{ {
isCancel=true; isCancel = true;
} }
public MyTask getLastTask(){ public MyTask getLastTask()
{
return lastTask; return lastTask;
} }
public void SetTask(MyTask myTask,Card[] cards,params string[] args){ #endregion
nowTask=myTask;
cardlist=cards; #region Other
mArgs=args; public void SetTask(MyTask myTask, Card[] cards, params string[] args)
{
nowTask = myTask;
cardlist = cards;
mArgs = args;
}
public void ToImg(string img, string saveimg1, string saveimg2)
{
if (!File.Exists(img))
return;
Bitmap bmp = new Bitmap(img);
MyBitmap.SaveAsJPEG(MyBitmap.Zoom(bmp, imgSet.W, imgSet.H),
saveimg1, imgSet.quilty);
MyBitmap.SaveAsJPEG(MyBitmap.Zoom(bmp, imgSet.w, imgSet.h),
saveimg2, imgSet.quilty);
} }
#endregion
#region 检查更新
public static void CheckVersion(bool showNew) public static void CheckVersion(bool showNew)
{ {
string newver = CheckUpdate.Check(MyConfig.readString(MyConfig.TAG_UPDATE_URL)); string newver = CheckUpdate.Check(MyConfig.readString(MyConfig.TAG_UPDATE_URL));
...@@ -79,19 +99,19 @@ public static void CheckVersion(bool showNew) ...@@ -79,19 +99,19 @@ public static void CheckVersion(bool showNew)
int.TryParse(Application.ProductVersion.Replace(".", ""), out iver); int.TryParse(Application.ProductVersion.Replace(".", ""), out iver);
int.TryParse(newver.Replace(".", ""), out iver2); int.TryParse(newver.Replace(".", ""), out iver2);
if (iver2 > iver) if (iver2 > iver)
{//has new version {//有最新版本
if (!MyMsg.Question(LMSG.HaveNewVersion)) if (!MyMsg.Question(LMSG.HaveNewVersion))
return; return;
} }
else if (iver2 > 0) else if (iver2 > 0)
{//now is last version {//现在就是最新版本
if (!showNew) if (!showNew)
return; return;
if (!MyMsg.Question(LMSG.NowIsNewVersion)) if (!MyMsg.Question(LMSG.NowIsNewVersion))
return; return;
} }
else else
{ {//检查失败
if (!showNew) if (!showNew)
return; return;
MyMsg.Error(LMSG.CheckUpdateFail); MyMsg.Error(LMSG.CheckUpdateFail);
...@@ -103,31 +123,39 @@ public static void CheckVersion(bool showNew) ...@@ -103,31 +123,39 @@ public static void CheckVersion(bool showNew)
else else
MyMsg.Show(LMSG.DownloadFail); MyMsg.Show(LMSG.DownloadFail);
} }
public void OnCheckUpdate(bool showNew){ public void OnCheckUpdate(bool showNew)
{
TaskHelper.CheckVersion(showNew); TaskHelper.CheckVersion(showNew);
} }
public void CutImages(string imgpath,bool isreplace) #endregion
#region 裁剪图片
public void CutImages(string imgpath, bool isreplace)
{ {
int count=cardlist.Length; int count = cardlist.Length;
int i=0; int i = 0;
foreach(Card c in cardlist) foreach (Card c in cardlist)
{ {
if(isCancel) if (isCancel)
break; break;
i++; i++;
worker.ReportProgress((i/count), string.Format("{0}/{1}",i,count)); worker.ReportProgress((i / count), string.Format("{0}/{1}", i, count));
string jpg=MyPath.Combine(imgpath, c.id+".jpg"); string jpg = MyPath.Combine(imgpath, c.id + ".jpg");
string savejpg=MyPath.Combine(mseHelper.ImagePath, c.id+".jpg"); string savejpg = MyPath.Combine(mseHelper.ImagePath, c.id + ".jpg");
if(File.Exists(jpg) && (isreplace || !File.Exists(savejpg))){ if (File.Exists(jpg) && (isreplace || !File.Exists(savejpg)))
Bitmap bp=new Bitmap(jpg); {
Bitmap bmp=null; Bitmap bp = new Bitmap(jpg);
if(c.IsType(CardType.TYPE_XYZ)){ Bitmap bmp = null;
if (c.IsType(CardType.TYPE_XYZ))
{
bmp = MyBitmap.Cut(bp, imgSet.xyzArea); bmp = MyBitmap.Cut(bp, imgSet.xyzArea);
} }
else if(c.IsType(CardType.TYPE_PENDULUM)){ else if (c.IsType(CardType.TYPE_PENDULUM))
{
bmp = MyBitmap.Cut(bp, imgSet.pendulumArea); bmp = MyBitmap.Cut(bp, imgSet.pendulumArea);
} }
else{ else
{
bmp = MyBitmap.Cut(bp, imgSet.normalArea); bmp = MyBitmap.Cut(bp, imgSet.normalArea);
} }
MyBitmap.SaveAsJPEG(bmp, savejpg, imgSet.quilty); MyBitmap.SaveAsJPEG(bmp, savejpg, imgSet.quilty);
...@@ -135,42 +163,41 @@ public void CutImages(string imgpath,bool isreplace) ...@@ -135,42 +163,41 @@ public void CutImages(string imgpath,bool isreplace)
} }
} }
} }
public void ToImg(string img,string saveimg1,string saveimg2){ #endregion
if(!File.Exists(img))
return; #region 转换图片
Bitmap bmp=new Bitmap(img); public void ConvertImages(string imgpath, string gamepath, bool isreplace)
MyBitmap.SaveAsJPEG(MyBitmap.Zoom(bmp, imgSet.W, imgSet.H),
saveimg1, imgSet.quilty);
MyBitmap.SaveAsJPEG(MyBitmap.Zoom(bmp, imgSet.w, imgSet.h),
saveimg2, imgSet.quilty);
}
public void ConvertImages(string imgpath,string gamepath,bool isreplace)
{ {
string picspath=MyPath.Combine(gamepath,"pics"); string picspath = MyPath.Combine(gamepath, "pics");
string thubpath=MyPath.Combine(picspath,"thumbnail"); string thubpath = MyPath.Combine(picspath, "thumbnail");
string[] files=Directory.GetFiles(imgpath); string[] files = Directory.GetFiles(imgpath);
int i=0; int i = 0;
int count=files.Length; int count = files.Length;
foreach(string f in files){ foreach (string f in files)
if(isCancel) {
if (isCancel)
break; break;
i++; i++;
worker.ReportProgress(i/count, string.Format("{0}/{1}",i,count)); worker.ReportProgress(i / count, string.Format("{0}/{1}", i, count));
string ex=Path.GetExtension(f).ToLower(); string ex = Path.GetExtension(f).ToLower();
string name=Path.GetFileNameWithoutExtension(f); string name = Path.GetFileNameWithoutExtension(f);
string jpg_b=MyPath.Combine(picspath,name+".jpg"); string jpg_b = MyPath.Combine(picspath, name + ".jpg");
string jpg_s=MyPath.Combine(thubpath,name+".jpg"); string jpg_s = MyPath.Combine(thubpath, name + ".jpg");
if(ex==".jpg"||ex==".png"||ex==".bmp"){ if (ex == ".jpg" || ex == ".png" || ex == ".bmp")
if(File.Exists(f)){ {
if (File.Exists(f))
{
//存在大图 //存在大图
Bitmap bmp=new Bitmap(f); Bitmap bmp = new Bitmap(f);
if(isreplace || !File.Exists(jpg_b)){ if (isreplace || !File.Exists(jpg_b))
{
MyBitmap.SaveAsJPEG(MyBitmap.Zoom(bmp, imgSet.W, imgSet.H), MyBitmap.SaveAsJPEG(MyBitmap.Zoom(bmp, imgSet.W, imgSet.H),
jpg_b, imgSet.quilty); jpg_b, imgSet.quilty);
} }
if(isreplace || !File.Exists(jpg_s)){ if (isreplace || !File.Exists(jpg_s))
{
MyBitmap.SaveAsJPEG(MyBitmap.Zoom(bmp, imgSet.w, imgSet.h), MyBitmap.SaveAsJPEG(MyBitmap.Zoom(bmp, imgSet.w, imgSet.h),
jpg_s, imgSet.quilty); jpg_s, imgSet.quilty);
...@@ -179,163 +206,183 @@ public void ConvertImages(string imgpath,string gamepath,bool isreplace) ...@@ -179,163 +206,183 @@ public void ConvertImages(string imgpath,string gamepath,bool isreplace)
} }
} }
} }
#endregion
#region MSE存档
public string MSEImage public string MSEImage
{ {
get{return mseHelper.ImagePath;} get { return mseHelper.ImagePath; }
} }
public void SaveMSEs(string file, Card[] cards,bool isUpdate){ public void SaveMSEs(string file, Card[] cards, bool isUpdate)
if(mseHelper.MaxNum==0) {
SaveMSE(1,file, cards, isUpdate); if (mseHelper.MaxNum == 0)
SaveMSE(1, file, cards, isUpdate);
else else
{ {
int c=cards.Length; int c = cards.Length;
int nums=c/mseHelper.MaxNum; int nums = c / mseHelper.MaxNum;
if(nums*mseHelper.MaxNum<c) if (nums * mseHelper.MaxNum < c)
nums++; nums++;
List<Card> clist=new List<Card>(); List<Card> clist = new List<Card>();
for(int i=0;i<nums;i++) for (int i = 0; i < nums; i++)
{ {
clist.Clear(); clist.Clear();
for(int j=0;j<mseHelper.MaxNum;j++) for (int j = 0; j < mseHelper.MaxNum; j++)
{ {
int index=i*mseHelper.MaxNum+j; int index = i * mseHelper.MaxNum + j;
if(index<c) if (index < c)
clist.Add(cards[index]); clist.Add(cards[index]);
} }
int t=file.LastIndexOf(".mse-set"); int t = file.LastIndexOf(".mse-set");
string fname=(t>0)?file.Substring(0,t):file; string fname = (t > 0) ? file.Substring(0, t) : file;
fname=fname+string.Format("_{0}.mse-set",i+1); fname = fname + string.Format("_{0}.mse-set", i + 1);
SaveMSE(i+1,fname,clist.ToArray(),isUpdate); SaveMSE(i + 1, fname, clist.ToArray(), isUpdate);
} }
} }
} }
public void SaveMSE(int num,string file, Card[] cards,bool isUpdate){ public void SaveMSE(int num, string file, Card[] cards, bool isUpdate)
string setFile=file+".txt"; {
string[] images=mseHelper.WriteSet(setFile, cards); string setFile = file + ".txt";
if(isUpdate)//仅更新文字 string[] images = mseHelper.WriteSet(setFile, cards);
if (isUpdate)//仅更新文字
return; return;
int i=0; int i = 0;
int count=images.Length; int count = images.Length;
using(ZipStorer zips=ZipStorer.Create(file, "")) using (ZipStorer zips = ZipStorer.Create(file, ""))
{ {
zips.EncodeUTF8=true; zips.EncodeUTF8 = true;
zips.AddFile(setFile,"set",""); zips.AddFile(setFile, "set", "");
foreach ( string img in images ) foreach (string img in images)
{ {
if(isCancel) if (isCancel)
break; break;
i++; i++;
worker.ReportProgress(i/count, string.Format("{0}/{1}-{2}",i,count,num)); worker.ReportProgress(i / count, string.Format("{0}/{1}-{2}", i, count, num));
zips.AddFile(img, Path.GetFileName(img),""); zips.AddFile(img, Path.GetFileName(img), "");
} }
} }
File.Delete(setFile); File.Delete(setFile);
} }
#endregion
#region 导出数据
public void ExportData(string zipname) public void ExportData(string zipname)
{ {
int i=0; int i = 0;
Card[] cards=cardlist; Card[] cards = cardlist;
if(cards == null || cards.Length == 0) if (cards == null || cards.Length == 0)
return; return;
int count=cards.Length; int count = cards.Length;
string path=Path.GetDirectoryName(zipname); string path = Path.GetDirectoryName(zipname);
string name=Path.GetFileNameWithoutExtension(zipname); string name = Path.GetFileNameWithoutExtension(zipname);
string cdbfile=zipname+".cdb"; string cdbfile = zipname + ".cdb";
string readme=MyPath.Combine(path, name+".txt"); string readme = MyPath.Combine(path, name + ".txt");
string deckydk=MyPath.Combine(path, "deck/"+name+".ydk"); string deckydk = MyPath.Combine(path, "deck/" + name + ".ydk");
string pics=MyPath.Combine(path,"pics"); string pics = MyPath.Combine(path, "pics");
string thumb=MyPath.Combine(pics,"thumbnail"); string thumb = MyPath.Combine(pics, "thumbnail");
string script=MyPath.Combine(path,"script"); string script = MyPath.Combine(path, "script");
File.Delete(cdbfile); File.Delete(cdbfile);
DataBase.Create(cdbfile); DataBase.Create(cdbfile);
DataBase.CopyDB(cdbfile,false,cardlist); DataBase.CopyDB(cdbfile, false, cardlist);
if(File.Exists(zipname)) if (File.Exists(zipname))
File.Delete(zipname); File.Delete(zipname);
using(ZipStorer zips=ZipStorer.Create(zipname, "")) using (ZipStorer zips = ZipStorer.Create(zipname, ""))
{ {
zips.AddFile(cdbfile, name+".cdb",""); zips.AddFile(cdbfile, name + ".cdb", "");
if(File.Exists(readme)) if (File.Exists(readme))
zips.AddFile(readme, "readme_"+name+".txt",""); zips.AddFile(readme, "readme_" + name + ".txt", "");
if(File.Exists(deckydk)) if (File.Exists(deckydk))
zips.AddFile(deckydk, "deck/"+name+".ydk",""); zips.AddFile(deckydk, "deck/" + name + ".ydk", "");
foreach(Card c in cards) foreach (Card c in cards)
{ {
i++; i++;
worker.ReportProgress(i/count, string.Format("{0}/{1}",i,count)); worker.ReportProgress(i / count, string.Format("{0}/{1}", i, count));
//zips.AddFile( //zips.AddFile(
string jpg1=MyPath.Combine(pics, c.id.ToString()+".jpg"); string jpg1 = MyPath.Combine(pics, c.id.ToString() + ".jpg");
string jpg2=MyPath.Combine(thumb, c.id.ToString()+".jpg"); string jpg2 = MyPath.Combine(thumb, c.id.ToString() + ".jpg");
string lua=MyPath.Combine(script, "c"+c.id.ToString()+".lua"); string lua = MyPath.Combine(script, "c" + c.id.ToString() + ".lua");
if(File.Exists(jpg1)) if (File.Exists(jpg1))
zips.AddFile(jpg1,"pics/"+c.id.ToString()+".jpg",""); zips.AddFile(jpg1, "pics/" + c.id.ToString() + ".jpg", "");
if(File.Exists(jpg2)) if (File.Exists(jpg2))
zips.AddFile(jpg2,"pics/thumbnail/"+c.id.ToString()+".jpg",""); zips.AddFile(jpg2, "pics/thumbnail/" + c.id.ToString() + ".jpg", "");
if(File.Exists(lua)) if (File.Exists(lua))
zips.AddFile(lua,"script/c"+c.id.ToString()+".lua",""); zips.AddFile(lua, "script/c" + c.id.ToString() + ".lua", "");
} }
} }
File.Delete(cdbfile); File.Delete(cdbfile);
} }
#endregion
public void Run(){ #region 运行
isCancel=false; public void Run()
isRun=true; {
isCancel = false;
isRun = true;
bool replace; bool replace;
bool showNew; bool showNew;
switch(nowTask){ switch (nowTask)
{
case MyTask.ExportData: case MyTask.ExportData:
if(mArgs!=null && mArgs.Length>=1){ if (mArgs != null && mArgs.Length >= 1)
{
ExportData(mArgs[0]); ExportData(mArgs[0]);
} }
break; break;
case MyTask.CheckUpdate: case MyTask.CheckUpdate:
showNew=false; showNew = false;
if(mArgs!=null && mArgs.Length>=1){ if (mArgs != null && mArgs.Length >= 1)
showNew=(mArgs[0]==Boolean.TrueString)?true:false; {
showNew = (mArgs[0] == Boolean.TrueString) ? true : false;
} }
OnCheckUpdate(showNew); OnCheckUpdate(showNew);
break; break;
case MyTask.CutImages: case MyTask.CutImages:
if(mArgs!=null && mArgs.Length>=2){ if (mArgs != null && mArgs.Length >= 2)
replace=true; {
if(mArgs.Length>=2){ replace = true;
if(mArgs[1]==Boolean.FalseString) if (mArgs.Length >= 2)
replace=false; {
if (mArgs[1] == Boolean.FalseString)
replace = false;
} }
CutImages(mArgs[0],replace); CutImages(mArgs[0], replace);
} }
break; break;
case MyTask.SaveAsMSE: case MyTask.SaveAsMSE:
if(mArgs!=null && mArgs.Length>=2){ if (mArgs != null && mArgs.Length >= 2)
replace=false; {
if(mArgs.Length>=2){ replace = false;
if(mArgs[1]==Boolean.TrueString) if (mArgs.Length >= 2)
replace=true; {
if (mArgs[1] == Boolean.TrueString)
replace = true;
} }
SaveMSEs(mArgs[0], cardlist, replace); SaveMSEs(mArgs[0], cardlist, replace);
} }
break; break;
case MyTask.ConvertImages: case MyTask.ConvertImages:
if(mArgs!=null && mArgs.Length>=2){ if (mArgs != null && mArgs.Length >= 2)
replace=true; {
if(mArgs.Length>=3){ replace = true;
if(mArgs[2]==Boolean.FalseString) if (mArgs.Length >= 3)
replace=false; {
if (mArgs[2] == Boolean.FalseString)
replace = false;
} }
ConvertImages(mArgs[0],mArgs[1],replace); ConvertImages(mArgs[0], mArgs[1], replace);
} }
break; break;
} }
isRun=false; isRun = false;
lastTask=nowTask; lastTask = nowTask;
nowTask=MyTask.NONE; nowTask = MyTask.NONE;
cardlist=null; cardlist = null;
mArgs=null; mArgs = null;
} }
#endregion
} }
} }
...@@ -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