Skip to content

Commit 2f8b779

Browse files
committed
MABProcessからMinformを起動できるように機能追加
1 parent bf5d35f commit 2f8b779

File tree

1 file changed

+46
-33
lines changed

1 file changed

+46
-33
lines changed

MABProcessAtWait/Program.cs

Lines changed: 46 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public partial class Form1 :Form {
8181
private Task backupTask;
8282

8383
public Form1() {
84+
logger.Info("Current Dir: "+System.Environment.CurrentDirectory);
8485
backupDataPath = AppConfig.BackupPath;
8586
this.ShowInTaskbar = false;
8687
this.Icon = new Icon(".\\Image\\app.ico");
@@ -92,16 +93,7 @@ public Form1() {
9293
timer.Interval = 1000;
9394
timer.Tick += new EventHandler(Timer_Tick);
9495

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();
10597
}
10698

10799
private void Close_Click(object sender, EventArgs e) {
@@ -117,13 +109,13 @@ private void Close_Click(object sender, EventArgs e) {
117109
Application.Exit();
118110
}
119111

120-
void Form1_Closing(object sender, EventArgs e) {
112+
private void Form1_Closing(object sender, EventArgs e) {
121113
logger.Info("アプリケーションが強制終了しました");
122114
notifyIcon.Visible = false;
123115
notifyIcon.Dispose();
124116
}
125117

126-
void Timer_Tick(object sender, EventArgs e) {
118+
private void Timer_Tick(object sender, EventArgs e) {
127119
// lancherが起動してない場合 => 何もしない
128120
// lancherが起動していてflagがfalse => flagをtrueにしてバックアップ動作
129121
// lancherが起動していてflagがtrue => 何もしない
@@ -136,14 +128,7 @@ void Timer_Tick(object sender, EventArgs e) {
136128
logger.Info("Minecraft Lancherの起動を検知しました");
137129
logger.Info("isRunningがfalseに設定されていました");
138130

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();
147132
backupTask = Task.Run(() => {
148133
DoBackupProcess();
149134
});
@@ -155,25 +140,31 @@ void Timer_Tick(object sender, EventArgs e) {
155140
}
156141
}
157142

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+
158153
private void DoBackupProcess() {
159154
logger.Info("バックアッププロセスを始めます");
160155
//zipperが起動している場合はバックアップを保留にする
161156
//バックアップがない場合で、_tmpファイルがある場合は前回のZipperがmoveを失敗してるだけの可能性があるから名前変更
162157
if (Directory.Exists(AppConfig.BackupPath + "_tmp") && (!Directory.Exists(AppConfig.BackupPath))) {
163158
Directory.Move(AppConfig.BackupPath + "_tmp", AppConfig.BackupPath);
164159
}
165-
166-
167160
int backupCount = 0;
168-
169161
List<string> worldPasses = GetWorldPasses();// バックアップをするワールドへのパス一覧
170162
string nowTime = DateTime.Now.ToString("yyyyMMddHHmm");
171163
if (worldPasses.Count == 0) {
172164
logger.Info("どうやらバックアップ予定のデータはないようです");
173165
}
174166

175167
notifyIcon.Text = $"{backupCount}/{worldPasses.Count}";
176-
177168
foreach (string worldPath in worldPasses) {
178169
notifyIcon.Text = $"{backupCount++}/{worldPasses.Count}";
179170
//前回のリロードとバックアップまでの間にワールドが消された場合
@@ -237,16 +228,8 @@ private void DoBackupProcess() {
237228
}
238229
Config.SyncConfig();
239230
logger.Info("全バックアップが完了しました ");
240-
241231
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();
250233
}
251234

252235
//バックアップをするワールドデータのパスを配列にして返す
@@ -282,5 +265,35 @@ private void DoBackup(string path, string Time) {
282265
logger.Info(path + " を " + backupPath + "へバックアップしました");
283266
}
284267
}
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+
}
285298
}
286299
}

0 commit comments

Comments
 (0)