2 //TODO:フェイドアウト フェイドインで処理中のバーを表示する。
3 //TODO:処理ファイルをバックグラウンドに流せないか
4 //TODO:コンソールアプリ、WEBアプリを作成したい
6 using System.Collections.Generic;
10 using System.Windows.Controls;
11 using System.Windows.Data;
12 using System.Windows.Documents;
13 using System.Windows.Input;
14 using System.Windows.Media;
15 using System.Windows.Media.Imaging;
16 using System.Windows.Navigation;
17 using System.Windows.Shapes;
20 namespace FileNameChenger
23 /// WindowMain.xaml の相互作用ロジック
25 public partial class WindowMain : Window
27 const string RunText = "変換実行";
28 const string CancelText = "中断";
30 //FileNameChengerCore.EStateFlg eStateFlg = FileNameChengerCore.EStateFlg.Non;
32 System.Windows.Forms.Timer stateTimer = null;
33 FileNameChengerCore.CFileCopy cFileCopy = null;
34 FileNameChengerCore.CConfig cConfig = null;
38 InitializeComponent();
40 progressBarWork.Opacity = 0;
41 //imageWork.Opacity = 0.25;
42 imageWork.Opacity = 0.0;
44 //progressBarWork.Visibility = Visibility.Hidden;
45 //imageWork.Visibility = Visibility.Hidden;
47 //btnStoryboard.Storyboard.Completed += new EventHandler(Storyboard_Completed);
49 stateTimer = new System.Windows.Forms.Timer();
50 stateTimer.Interval = 100;
51 stateTimer.Tick += new EventHandler(stateTimer_Tick);
54 cConfig = new FileNameChengerCore.CConfig(FileNameChenger.Properties.Resources.ConfigFileName);
57 textBoxFrom.Text = cConfig.FileNameFrom;
58 textBoxTo.Text = cConfig.FileNameTo;
61 bool IsWidthUp = false;
62 private void labelSetup_MouseEnter(object sender, MouseEventArgs e)
74 IsWidthUp = !IsWidthUp;
79 private void setImage()
81 string dir = @".\img";
83 if (!Directory.Exists(dir))
85 Directory.CreateDirectory(dir);
88 string[] files = Directory.GetFiles(dir, "*.jpg", SearchOption.AllDirectories);
91 BitmapImage myBitmapImage = new BitmapImage();
93 if (files.Length == 0)
95 myBitmapImage.BeginInit();
96 myBitmapImage.UriSource = new Uri(@"FileNameChenger.ico", UriKind.RelativeOrAbsolute);
97 myBitmapImage.EndInit();
101 Random r = new Random();
102 int index = r.Next(files.Length - 1);
103 myBitmapImage.BeginInit();
104 myBitmapImage.UriSource = new Uri(@"file://" + Directory.GetCurrentDirectory() + files[index], UriKind.RelativeOrAbsolute);
105 myBitmapImage.EndInit();
108 imageWork.Source = myBitmapImage;
113 private void buttonRun_Click(object sender, RoutedEventArgs e)
118 case FileNameChengerCore.EStateFlg.Non:
119 buttonRun.Content = RunText;
121 case FileNameChengerCore.EStateFlg.Run:
122 buttonRun.Content = CancelText;
124 case FileNameChengerCore.EStateFlg.End:
125 case FileNameChengerCore.EStateFlg.Cancel:
126 buttonRun.Content = RunText;
134 //WorkView view = new WorkView();
145 labelFrom.Visibility = Visibility.Visible;
146 labelTo.Visibility = Visibility.Visible;
147 textBoxFrom.Visibility = Visibility.Visible;
148 textBoxTo.Visibility = Visibility.Visible;
151 //checkBoxViewControl_Run.IsChecked = !checkBoxViewControl_Run.IsChecked;
153 if (cFileCopy != null)
158 buttonRun.Content = RunText;
159 Title = FileNameChenger.Properties.Resources.Title;
164 progressBarWork.Visibility = Visibility.Visible;
165 imageWork.Visibility = Visibility.Visible;
168 //checkBoxViewControl.IsChecked = !checkBoxViewControl.IsChecked;
170 cFileCopy = new FileNameChengerCore.CFileCopy(
171 textBoxFrom.Text, textBoxTo.Text, cConfig.SerchPattern, cConfig.FileNamePattern);
172 if (cFileCopy.Count > 0)
175 buttonRun.Content = CancelText;
176 if (cFileCopy.FreeSpace)
178 labelNonFreeSpace.Visibility = Visibility.Hidden;
182 labelNonFreeSpace.Visibility = Visibility.Visible;
185 workingImage.Angle = 0;
187 progressBarWork.Minimum = 0;
188 progressBarWork.Maximum = cFileCopy.Count;
189 progressBarWork.Value = 0;
191 cFileCopy.DoWorkEndEvent += new EventHandler<EventArgs>(cFileCopy_DoWorkEndEvent);
192 cFileCopy.DoWorkingEvent += new EventHandler<FileNameChengerCore.DoWorkingEventArgs>(cFileCopy_DoWorkingEvent);
206 //btnStoryboard.Storyboard.Begin(this);
209 List<string> files = new List<string>();
210 void cFileCopy_DoWorkingEvent(object sender, FileNameChengerCore.DoWorkingEventArgs e)
212 //throw new NotImplementedException();
215 files.Add(e.FileNameFrom + "→" + e.FileNameTo);
221 void cFileCopy_DoWorkEndEvent(object sender, EventArgs e)
223 //throw new NotImplementedException();
224 //buttonRun.Content = CancelText;
231 void stateTimer_Tick(object sender, EventArgs e)
233 //throw new NotImplementedException();
234 Title = FileNameChenger.Properties.Resources.Title
235 + "(" + state.ToString() + "/" + progressBarWork.Maximum.ToString() + ")";
244 Title = FileNameChenger.Properties.Resources.Title;
253 if (workingImage.Angle >= 360)
255 workingImage.Angle = 0;
260 workingImage.Angle++;
265 lock (progressBarWork)
267 if (progressBarWork.Opacity <= 1)
269 progressBarWork.Opacity += 0.1;
271 progressBarWork.Value = state;
273 if (imageWork.Opacity <= 1)
275 imageWork.Opacity += 0.1;
280 if (labelFrom.Opacity >= 0)
282 labelFrom.Opacity -= 0.1;
284 if (labelTo.Opacity >= 0)
286 labelTo.Opacity -= 0.1;
288 if (textBoxFrom.Opacity >= 0)
290 textBoxFrom.Opacity -= 0.1;
292 if (textBoxTo.Opacity >= 0)
294 textBoxTo.Opacity -= 0.1;
299 buttonRun.Content = RunText;
303 if (progressBarWork.Opacity >= 0)
305 progressBarWork.Opacity -= 0.1;
307 if (imageWork.Opacity >= 0)
309 imageWork.Opacity -= 0.1;
313 if (labelFrom.Opacity <= 1)
315 labelFrom.Opacity += 0.1;
317 if (labelTo.Opacity <= 1)
319 labelTo.Opacity += 0.1;
321 if (textBoxFrom.Opacity <= 1)
323 textBoxFrom.Opacity += 0.1;
325 if (textBoxTo.Opacity <= 1)
327 textBoxTo.Opacity += 0.1;
331 if (labelTo.Opacity == 1)
340 void Storyboard_Completed(object sender, EventArgs e)
343 //throw new NotImplementedException();
345 daLabelFrom.From = labelFrom.Opacity;
346 daLabelTo.From = labelTo.Opacity;
347 daTextBoxFrom.From = textBoxFrom.Opacity;
348 daTextBoxTo.From = textBoxTo.Opacity;
349 daButtonFrom.From = buttonFrom.Opacity;
350 daButtonTo.From = buttonTo.Opacity;
352 daProgressBarWork.From = progressBarWork.Opacity;
353 daImageWork.From = imageWork.Opacity;
357 labelFrom.Visibility = Visibility.Hidden;
358 labelTo.Visibility = Visibility.Hidden;
359 textBoxFrom.Visibility = Visibility.Hidden;
360 textBoxTo.Visibility = Visibility.Hidden;
365 daTextBoxFrom.To = 1;
370 daProgressBarWork.To = 0;
376 progressBarWork.Visibility = Visibility.Hidden;
377 imageWork.Visibility = Visibility.Hidden;
381 daTextBoxFrom.To = 0;
386 daProgressBarWork.To = 1;
392 private void Window_Unloaded(object sender, RoutedEventArgs e)
396 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
398 if (cFileCopy != null)
403 cConfig.FileNameFrom = textBoxFrom.Text;
404 cConfig.FileNameTo = textBoxTo.Text;
408 private void Grid_DragEnter(object sender, DragEventArgs e)
410 if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop)
411 || e.Data.GetDataPresent(System.Windows.DataFormats.Text)
412 || e.Data.GetDataPresent(System.Windows.DataFormats.UnicodeText))
414 e.Effects = System.Windows.DragDropEffects.Copy;
419 private void Grid_Drop(object sender, DragEventArgs e)
421 // ファイルドロップした場合のみ処理
422 if (e.Data.GetDataPresent(DataFormats.FileDrop))
424 foreach (string fileName in (string[])e.Data.GetData(DataFormats.FileDrop))
426 Point p = e.GetPosition(this);
427 if (p.Y < (Height/2))
429 textBoxFrom.Text = fileName;
433 //TextBox textBox = (TextBox)sender;
434 //textBox.Text = fileName;
435 textBoxTo.Text = fileName;