- //現行の、DownloadIndexFileDialog.cs にある private void BrandIndex_Shown(object sender, EventArgs e)に下記内容を差し替え
- private void BrandIndex_Shown(object sender, EventArgs e)
- {
- this.btnClose.Enabled = false;
- MemoryStream ms = null;
- try
- {
- Env.Frame.Cursor = Cursors.WaitCursor;
- ms = Util.HttpDownload("http://protra.osdn.jp/data/index.txt");
- int dt = BrandCollection.GuessDate(ms);
- ms.Position = 0;
- if (dt > Env.BrandCollection.LastUpdatedDate)
- {
- System.Collections.Generic.Dictionary<int, string> dic_org = new System.Collections.Generic.Dictionary<int, string>();
- System.Collections.Generic.Dictionary<int, string> dic_dest = new System.Collections.Generic.Dictionary<int, string>();//☆この行、追加 ①
- string[] lines = File.ReadAllLines(Env.GetAppDir() + "index.txt", Encoding.Default);
- foreach (string line in lines)
- {
- string[] cols = line.Split(',');
- int code = 0;
- if (int.TryParse(cols[0], out code))
- dic_org.Add(code, line);
- }
- dic_dest = dic_org;//☆この行、追加 ②
- label.Text = "新しいインデックスファイルをダウンロードしました。";
- this.Width = 520;
- this.Height = 400;
- Util.StreamToFile(ms, Env.GetAppDir() + "index.txt");
- StringBuilder sb = new StringBuilder();
- ms.Seek(0, SeekOrigin.Begin);
- TextReader tr = new StreamReader(ms, Encoding.Default);
- while (tr.Peek() >= 0)
- {
- string line = tr.ReadLine();
- string[] cols = line.Split(',');
- int code = 0;
- if (int.TryParse(cols[0], out code))
- {
- if (!dic_org.ContainsKey(code))
- {//☆この{、追加 ③
- sb.AppendLine("新規銘柄:" + line);
- dic_dest.Add(code, line);//☆この行、追加 ④
- }//☆この}、追加 ⑤
- else
- {
- if (dic_org[code] != line)
- {
- sb.AppendLine("変更 :" + line);
- sb.AppendLine(" 旧:" + dic_org[code]);
- dic_dest[code] = line;//☆この行、追加 ⑥
- }
- }
- }
- } //これを利用する手もあり
- textBox1.Text = sb.ToString();
- this.Refresh();
- //MessageBox.Show(sb.ToString(), "新しいindex.txt");
- //dic_org.Clear();//☆この行、コメントアウト ⑦
- //Env.BrandCollection.Load(Env.GetAppDir() + "index.txt"); //そのまま更新 //☆この行、コメントアウト ⑧
- Env.BrandCollection.Load(dic_dest); //そのまま更新 //☆この行、追加 ⑨
- dic_org.Clear();//☆この行、追加 ⑩
- dic_dest.Clear();//☆この行、追加 ⑪
- if (File.Exists(Env.GetAppDir() + "index_append.txt"))
- Env.BrandCollection.Load(Env.GetAppDir() + "index_append.txt");
- Env.Frame.Cursor = Cursors.Default;
- label.Text = "銘柄情報が更新されました。";
- }
- else
- {
- label.Text = "新しいインデックスファイルはありません。";
- }
- }
- catch (Exception ex)
- {
- Util.ReportCriticalError(ex);
- }
- finally
- {
- if (ms != null) ms.Close();
- this.btnClose.Enabled = true;
- }
- }