• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

OmegaChartのソースコードの保守


コミットメタ情報

リビジョン6a0f24711d7f1c7c2198152e3d54d334623a3821 (tree)
日時2016-04-16 17:17:38
作者panacoran <panacoran@user...>
コミッターpanacoran

ログメッセージ

再起動せずにindex.txtを更新できるようにする

https://osdn.jp/users/panacoran/pastebin/3210

変更サマリ

差分

--- a/Command.cs
+++ b/Command.cs
@@ -1058,28 +1058,9 @@ namespace Zanetti.Commands {
10581058 #endif
10591059 }
10601060 public static CommandResult DownloadIndexFile() {
1061- MemoryStream ns = null;
1062- try {
1063- ns = Util.HttpDownload("http://protra.sourceforge.jp/data/index.txt");
1064- int dt = BrandCollection.GuessDate(ns);
1065- ns.Position = 0;
1066- if(dt > Env.BrandCollection.LastUpdatedDate) {
1067- Util.Information(Env.Frame, "新しいインデックスファイルが見つかりました。反映させるにはOmegaChartの再起動が必要です。");
1068- Util.StreamToFile(ns, Env.GetAppDir() + "index.txt");
1069- return CommandResult.Succeeded;
1070- }
1071- else {
1072- Util.Information(Env.Frame, "新しいインデックスファイルはありません。");
1073- return CommandResult.Ignored;
1074- }
1075- }
1076- catch(Exception ex) {
1077- Util.ReportCriticalError(ex);
1078- return CommandResult.Failed;
1079- }
1080- finally {
1081- if(ns!=null) ns.Close();
1082- }
1061+ using (var dlg = new DownloadIndexFileDialog())
1062+ dlg.ShowDialog();
1063+ return CommandResult.Succeeded;
10831064 }
10841065
10851066 #if DOJIMA
--- /dev/null
+++ b/DownloadIndexFileDialog.cs
@@ -0,0 +1,187 @@
1+using System;
2+using System.IO;
3+using System.Text;
4+using System.Windows.Forms;
5+
6+namespace Zanetti.Data
7+{
8+ public class DownloadIndexFileDialog : Form
9+ {
10+ /// <summary>
11+ /// Required designer variable.
12+ /// </summary>
13+ private System.ComponentModel.IContainer components = null;
14+
15+ /// <summary>
16+ /// Clean up any resources being used.
17+ /// </summary>
18+ /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
19+ protected override void Dispose(bool disposing)
20+ {
21+ if (disposing && (components != null))
22+ {
23+ components.Dispose();
24+ }
25+ base.Dispose(disposing);
26+ }
27+
28+ #region Windows Form Designer generated code
29+
30+ /// <summary>
31+ /// Required method for Designer support - do not modify
32+ /// the contents of this method with the code editor.
33+ /// </summary>
34+ private void InitializeComponent()
35+ {
36+ this.toolStrip1 = new System.Windows.Forms.ToolStrip();
37+ this.btnClose = new System.Windows.Forms.ToolStripButton();
38+ this.label = new System.Windows.Forms.ToolStripLabel();
39+ this.textBox1 = new System.Windows.Forms.TextBox();
40+ this.toolStrip1.SuspendLayout();
41+ this.SuspendLayout();
42+ //
43+ // toolStrip1
44+ //
45+ this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
46+ this.btnClose,
47+ this.label});
48+ this.toolStrip1.Location = new System.Drawing.Point(0, 0);
49+ this.toolStrip1.Name = "toolStrip1";
50+ this.toolStrip1.Size = new System.Drawing.Size(344, 25);
51+ this.toolStrip1.TabIndex = 0;
52+ this.toolStrip1.Text = "toolStrip1";
53+ //
54+ // btnClose
55+ //
56+ this.btnClose.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
57+ this.btnClose.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
58+ this.btnClose.Name = "btnClose";
59+ this.btnClose.Size = new System.Drawing.Size(48, 22);
60+ this.btnClose.Text = "閉じる";
61+ this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
62+ //
63+ // label
64+ //
65+ this.label.Name = "label";
66+ this.label.Size = new System.Drawing.Size(304, 18);
67+ this.label.Text = "OSDNにアクセスしています。お待ちください。";
68+ //
69+ // textBox1
70+ //
71+ this.textBox1.Dock = System.Windows.Forms.DockStyle.Fill;
72+ this.textBox1.Location = new System.Drawing.Point(0, 25);
73+ this.textBox1.Multiline = true;
74+ this.textBox1.Name = "textBox1";
75+ this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Both;
76+ this.textBox1.Size = new System.Drawing.Size(344, 1);
77+ this.textBox1.TabIndex = 1;
78+ //
79+ // DownloadIndexFileDialog
80+ //
81+ this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
82+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
83+ this.ClientSize = new System.Drawing.Size(344, 26);
84+ this.Controls.Add(this.textBox1);
85+ this.Controls.Add(this.toolStrip1);
86+ this.Name = "DownloadIndexFileDialog";
87+ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
88+ this.Text = "Index.txt";
89+ this.Shown += new System.EventHandler(this.BrandIndex_Shown);
90+ this.toolStrip1.ResumeLayout(false);
91+ this.toolStrip1.PerformLayout();
92+ this.ResumeLayout(false);
93+ this.PerformLayout();
94+
95+ }
96+
97+ #endregion
98+
99+ private System.Windows.Forms.ToolStrip toolStrip1;
100+ private System.Windows.Forms.ToolStripButton btnClose;
101+ private System.Windows.Forms.ToolStripLabel label;
102+ private System.Windows.Forms.TextBox textBox1;
103+
104+ public DownloadIndexFileDialog()
105+ {
106+ InitializeComponent();
107+ }
108+
109+ private void btnClose_Click(object sender, EventArgs e)
110+ {
111+ this.Close();
112+ }
113+
114+ private void BrandIndex_Shown(object sender, EventArgs e)
115+ {
116+ this.btnClose.Enabled = false;
117+ MemoryStream ms = null;
118+ try
119+ {
120+ Env.Frame.Cursor = Cursors.WaitCursor;
121+ ms = Util.HttpDownload("http://protra.osdn.jp/data/index.txt");
122+ int dt = BrandCollection.GuessDate(ms);
123+ ms.Position = 0;
124+ if (dt > Env.BrandCollection.LastUpdatedDate)
125+ {
126+ System.Collections.Generic.Dictionary<int, string> dic_org = new System.Collections.Generic.Dictionary<int, string>();
127+ string[] lines = File.ReadAllLines(Env.GetAppDir() + "index.txt", Encoding.Default);
128+ foreach (string line in lines)
129+ {
130+ string[] cols = line.Split(',');
131+ int code = 0;
132+ if (int.TryParse(cols[0], out code))
133+ dic_org.Add(code, line);
134+ }
135+ label.Text = "新しいインデックスファイルをダウンロードしました。";
136+ this.Width = 520;
137+ this.Height = 400;
138+ Util.StreamToFile(ms, Env.GetAppDir() + "index.txt");
139+ StringBuilder sb = new StringBuilder();
140+ ms.Seek(0, SeekOrigin.Begin);
141+ TextReader tr = new StreamReader(ms, Encoding.Default);
142+ while (tr.Peek() >= 0)
143+ {
144+ string line = tr.ReadLine();
145+ string[] cols = line.Split(',');
146+ int code = 0;
147+ if (int.TryParse(cols[0], out code))
148+ {
149+ if (!dic_org.ContainsKey(code))
150+ sb.AppendLine("新規銘柄:" + line);
151+ else
152+ {
153+ if (dic_org[code] != line)
154+ {
155+ sb.AppendLine("変更 :" + line);
156+ sb.AppendLine(" 旧:" + dic_org[code]);
157+ }
158+ }
159+ }
160+ } //これを利用する手もあり
161+ textBox1.Text = sb.ToString();
162+ this.Refresh();
163+ //MessageBox.Show(sb.ToString(), "新しいindex.txt");
164+ dic_org.Clear();
165+ Env.BrandCollection.Load(Env.GetAppDir() + "index.txt"); //そのまま更新
166+ if (File.Exists(Env.GetAppDir() + "index_append.txt"))
167+ Env.BrandCollection.Load(Env.GetAppDir() + "index_append.txt");
168+ Env.Frame.Cursor = Cursors.Default;
169+ label.Text = "銘柄情報が更新されました。";
170+ }
171+ else
172+ {
173+ label.Text = "新しいインデックスファイルはありません。";
174+ }
175+ }
176+ catch (Exception ex)
177+ {
178+ Util.ReportCriticalError(ex);
179+ }
180+ finally
181+ {
182+ if (ms != null) ms.Close();
183+ this.btnClose.Enabled = true;
184+ }
185+ }
186+ }
187+}
\ No newline at end of file
--- a/Util.cs
+++ b/Util.cs
@@ -141,8 +141,8 @@ namespace Zanetti
141141 }
142142 }
143143 public static void StreamToFile(Stream input, string filename) {
144- FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write);
145- CopyStream(input, fs);
144+ using (FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.Write))
145+ CopyStream(input, fs);
146146 }
147147
148148 //COLORREFに対応した整数を返す
--- a/zanetti.csproj
+++ b/zanetti.csproj
@@ -125,6 +125,9 @@
125125 <Compile Include="Download.cs">
126126 <SubType>Form</SubType>
127127 </Compile>
128+ <Compile Include="DownloadIndexFileDialog.cs">
129+ <SubType>Form</SubType>
130+ </Compile>
128131 <Compile Include="DownloadOrder.cs" />
129132 <Compile Include="DreamVisor.cs" />
130133 <Compile Include="Edatalab.cs" />