• R/O
  • SSH
  • HTTPS

ewatch: Commit


Commit MetaInfo

Revisão38 (tree)
Hora2017-08-08 14:56:17
Autorbananajinn

Mensagem de Log

ファイル監視のSJIS対応

Mudança Sumário

Diff

--- trunk/EWatch/EWatch/Utils/FileAndEncoding.cs (nonexistent)
+++ trunk/EWatch/EWatch/Utils/FileAndEncoding.cs (revision 38)
@@ -0,0 +1,40 @@
1+/*
2+ * Created by SharpDevelop.
3+ * User: banana
4+ * Date: 2017/08/08
5+ * Time: 13:59
6+ *
7+ * To change this template use Tools | Options | Coding | Edit Standard Headers.
8+ */
9+using System;
10+using System.Text;
11+using System.Text.RegularExpressions;
12+
13+namespace EWatch.Utils
14+{
15+ /// <summary>
16+ /// ファイル名とエンコーディングを保持します。
17+ /// </summary>
18+ public class FileAndEncoding
19+ {
20+ public string File { get; set; }
21+ public Encoding Encoding { get; set; }
22+
23+ public FileAndEncoding()
24+ {
25+ Encoding = Encoding.UTF8;
26+ }
27+
28+ public static FileAndEncoding Parse(string line)
29+ {
30+ var result = new FileAndEncoding();
31+ result.File = line;
32+ var match = Regex.Match(line, "^(\\[([0-9]+)\\])?(.*)$");
33+ if(match.Success && !string.IsNullOrEmpty(match.Groups[2].Value)){
34+ result.Encoding = Encoding.GetEncoding(int.Parse(match.Groups[2].Value));
35+ result.File = match.Groups[3].Value;
36+ }
37+ return result;
38+ }
39+ }
40+}
--- trunk/EWatch/EWatch/Watchers/WatchThread.cs (revision 37)
+++ trunk/EWatch/EWatch/Watchers/WatchThread.cs (revision 38)
@@ -9,8 +9,10 @@
99 using System;
1010 using System.Collections.Generic;
1111 using System.Text;
12+using System.Text.RegularExpressions;
1213 using System.Threading;
1314 using EWatch.Models.Configurations;
15+using EWatch.Utils;
1416
1517 namespace EWatch.Watchers
1618 {
@@ -79,7 +81,8 @@
7981 }
8082 Dictionary<string,List<ActionTable>> files = config.File;
8183 foreach(string path in files.Keys){
82- BaseWatcher watcher = new FileWatcher(path, Encoding.UTF8, files[path]);
84+ var fileAndEncoding = FileAndEncoding.Parse(path);
85+ BaseWatcher watcher = new FileWatcher(fileAndEncoding.File, fileAndEncoding.Encoding, files[path]);
8386 watchers.Add(watcher);
8487 }
8588 Dictionary<string,List<ActionTable>> syslogs = config.Syslog;
--- trunk/EWatch/EWatchUI/FormRuleEdit.Designer.cs (revision 37)
+++ trunk/EWatch/EWatchUI/FormRuleEdit.Designer.cs (revision 38)
@@ -64,6 +64,7 @@
6464 this.textBoxSource = new System.Windows.Forms.TextBox();
6565 this.textBoxEventID = new System.Windows.Forms.TextBox();
6666 this.label11 = new System.Windows.Forms.Label();
67+ this.checkBoxShiftJIS = new System.Windows.Forms.CheckBox();
6768 this.SuspendLayout();
6869 //
6970 // label1
@@ -301,6 +302,15 @@
301302 this.label11.TabIndex = 7;
302303 this.label11.Text = "Event ID";
303304 //
305+ // checkBoxShiftJIS
306+ //
307+ this.checkBoxShiftJIS.Location = new System.Drawing.Point(380, 33);
308+ this.checkBoxShiftJIS.Name = "checkBoxShiftJIS";
309+ this.checkBoxShiftJIS.Size = new System.Drawing.Size(76, 24);
310+ this.checkBoxShiftJIS.TabIndex = 25;
311+ this.checkBoxShiftJIS.Text = "ShiftJIS";
312+ this.checkBoxShiftJIS.UseVisualStyleBackColor = true;
313+ //
304314 // FormRuleEdit
305315 //
306316 this.AcceptButton = this.buttonOK;
@@ -308,6 +318,7 @@
308318 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
309319 this.CancelButton = this.buttonCancel;
310320 this.ClientSize = new System.Drawing.Size(468, 343);
321+ this.Controls.Add(this.checkBoxShiftJIS);
311322 this.Controls.Add(this.textBoxEventID);
312323 this.Controls.Add(this.label11);
313324 this.Controls.Add(this.textBoxSource);
@@ -371,5 +382,6 @@
371382 private System.Windows.Forms.Button buttonRef;
372383 private System.Windows.Forms.ComboBox comboBoxTarget;
373384 private System.Windows.Forms.Label label1;
385+ private System.Windows.Forms.CheckBox checkBoxShiftJIS;
374386 }
375387 }
--- trunk/EWatch/EWatchUI/FormRuleEdit.cs (revision 37)
+++ trunk/EWatch/EWatchUI/FormRuleEdit.cs (revision 38)
@@ -9,7 +9,9 @@
99 using System;
1010 using System.Collections.Generic;
1111 using System.Drawing;
12+using System.Linq;
1213 using System.Text;
14+using System.Text.RegularExpressions;
1315 using System.Windows.Forms;
1416 using EWatch.Actions;
1517 using EWatch.Models.Configurations;
@@ -42,6 +44,7 @@
4244
4345 void FormRuleEditLoad(object sender, EventArgs e)
4446 {
47+ checkBoxShiftJIS.Visible = Type == WatchType.File;
4548 switch (Type) {
4649 case WatchType.EventLog:
4750 SetDataForEventLog();
@@ -116,7 +119,8 @@
116119 private void SetDataForFile()
117120 {
118121 comboBoxTarget.Items.Clear();
119- comboBoxTarget.Items.AddRange(TargetValues);
122+ comboBoxTarget.Items.AddRange(TargetValues.Select(
123+ x => FileAndEncoding.Parse(x).File).ToArray());
120124 buttonRef.Visible = true;
121125
122126 comboBoxLogLevel.Enabled = false;
@@ -124,7 +128,9 @@
124128 textBoxEventID.Enabled = false;
125129
126130 if(Table != null){
127- comboBoxTarget.Text = Target;
131+ var fe = FileAndEncoding.Parse(Target);
132+ comboBoxTarget.Text = fe.File;
133+ checkBoxShiftJIS.Checked = fe.Encoding.CodePage == 932;
128134 textBoxHostname.Text = Table.HostName;
129135 textBoxMatch.Text = Table.MatchPattern;
130136 textBoxIgnore.Text = Table.IgnorePattern;
@@ -156,9 +162,18 @@
156162 Close();
157163 }
158164
165+ private string GetTarget()
166+ {
167+ var result = comboBoxTarget.Text;
168+ if(Type == WatchType.File && checkBoxShiftJIS.Checked){
169+ result = string.Format("[{0}]{1}", 932, result);
170+ }
171+ return result;
172+ }
173+
159174 private void GetData()
160175 {
161- Target = comboBoxTarget.Text;
176+ Target = GetTarget();
162177 if(comboBoxLogLevel.Enabled){
163178 Table.LogLevel = comboBoxLogLevel.Text;
164179 }
--- trunk/EWatch/EWatchUI/MainForm.cs (revision 37)
+++ trunk/EWatch/EWatchUI/MainForm.cs (revision 38)
@@ -171,9 +171,13 @@
171171 if(item != null){
172172 FormRuleEdit form = new FormRuleEdit();
173173 SetFormRuleEditData(form, item);
174+ var originalTarget = form.Target;
174175 if(form.ShowDialog() == DialogResult.OK){
175- List<ActionTable> tables = GetActionTableList(GetCurrentActionDictionary(), form.Target);
176+ var actionDic = GetCurrentActionDictionary();
177+ List<ActionTable> tables = GetActionTableList(actionDic, originalTarget);
176178 tables[(int)item.Tag] = form.Table;
179+ actionDic.Remove(originalTarget);
180+ actionDic.Add(form.Target, tables);
177181 SetListItems();
178182 Dirty = true;
179183 }
Show on old repository browser