Commit 346dfc10 authored by keyongyu's avatar keyongyu

const

parent 1a300ffb
...@@ -22,85 +22,85 @@ ...@@ -22,85 +22,85 @@
namespace DataEditorX namespace DataEditorX
{ {
/// <summary> /// <summary>
/// Description of CodeEditForm. /// Description of CodeEditForm.
/// </summary> /// </summary>
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
#region init #region init
AutocompleteMenu popupMenu; AutocompleteMenu popupMenu;
AutocompleteMenu popupMenu_fun; AutocompleteMenu popupMenu_fun;
AutocompleteMenu popupMenu_con; AutocompleteMenu popupMenu_con;
AutocompleteMenu popupMenu_find; AutocompleteMenu popupMenu_find;
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()
{ {
InitForm(); InitForm();
} }
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;
popupMenu.Items.MaximumSize = new System.Drawing.Size(200, 400); popupMenu.Items.MaximumSize = new System.Drawing.Size(200, 400);
popupMenu.Items.Width = 300; popupMenu.Items.Width = 300;
popupMenu_fun = new FastColoredTextBoxNS.AutocompleteMenu(fctb); popupMenu_fun = new FastColoredTextBoxNS.AutocompleteMenu(fctb);
popupMenu_fun.MinFragmentLength = 2; popupMenu_fun.MinFragmentLength = 2;
popupMenu_fun.Items.Font = ft; popupMenu_fun.Items.Font = ft;
popupMenu_fun.Items.MaximumSize = new System.Drawing.Size(200, 400); popupMenu_fun.Items.MaximumSize = new System.Drawing.Size(200, 400);
popupMenu_fun.Items.Width = 300; popupMenu_fun.Items.Width = 300;
popupMenu_con = new FastColoredTextBoxNS.AutocompleteMenu(fctb); popupMenu_con = new FastColoredTextBoxNS.AutocompleteMenu(fctb);
popupMenu_con.MinFragmentLength = 2; popupMenu_con.MinFragmentLength = 2;
popupMenu_con.Items.Font = ft; popupMenu_con.Items.Font = ft;
popupMenu_con.Items.MaximumSize = new System.Drawing.Size(200, 400); popupMenu_con.Items.MaximumSize = new System.Drawing.Size(200, 400);
popupMenu_con.Items.Width = 300; popupMenu_con.Items.Width = 300;
popupMenu_find = new FastColoredTextBoxNS.AutocompleteMenu(fctb); popupMenu_find = new FastColoredTextBoxNS.AutocompleteMenu(fctb);
popupMenu_find.MinFragmentLength = 2; popupMenu_find.MinFragmentLength = 2;
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;
} }
public void LoadXml(string xmlfile) public void LoadXml(string xmlfile)
{ {
fctb.DescriptionFile=xmlfile; fctb.DescriptionFile = xmlfile;
} }
#endregion #endregion
#region Open #region Open
public void SetActived() public void SetActived()
{ {
this.Activate(); this.Activate();
...@@ -117,187 +117,192 @@ public bool Create(string file) ...@@ -117,187 +117,192 @@ public bool Create(string file)
{ {
return Open(file); return Open(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;
} }
return false; return false;
} }
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)
{ {
HideMenu(); HideMenu();
fctb.OnTextChangedDelayed(fctb.Range); fctb.OnTextChangedDelayed(fctb.Range);
} }
#endregion #endregion
#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; {
fctb.Width -= documentMap1.Width; documentMap1.Visible = true;
} menuitem_showmap.Checked = true;
} fctb.Width -= documentMap1.Width;
#endregion }
}
#region title #endregion
void SetTitle()
{ #region title
string str=title; void SetTitle()
if(string.IsNullOrEmpty(nowFile)) {
str=title; string str = title;
else if (string.IsNullOrEmpty(nowFile))
str=nowFile+"-"+title; str = title;
if(this.MdiParent !=null) else
{ str = nowFile + "-" + title;
if(string.IsNullOrEmpty(nowFile)) if (this.MdiParent != null)
this.Text=title; {
else if (string.IsNullOrEmpty(nowFile))
this.Text=Path.GetFileName(nowFile); this.Text = title;
this.MdiParent.Text=str; else
} this.Text = Path.GetFileName(nowFile);
else this.MdiParent.Text = str;
this.Text=str; }
} else
this.Text = str;
void CodeEditFormEnter(object sender, EventArgs e) }
{
SetTitle(); void CodeEditFormEnter(object sender, EventArgs e)
} {
#endregion SetTitle();
}
#region tooltip #endregion
public void InitTooltip(CodeConfig codeconfig)
{ #region tooltip
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);
popupMenu_con.Items.SetAutocompleteItems(codeconfig.ConList); popupMenu_con.Items.SetAutocompleteItems(codeconfig.ConList);
popupMenu_fun.Items.SetAutocompleteItems(codeconfig.FunList); popupMenu_fun.Items.SetAutocompleteItems(codeconfig.FunList);
} }
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;
} }
void FctbToolTipNeeded(object sender, ToolTipNeededEventArgs e) 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 }
desc=FindTooltip(e.HoveredWord); else
if(!string.IsNullOrEmpty(desc)) desc = FindTooltip(e.HoveredWord);
{ if (!string.IsNullOrEmpty(desc))
e.ToolTipTitle = e.HoveredWord; {
e.ToolTipText = desc; e.ToolTipTitle = e.HoveredWord;
} e.ToolTipText = desc;
} }
} }
#endregion }
#endregion
#region Key
void FctbKeyDown(object sender, KeyEventArgs e) #region Key
{ void FctbKeyDown(object sender, KeyEventArgs e)
if (e.KeyData == (Keys.K | Keys.Control)) {
{ if (e.KeyData == (Keys.K | Keys.Control))
//forced show (MinFragmentLength will be ignored) {
popupMenu_fun.Show(true); //forced show (MinFragmentLength will be ignored)
e.Handled = true; popupMenu_fun.Show(true);
}else if (e.KeyData == (Keys.T | Keys.Control)) e.Handled = true;
{ }
//forced show (MinFragmentLength will be ignored) else if (e.KeyData == (Keys.T | Keys.Control))
popupMenu_con.Show(true); {
e.Handled = true; //forced show (MinFragmentLength will be ignored)
} popupMenu_con.Show(true);
//else if(e.KeyData == Keys(Keys.Control | Keys e.Handled = true;
} }
#endregion //else if(e.KeyData == Keys(Keys.Control | Keys
}
#region input #endregion
void Menuitem_showinputClick(object sender, EventArgs e) #region input
{
if(menuitem_showinput.Checked) void Menuitem_showinputClick(object sender, EventArgs e)
{ {
menuitem_showinput.Checked=false; if (menuitem_showinput.Checked)
tb_input.Visible=false; {
} menuitem_showinput.Checked = false;
else{ tb_input.Visible = false;
menuitem_showinput.Checked=true; }
tb_input.Visible=true; else
} {
} menuitem_showinput.Checked = true;
#endregion tb_input.Visible = true;
}
#region menu }
void Menuitem_findClick(object sender, EventArgs e) #endregion
{
fctb.ShowFindDialog(); #region menu
} void Menuitem_findClick(object sender, EventArgs e)
{
void Menuitem_replaceClick(object sender, EventArgs e) fctb.ShowFindDialog();
{ }
fctb.ShowReplaceDialog();
} void Menuitem_replaceClick(object sender, EventArgs e)
{
fctb.ShowReplaceDialog();
}
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)
{ {
...@@ -317,119 +322,123 @@ bool savefile(bool saveas) ...@@ -317,119 +322,123 @@ bool savefile(bool saveas)
return true; return true;
} }
public bool Save() public bool Save()
{ {
return savefile(string.IsNullOrEmpty(nowFile)); return savefile(string.IsNullOrEmpty(nowFile));
} }
public bool SaveAs() public bool SaveAs()
{ {
return savefile(true); return savefile(true);
} }
void SaveToolStripMenuItemClick(object sender, EventArgs e) void SaveToolStripMenuItemClick(object sender, EventArgs e)
{ {
Save(); Save();
} }
void SaveAsToolStripMenuItemClick(object sender, EventArgs e) void SaveAsToolStripMenuItemClick(object sender, EventArgs e)
{ {
SaveAs(); SaveAs();
} }
void QuitToolStripMenuItemClick(object sender, EventArgs e) void QuitToolStripMenuItemClick(object sender, EventArgs e)
{ {
this.Close(); this.Close();
} }
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));
} }
} }
} }
#endregion #endregion
#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);
} }
} }
popupMenu_find.Items.SetAutocompleteItems(tlist.ToArray()); popupMenu_find.Items.SetAutocompleteItems(tlist.ToArray());
popupMenu_find.Show(true); popupMenu_find.Show(true);
} }
} }
#endregion #endregion
#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)) {
Save(); if (MyMsg.Question(LMSG.IfSaveScript))
} Save();
}else if(fctb.Text.Length>0){ }
if(MyMsg.Question(LMSG.IfSaveScript)) }
Save(); else if (fctb.Text.Length > 0)
} {
} if (MyMsg.Question(LMSG.IfSaveScript))
Save();
}
}
#endregion #endregion
#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; {
SetCardDB(file); string file = tsmi.Text;
} SetCardDB(file);
} }
public void SetCardDB(string name) }
{ public void SetCardDB(string name)
{
nowcdb = name; nowcdb = name;
if (!backgroundWorker1.IsBusy) if (!backgroundWorker1.IsBusy)
backgroundWorker1.RunWorkerAsync(); backgroundWorker1.RunWorkerAsync();
} }
private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{ {
if (nowcdb != null && File.Exists(nowcdb)) if (nowcdb != null && File.Exists(nowcdb))
...@@ -449,40 +458,40 @@ public void SetCards(Card[] cards) ...@@ -449,40 +458,40 @@ 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
//get fragment around caret //get fragment around caret
var fragment = fctb.Selection.GetFragment(@"\w"); var fragment = fctb.Selection.GetFragment(@"\w");
string text = fragment.Text; string text = fragment.Text;
if (text.Length == 0) if (text.Length == 0)
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
#region goto function define #region goto function define
void FctbMouseClick(object sender, MouseEventArgs e) void FctbMouseClick(object sender, MouseEventArgs e)
{ {
var fragment = fctb.Selection.GetFragment(@"\w"); var fragment = fctb.Selection.GetFragment(@"\w");
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());
} }
} }
} }
#endregion #endregion
......
...@@ -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)
{ {
......
...@@ -21,57 +21,77 @@ ...@@ -21,57 +21,77 @@
namespace DataEditorX.Core namespace DataEditorX.Core
{ {
public enum MyTask{ public enum MyTask
NONE, {
CheckUpdate, NONE,
ExportData, CheckUpdate,
SaveAsMSE, ExportData,
CutImages, SaveAsMSE,
ConvertImages, CutImages,
} ConvertImages,
/// <summary> }
/// Description of TaskHelper. /// <summary>
/// </summary> /// Description of TaskHelper.
public class TaskHelper /// </summary>
{ public class TaskHelper
private MyTask nowTask=MyTask.NONE; {
private MyTask lastTask=MyTask.NONE; #region Member
private Card[] cardlist; private MyTask nowTask = MyTask.NONE;
private string[] mArgs; private MyTask lastTask = MyTask.NONE;
private ImageSet imgSet=new ImageSet(); private Card[] cardlist;
private MSE mseHelper; private string[] mArgs;
private bool isCancel=false; private ImageSet imgSet = new ImageSet();
private bool isRun=false; private MSE mseHelper;
private BackgroundWorker worker; private bool isCancel = false;
private bool isRun = false;
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()
{ {
return isRun; return isRun;
} }
public bool IsCancel() public bool IsCancel()
{ {
return isCancel; return 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){ }
nowTask=myTask; #endregion
cardlist=cards;
mArgs=args; #region Other
} 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,239 +123,266 @@ public static void CheckVersion(bool showNew) ...@@ -103,239 +123,266 @@ 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
{
int count=cardlist.Length;
int i=0;
foreach(Card c in cardlist)
{
if(isCancel)
break;
i++;
worker.ReportProgress((i/count), string.Format("{0}/{1}",i,count));
string jpg=MyPath.Combine(imgpath, c.id+".jpg");
string savejpg=MyPath.Combine(mseHelper.ImagePath, c.id+".jpg");
if(File.Exists(jpg) && (isreplace || !File.Exists(savejpg))){
Bitmap bp=new Bitmap(jpg);
Bitmap bmp=null;
if(c.IsType(CardType.TYPE_XYZ)){
bmp = MyBitmap.Cut(bp, imgSet.xyzArea);
}
else if(c.IsType(CardType.TYPE_PENDULUM)){
bmp = MyBitmap.Cut(bp, imgSet.pendulumArea);
}
else{
bmp = MyBitmap.Cut(bp, imgSet.normalArea);
}
MyBitmap.SaveAsJPEG(bmp, savejpg, imgSet.quilty);
//bmp.Save(savejpg, ImageFormat.Png);
}
}
}
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);
}
public void ConvertImages(string imgpath,string gamepath,bool isreplace)
{
string picspath=MyPath.Combine(gamepath,"pics");
string thubpath=MyPath.Combine(picspath,"thumbnail");
string[] files=Directory.GetFiles(imgpath);
int i=0;
int count=files.Length;
foreach(string f in files){
if(isCancel)
break;
i++;
worker.ReportProgress(i/count, string.Format("{0}/{1}",i,count));
string ex=Path.GetExtension(f).ToLower();
string name=Path.GetFileNameWithoutExtension(f);
string jpg_b=MyPath.Combine(picspath,name+".jpg");
string jpg_s=MyPath.Combine(thubpath,name+".jpg");
if(ex==".jpg"||ex==".png"||ex==".bmp"){
if(File.Exists(f)){
//存在大图
Bitmap bmp=new Bitmap(f);
if(isreplace || !File.Exists(jpg_b)){
MyBitmap.SaveAsJPEG(MyBitmap.Zoom(bmp, imgSet.W, imgSet.H),
jpg_b, imgSet.quilty);
}
if(isreplace || !File.Exists(jpg_s)){
MyBitmap.SaveAsJPEG(MyBitmap.Zoom(bmp, imgSet.w, imgSet.h),
jpg_s, imgSet.quilty);
}
}
}
}
}
public string MSEImage
{
get{return mseHelper.ImagePath;}
}
public void SaveMSEs(string file, Card[] cards,bool isUpdate){
if(mseHelper.MaxNum==0)
SaveMSE(1,file, cards, isUpdate);
else
{
int c=cards.Length;
int nums=c/mseHelper.MaxNum;
if(nums*mseHelper.MaxNum<c)
nums++;
List<Card> clist=new List<Card>();
for(int i=0;i<nums;i++)
{
clist.Clear();
for(int j=0;j<mseHelper.MaxNum;j++)
{
int index=i*mseHelper.MaxNum+j;
if(index<c)
clist.Add(cards[index]);
}
int t=file.LastIndexOf(".mse-set");
string fname=(t>0)?file.Substring(0,t):file;
fname=fname+string.Format("_{0}.mse-set",i+1);
SaveMSE(i+1,fname,clist.ToArray(),isUpdate);
}
}
}
public void SaveMSE(int num,string file, Card[] cards,bool isUpdate){
string setFile=file+".txt";
string[] images=mseHelper.WriteSet(setFile, cards);
if(isUpdate)//仅更新文字
return;
int i=0;
int count=images.Length;
using(ZipStorer zips=ZipStorer.Create(file, ""))
{
zips.EncodeUTF8=true;
zips.AddFile(setFile,"set","");
foreach ( string img in images )
{
if(isCancel)
break;
i++;
worker.ReportProgress(i/count, string.Format("{0}/{1}-{2}",i,count,num));
zips.AddFile(img, Path.GetFileName(img),"");
}
}
File.Delete(setFile);
}
public void ExportData(string zipname)
{
int i=0;
Card[] cards=cardlist;
if(cards == null || cards.Length == 0)
return;
int count=cards.Length;
string path=Path.GetDirectoryName(zipname);
string name=Path.GetFileNameWithoutExtension(zipname);
string cdbfile=zipname+".cdb";
string readme=MyPath.Combine(path, name+".txt");
string deckydk=MyPath.Combine(path, "deck/"+name+".ydk");
string pics=MyPath.Combine(path,"pics");
string thumb=MyPath.Combine(pics,"thumbnail");
string script=MyPath.Combine(path,"script");
File.Delete(cdbfile);
DataBase.Create(cdbfile);
DataBase.CopyDB(cdbfile,false,cardlist);
if(File.Exists(zipname)) #region 裁剪图片
File.Delete(zipname); public void CutImages(string imgpath, bool isreplace)
using(ZipStorer zips=ZipStorer.Create(zipname, "")) {
{ int count = cardlist.Length;
zips.AddFile(cdbfile, name+".cdb",""); int i = 0;
if(File.Exists(readme)) foreach (Card c in cardlist)
zips.AddFile(readme, "readme_"+name+".txt",""); {
if(File.Exists(deckydk)) if (isCancel)
zips.AddFile(deckydk, "deck/"+name+".ydk",""); break;
foreach(Card c in cards) i++;
{ worker.ReportProgress((i / count), string.Format("{0}/{1}", i, count));
i++; string jpg = MyPath.Combine(imgpath, c.id + ".jpg");
worker.ReportProgress(i/count, string.Format("{0}/{1}",i,count)); string savejpg = MyPath.Combine(mseHelper.ImagePath, c.id + ".jpg");
//zips.AddFile( if (File.Exists(jpg) && (isreplace || !File.Exists(savejpg)))
string jpg1=MyPath.Combine(pics, c.id.ToString()+".jpg"); {
string jpg2=MyPath.Combine(thumb, c.id.ToString()+".jpg"); Bitmap bp = new Bitmap(jpg);
string lua=MyPath.Combine(script, "c"+c.id.ToString()+".lua"); Bitmap bmp = null;
if (c.IsType(CardType.TYPE_XYZ))
if(File.Exists(jpg1)) {
zips.AddFile(jpg1,"pics/"+c.id.ToString()+".jpg",""); bmp = MyBitmap.Cut(bp, imgSet.xyzArea);
if(File.Exists(jpg2)) }
zips.AddFile(jpg2,"pics/thumbnail/"+c.id.ToString()+".jpg",""); else if (c.IsType(CardType.TYPE_PENDULUM))
if(File.Exists(lua)) {
zips.AddFile(lua,"script/c"+c.id.ToString()+".lua",""); bmp = MyBitmap.Cut(bp, imgSet.pendulumArea);
} }
} else
{
bmp = MyBitmap.Cut(bp, imgSet.normalArea);
}
MyBitmap.SaveAsJPEG(bmp, savejpg, imgSet.quilty);
//bmp.Save(savejpg, ImageFormat.Png);
}
}
}
#endregion
#region 转换图片
public void ConvertImages(string imgpath, string gamepath, bool isreplace)
{
string picspath = MyPath.Combine(gamepath, "pics");
string thubpath = MyPath.Combine(picspath, "thumbnail");
string[] files = Directory.GetFiles(imgpath);
int i = 0;
int count = files.Length;
foreach (string f in files)
{
if (isCancel)
break;
i++;
worker.ReportProgress(i / count, string.Format("{0}/{1}", i, count));
string ex = Path.GetExtension(f).ToLower();
string name = Path.GetFileNameWithoutExtension(f);
string jpg_b = MyPath.Combine(picspath, name + ".jpg");
string jpg_s = MyPath.Combine(thubpath, name + ".jpg");
if (ex == ".jpg" || ex == ".png" || ex == ".bmp")
{
if (File.Exists(f))
{
//存在大图
Bitmap bmp = new Bitmap(f);
if (isreplace || !File.Exists(jpg_b))
{
MyBitmap.SaveAsJPEG(MyBitmap.Zoom(bmp, imgSet.W, imgSet.H),
jpg_b, imgSet.quilty);
}
if (isreplace || !File.Exists(jpg_s))
{
MyBitmap.SaveAsJPEG(MyBitmap.Zoom(bmp, imgSet.w, imgSet.h),
jpg_s, imgSet.quilty);
}
}
}
}
}
#endregion
#region MSE存档
public string MSEImage
{
get { return mseHelper.ImagePath; }
}
public void SaveMSEs(string file, Card[] cards, bool isUpdate)
{
if (mseHelper.MaxNum == 0)
SaveMSE(1, file, cards, isUpdate);
else
{
int c = cards.Length;
int nums = c / mseHelper.MaxNum;
if (nums * mseHelper.MaxNum < c)
nums++;
List<Card> clist = new List<Card>();
for (int i = 0; i < nums; i++)
{
clist.Clear();
for (int j = 0; j < mseHelper.MaxNum; j++)
{
int index = i * mseHelper.MaxNum + j;
if (index < c)
clist.Add(cards[index]);
}
int t = file.LastIndexOf(".mse-set");
string fname = (t > 0) ? file.Substring(0, t) : file;
fname = fname + string.Format("_{0}.mse-set", i + 1);
SaveMSE(i + 1, fname, clist.ToArray(), isUpdate);
}
}
}
public void SaveMSE(int num, string file, Card[] cards, bool isUpdate)
{
string setFile = file + ".txt";
string[] images = mseHelper.WriteSet(setFile, cards);
if (isUpdate)//仅更新文字
return;
int i = 0;
int count = images.Length;
using (ZipStorer zips = ZipStorer.Create(file, ""))
{
zips.EncodeUTF8 = true;
zips.AddFile(setFile, "set", "");
foreach (string img in images)
{
if (isCancel)
break;
i++;
worker.ReportProgress(i / count, string.Format("{0}/{1}-{2}", i, count, num));
zips.AddFile(img, Path.GetFileName(img), "");
}
}
File.Delete(setFile);
}
#endregion
#region 导出数据
public void ExportData(string zipname)
{
int i = 0;
Card[] cards = cardlist;
if (cards == null || cards.Length == 0)
return;
int count = cards.Length;
string path = Path.GetDirectoryName(zipname);
string name = Path.GetFileNameWithoutExtension(zipname);
string cdbfile = zipname + ".cdb";
string readme = MyPath.Combine(path, name + ".txt");
string deckydk = MyPath.Combine(path, "deck/" + name + ".ydk");
string pics = MyPath.Combine(path, "pics");
string thumb = MyPath.Combine(pics, "thumbnail");
string script = MyPath.Combine(path, "script");
File.Delete(cdbfile);
DataBase.Create(cdbfile);
DataBase.CopyDB(cdbfile, false, cardlist);
if (File.Exists(zipname))
File.Delete(zipname);
using (ZipStorer zips = ZipStorer.Create(zipname, ""))
{
zips.AddFile(cdbfile, name + ".cdb", "");
if (File.Exists(readme))
zips.AddFile(readme, "readme_" + name + ".txt", "");
if (File.Exists(deckydk))
zips.AddFile(deckydk, "deck/" + name + ".ydk", "");
foreach (Card c in cards)
{
i++;
worker.ReportProgress(i / count, string.Format("{0}/{1}", i, count));
//zips.AddFile(
string jpg1 = MyPath.Combine(pics, c.id.ToString() + ".jpg");
string jpg2 = MyPath.Combine(thumb, c.id.ToString() + ".jpg");
string lua = MyPath.Combine(script, "c" + c.id.ToString() + ".lua");
if (File.Exists(jpg1))
zips.AddFile(jpg1, "pics/" + c.id.ToString() + ".jpg", "");
if (File.Exists(jpg2))
zips.AddFile(jpg2, "pics/thumbnail/" + c.id.ToString() + ".jpg", "");
if (File.Exists(lua))
zips.AddFile(lua, "script/c" + c.id.ToString() + ".lua", "");
}
}
File.Delete(cdbfile); File.Delete(cdbfile);
} }
#endregion
public void Run(){
isCancel=false; #region 运行
isRun=true; public void Run()
bool replace; {
bool showNew; isCancel = false;
switch(nowTask){ isRun = true;
case MyTask.ExportData: bool replace;
if(mArgs!=null && mArgs.Length>=1){ bool showNew;
ExportData(mArgs[0]); switch (nowTask)
} {
break; case MyTask.ExportData:
case MyTask.CheckUpdate: if (mArgs != null && mArgs.Length >= 1)
showNew=false; {
if(mArgs!=null && mArgs.Length>=1){ ExportData(mArgs[0]);
showNew=(mArgs[0]==Boolean.TrueString)?true:false; }
} break;
OnCheckUpdate(showNew); case MyTask.CheckUpdate:
break; showNew = false;
case MyTask.CutImages: if (mArgs != null && mArgs.Length >= 1)
if(mArgs!=null && mArgs.Length>=2){ {
replace=true; showNew = (mArgs[0] == Boolean.TrueString) ? true : false;
if(mArgs.Length>=2){ }
if(mArgs[1]==Boolean.FalseString) OnCheckUpdate(showNew);
replace=false; break;
} case MyTask.CutImages:
CutImages(mArgs[0],replace); if (mArgs != null && mArgs.Length >= 2)
} {
break; replace = true;
case MyTask.SaveAsMSE: if (mArgs.Length >= 2)
if(mArgs!=null && mArgs.Length>=2){ {
replace=false; if (mArgs[1] == Boolean.FalseString)
if(mArgs.Length>=2){ replace = false;
if(mArgs[1]==Boolean.TrueString) }
replace=true; CutImages(mArgs[0], replace);
} }
SaveMSEs(mArgs[0], cardlist, replace); break;
} case MyTask.SaveAsMSE:
break; if (mArgs != null && mArgs.Length >= 2)
case MyTask.ConvertImages: {
if(mArgs!=null && mArgs.Length>=2){ replace = false;
replace=true; if (mArgs.Length >= 2)
if(mArgs.Length>=3){ {
if(mArgs[2]==Boolean.FalseString) if (mArgs[1] == Boolean.TrueString)
replace=false; replace = true;
} }
ConvertImages(mArgs[0],mArgs[1],replace); SaveMSEs(mArgs[0], cardlist, replace);
} }
break; break;
} case MyTask.ConvertImages:
isRun=false; if (mArgs != null && mArgs.Length >= 2)
lastTask=nowTask; {
nowTask=MyTask.NONE; replace = true;
cardlist=null; if (mArgs.Length >= 3)
mArgs=null; {
} if (mArgs[2] == Boolean.FalseString)
} replace = false;
}
ConvertImages(mArgs[0], mArgs[1], replace);
}
break;
}
isRun = false;
lastTask = nowTask;
nowTask = MyTask.NONE;
cardlist = 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