@@ -81,6 +81,7 @@ public partial class Form1 :Form {
81
81
private Task backupTask ;
82
82
83
83
public Form1 ( ) {
84
+ logger . Info ( "Current Dir: " + System . Environment . CurrentDirectory ) ;
84
85
backupDataPath = AppConfig . BackupPath ;
85
86
this . ShowInTaskbar = false ;
86
87
this . Icon = new Icon ( ".\\ Image\\ app.ico" ) ;
@@ -92,16 +93,7 @@ public Form1() {
92
93
timer . Interval = 1000 ;
93
94
timer . Tick += new EventHandler ( Timer_Tick ) ;
94
95
95
- notifyIcon = new NotifyIcon ( ) ;
96
- notifyIcon . Icon = new Icon ( ".\\ Image\\ app_sub.ico" ) ;
97
- notifyIcon . Visible = true ;
98
- notifyIcon . Text = "MAB待機モジュール" ;
99
- ContextMenuStrip menu = new ContextMenuStrip ( ) ;
100
- ToolStripMenuItem exit = new ToolStripMenuItem ( ) ;
101
- exit . Text = "終了" ;
102
- exit . Click += new EventHandler ( Close_Click ) ;
103
- menu . Items . Add ( exit ) ;
104
- notifyIcon . ContextMenuStrip = menu ;
96
+ SetNotifyIconWait ( ) ;
105
97
}
106
98
107
99
private void Close_Click ( object sender , EventArgs e ) {
@@ -117,13 +109,13 @@ private void Close_Click(object sender, EventArgs e) {
117
109
Application . Exit ( ) ;
118
110
}
119
111
120
- void Form1_Closing ( object sender , EventArgs e ) {
112
+ private void Form1_Closing ( object sender , EventArgs e ) {
121
113
logger . Info ( "アプリケーションが強制終了しました" ) ;
122
114
notifyIcon . Visible = false ;
123
115
notifyIcon . Dispose ( ) ;
124
116
}
125
117
126
- void Timer_Tick ( object sender , EventArgs e ) {
118
+ private void Timer_Tick ( object sender , EventArgs e ) {
127
119
// lancherが起動してない場合 => 何もしない
128
120
// lancherが起動していてflagがfalse => flagをtrueにしてバックアップ動作
129
121
// lancherが起動していてflagがtrue => 何もしない
@@ -136,14 +128,7 @@ void Timer_Tick(object sender, EventArgs e) {
136
128
logger . Info ( "Minecraft Lancherの起動を検知しました" ) ;
137
129
logger . Info ( "isRunningがfalseに設定されていました" ) ;
138
130
139
- notifyIcon . Icon = new Icon ( ".\\ Image\\ app_sub_doing.ico" ) ;
140
- ContextMenuStrip menu = new ContextMenuStrip ( ) ;
141
- ToolStripMenuItem exit = new ToolStripMenuItem ( ) {
142
- Text = "強制終了" ,
143
- } ;
144
- exit . Click += new EventHandler ( Close_Click ) ;
145
- menu . Items . Add ( exit ) ;
146
- notifyIcon . ContextMenuStrip = menu ;
131
+ SetNotifyIconBackuping ( ) ;
147
132
backupTask = Task . Run ( ( ) => {
148
133
DoBackupProcess ( ) ;
149
134
} ) ;
@@ -155,25 +140,31 @@ void Timer_Tick(object sender, EventArgs e) {
155
140
}
156
141
}
157
142
143
+ private void bootMainForm_Click ( object sender , EventArgs e ) {
144
+ logger . Info ( System . Environment . CurrentDirectory ) ;
145
+
146
+ var mainForm = new ProcessStartInfo ( ) ;
147
+ mainForm . FileName = ".\\ Minecraft Auto Backup.exe" ;
148
+ mainForm . UseShellExecute = true ;
149
+ mainForm . WorkingDirectory = ".\\ " ;
150
+ Process . Start ( mainForm ) ;
151
+ }
152
+
158
153
private void DoBackupProcess ( ) {
159
154
logger . Info ( "バックアッププロセスを始めます" ) ;
160
155
//zipperが起動している場合はバックアップを保留にする
161
156
//バックアップがない場合で、_tmpファイルがある場合は前回のZipperがmoveを失敗してるだけの可能性があるから名前変更
162
157
if ( Directory . Exists ( AppConfig . BackupPath + "_tmp" ) && ( ! Directory . Exists ( AppConfig . BackupPath ) ) ) {
163
158
Directory . Move ( AppConfig . BackupPath + "_tmp" , AppConfig . BackupPath ) ;
164
159
}
165
-
166
-
167
160
int backupCount = 0 ;
168
-
169
161
List < string > worldPasses = GetWorldPasses ( ) ; // バックアップをするワールドへのパス一覧
170
162
string nowTime = DateTime . Now . ToString ( "yyyyMMddHHmm" ) ;
171
163
if ( worldPasses . Count == 0 ) {
172
164
logger . Info ( "どうやらバックアップ予定のデータはないようです" ) ;
173
165
}
174
166
175
167
notifyIcon . Text = $ "{ backupCount } /{ worldPasses . Count } ";
176
-
177
168
foreach ( string worldPath in worldPasses ) {
178
169
notifyIcon . Text = $ "{ backupCount ++ } /{ worldPasses . Count } ";
179
170
//前回のリロードとバックアップまでの間にワールドが消された場合
@@ -237,16 +228,8 @@ private void DoBackupProcess() {
237
228
}
238
229
Config . SyncConfig ( ) ;
239
230
logger . Info ( "全バックアップが完了しました " ) ;
240
-
241
231
timer . Enabled = true ;
242
- notifyIcon . Icon = new Icon ( ".\\ Image\\ app_sub.ico" ) ;
243
- notifyIcon . Text = "MAB待機モジュール" ;
244
- ContextMenuStrip menu = new ContextMenuStrip ( ) ;
245
- ToolStripMenuItem exit = new ToolStripMenuItem ( ) ;
246
- exit . Text = "終了" ;
247
- exit . Click += new EventHandler ( Close_Click ) ;
248
- menu . Items . Add ( exit ) ;
249
- notifyIcon . ContextMenuStrip = menu ;
232
+ SetNotifyIconWait ( ) ;
250
233
}
251
234
252
235
//バックアップをするワールドデータのパスを配列にして返す
@@ -282,5 +265,35 @@ private void DoBackup(string path, string Time) {
282
265
logger . Info ( path + " を " + backupPath + "へバックアップしました" ) ;
283
266
}
284
267
}
268
+
269
+ private void SetNotifyIconWait ( ) {
270
+ notifyIcon = new NotifyIcon ( ) ;
271
+ notifyIcon . Icon = new Icon ( ".\\ Image\\ app_sub.ico" ) ;
272
+ notifyIcon . Text = "MAB待機モジュール" ;
273
+ notifyIcon . Visible = true ;
274
+ ContextMenuStrip menu = new ContextMenuStrip ( ) ;
275
+ ToolStripMenuItem exit = new ToolStripMenuItem ( ) ;
276
+ exit . Text = "終了" ;
277
+ exit . Click += new EventHandler ( Close_Click ) ;
278
+ menu . Items . Add ( exit ) ;
279
+ ToolStripMenuItem bootMainForm = new ToolStripMenuItem ( ) ;
280
+ bootMainForm . Text = "バックアップの設定を編集する" ;
281
+ bootMainForm . Click += new EventHandler ( bootMainForm_Click ) ;
282
+ menu . Items . Add ( bootMainForm ) ;
283
+ notifyIcon . ContextMenuStrip = menu ;
284
+ }
285
+
286
+ private void SetNotifyIconBackuping ( ) {
287
+ notifyIcon = new NotifyIcon ( ) ;
288
+ notifyIcon . Icon = new Icon ( ".\\ Image\\ app_sub_doing.ico" ) ;
289
+ notifyIcon . Text = "MAB待機モジュール(バックアップ中)" ;
290
+ notifyIcon . Visible = true ;
291
+ ContextMenuStrip menu = new ContextMenuStrip ( ) ;
292
+ ToolStripMenuItem exit = new ToolStripMenuItem ( ) ;
293
+ exit . Text = "強制終了" ;
294
+ exit . Click += new EventHandler ( Close_Click ) ;
295
+ menu . Items . Add ( exit ) ;
296
+ notifyIcon . ContextMenuStrip = menu ;
297
+ }
285
298
}
286
299
}
0 commit comments