Notifying a message in Action center.
Revision | a59b49f158ac8cba6c95ddc08b19df6cf84b2b30 (tree) |
---|---|
Zeit | 2015-01-05 15:44:14 |
Autor | JeffyTS <JeffyTS@outl...> |
Commiter | JeffyTS |
Coresponded to workingDir.
@@ -370,7 +370,7 @@ namespace CtrlVix | ||
370 | 370 | return Constants.TOOLS_RUNNING.NOT_RUNNING; |
371 | 371 | } |
372 | 372 | |
373 | - public Constants.POWER_OFF_MODE CheckPowerOffMode(string vmxFilePath) | |
373 | + public Constants.POWER_OFF_MODE CheckPowerOffMode(string vmxFilePath, string workingDir) | |
374 | 374 | { |
375 | 375 | int vmState; |
376 | 376 | string Dir; |
@@ -395,7 +395,8 @@ namespace CtrlVix | ||
395 | 395 | // エラーでファイルが残った場合などはうまく判定できない可能性あり |
396 | 396 | try |
397 | 397 | { |
398 | - Dir = System.IO.Path.GetDirectoryName(vmxFilePath); | |
398 | + // Dir = System.IO.Path.GetDirectoryName(vmxFilePath); | |
399 | + Dir = workingDir; | |
399 | 400 | VMname = System.IO.Path.GetFileNameWithoutExtension(vmxFilePath); |
400 | 401 | VMSSname = VMname + "-*.vmss"; |
401 | 402 |
@@ -10,7 +10,7 @@ using System.Runtime.InteropServices; | ||
10 | 10 | [assembly: AssemblyConfiguration("")] |
11 | 11 | [assembly: AssemblyCompany("")] |
12 | 12 | [assembly: AssemblyProduct("CtrlVIX")] |
13 | -[assembly: AssemblyCopyright("Copyright © 2014")] | |
13 | +[assembly: AssemblyCopyright("Copyright © 2014-2015 T.S. All rights reserved.")] | |
14 | 14 | [assembly: AssemblyTrademark("")] |
15 | 15 | [assembly: AssemblyCulture("")] |
16 | 16 |
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices; | ||
32 | 32 | // すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を |
33 | 33 | // 既定値にすることができます: |
34 | 34 | // [assembly: AssemblyVersion("1.0.*")] |
35 | -[assembly: AssemblyVersion("1.0.0.0")] | |
36 | -[assembly: AssemblyFileVersion("1.0.0.0")] | |
35 | +[assembly: AssemblyVersion("1.0.2.0")] | |
36 | +[assembly: AssemblyFileVersion("1.0.2.0")] |
@@ -12,6 +12,10 @@ using CtrlVix; // Add | ||
12 | 12 | using System.Reflection; // Add |
13 | 13 | using System.Management; // Add |
14 | 14 | using System.Diagnostics; // Add |
15 | +using System.IO; // Add | |
16 | +using System.Text.RegularExpressions; // Add | |
17 | + | |
18 | + | |
15 | 19 | |
16 | 20 | |
17 | 21 | namespace VMwPlayerTaskTray |
@@ -48,6 +52,7 @@ namespace VMwPlayerTaskTray | ||
48 | 52 | |
49 | 53 | // クラス内のグローバル変数 |
50 | 54 | private string vmxFilePath = ""; |
55 | + private string workingDir = ""; | |
51 | 56 | private VMSTATE vmState = VMSTATE.UNDEFINED; |
52 | 57 | private enum VMSTATE : int // ChangeMenuItem() |
53 | 58 | { |
@@ -93,6 +98,7 @@ namespace VMwPlayerTaskTray | ||
93 | 98 | { |
94 | 99 | vmxFilePath = Program.vmxFilePath; // Mainで設定されたvmxFilePathをコピー |
95 | 100 | vmxName = System.IO.Path.GetFileNameWithoutExtension(vmxFilePath); // vmx 名を作成 |
101 | + workingDir = GetWorkingDir(vmxFilePath); //workingDirの取得 | |
96 | 102 | |
97 | 103 | if (CountProcess(PROGRAM_NAME, vmxName) > 1) // 二重起動のチェック |
98 | 104 | { |
@@ -286,7 +292,8 @@ namespace VMwPlayerTaskTray | ||
286 | 292 | // Go to Suspend mode |
287 | 293 | if (!Vix.VMOperation(vmxFilePath, CtrlVix.Constants.POWEROP.SUSPEND)) return false; |
288 | 294 | while (((state = Vix.GetVMState(vmxFilePath)) != CtrlVix.Constants.VMSTATE.POWERED_OFF) |
289 | - && ((pwOff = Vix.CheckPowerOffMode(vmxFilePath)) != CtrlVix.Constants.POWER_OFF_MODE.SUSPENDED)) | |
295 | + && ((pwOff = Vix.CheckPowerOffMode(vmxFilePath, workingDir)) | |
296 | + != CtrlVix.Constants.POWER_OFF_MODE.SUSPENDED)) | |
290 | 297 | { |
291 | 298 | if (state == CtrlVix.Constants.VMSTATE.ERROR) return false; |
292 | 299 | if (pwOff == CtrlVix.Constants.POWER_OFF_MODE.ERROR) return false; |
@@ -302,7 +309,8 @@ namespace VMwPlayerTaskTray | ||
302 | 309 | // Go to Suspend mode |
303 | 310 | if (!Vix.VMOperation(vmxFilePath, CtrlVix.Constants.POWEROP.SUSPEND)) return false; |
304 | 311 | while (((state = Vix.GetVMState(vmxFilePath)) != CtrlVix.Constants.VMSTATE.POWERED_OFF) |
305 | - && ((pwOff = Vix.CheckPowerOffMode(vmxFilePath)) != CtrlVix.Constants.POWER_OFF_MODE.SUSPENDED)) | |
312 | + && ((pwOff = Vix.CheckPowerOffMode(vmxFilePath, workingDir)) | |
313 | + != CtrlVix.Constants.POWER_OFF_MODE.SUSPENDED)) | |
306 | 314 | { |
307 | 315 | if (state == CtrlVix.Constants.VMSTATE.ERROR) return false; |
308 | 316 | if (pwOff == CtrlVix.Constants.POWER_OFF_MODE.ERROR) return false; |
@@ -349,7 +357,8 @@ namespace VMwPlayerTaskTray | ||
349 | 357 | break; |
350 | 358 | case VMCTRL.GO_SUSPEND: |
351 | 359 | while (((state = Vix.GetVMState(vmxFilePath)) != CtrlVix.Constants.VMSTATE.POWERED_OFF) |
352 | - && ((pwOff = Vix.CheckPowerOffMode(vmxFilePath)) != CtrlVix.Constants.POWER_OFF_MODE.SUSPENDED)) | |
360 | + && ((pwOff = Vix.CheckPowerOffMode(vmxFilePath, workingDir)) | |
361 | + != CtrlVix.Constants.POWER_OFF_MODE.SUSPENDED)) | |
353 | 362 | { |
354 | 363 | if (state == CtrlVix.Constants.VMSTATE.ERROR) return false; |
355 | 364 | if (pwOff == CtrlVix.Constants.POWER_OFF_MODE.ERROR) return false; |
@@ -441,7 +450,7 @@ namespace VMwPlayerTaskTray | ||
441 | 450 | } |
442 | 451 | else |
443 | 452 | { |
444 | - switch (Vix.CheckPowerOffMode(vmxFilePath)) | |
453 | + switch (Vix.CheckPowerOffMode(vmxFilePath, workingDir)) | |
445 | 454 | { |
446 | 455 | case Constants.POWER_OFF_MODE.SUSPENDED: |
447 | 456 | // Suspended |
@@ -580,6 +589,70 @@ namespace VMwPlayerTaskTray | ||
580 | 589 | return count; |
581 | 590 | } |
582 | 591 | |
592 | + private string GetWorkingDir(string vmxFilePath) | |
593 | + { | |
594 | + foreach (var section in ReadVMX(vmxFilePath)) { | |
595 | + // section.Key は無視 | |
596 | + foreach (var pair in section.Value) { | |
597 | + if (pair.Key == "workingDir") return (pair.Value.Substring(1, pair.Value.Length - 2)); | |
598 | + } | |
599 | + } | |
600 | + return System.IO.Path.GetDirectoryName(vmxFilePath); | |
601 | + } | |
602 | + | |
603 | + private static Dictionary<string, Dictionary<string, string>> ReadVMX(string file) | |
604 | + { | |
605 | + using (var reader = new StreamReader(file)) | |
606 | + { | |
607 | + var sections = new Dictionary<string, Dictionary<string, string>>(StringComparer.Ordinal); | |
608 | + var regexSection = new Regex(@"^\s*\[(?<section>[^\]]+)\].*$", RegexOptions.Singleline | |
609 | + | RegexOptions.CultureInvariant); | |
610 | + var regexNameValue = new Regex(@"^\s*(?<name>[^=]+)=(?<value>.*?)(\s+;(?<comment>.*))?$", | |
611 | + RegexOptions.Singleline | RegexOptions.CultureInvariant); | |
612 | + var currentSection = string.Empty; | |
613 | + | |
614 | + // セクション名が明示されていない先頭部分のセクション名を""として扱う | |
615 | + sections[string.Empty] = new Dictionary<string, string>(); | |
616 | + | |
617 | + for (; ; ) | |
618 | + { | |
619 | + var line = reader.ReadLine(); | |
620 | + | |
621 | + if (line == null) break; | |
622 | + | |
623 | + // 空行は読み飛ばす | |
624 | + if (line.Length == 0) continue; | |
625 | + | |
626 | + // コメント行は読み飛ばす | |
627 | + if (line.StartsWith(";", StringComparison.Ordinal)) continue; | |
628 | + else if (line.StartsWith("#", StringComparison.Ordinal)) continue; | |
629 | + | |
630 | + var matchNameValue = regexNameValue.Match(line); | |
631 | + | |
632 | + if (matchNameValue.Success) | |
633 | + { | |
634 | + // name=valueの行 | |
635 | + sections[currentSection][matchNameValue.Groups["name"].Value.Trim()] | |
636 | + = matchNameValue.Groups["value"].Value.Trim(); | |
637 | + continue; | |
638 | + } | |
639 | + | |
640 | + var matchSection = regexSection.Match(line); | |
641 | + | |
642 | + if (matchSection.Success) | |
643 | + { | |
644 | + // [section]の行 | |
645 | + currentSection = matchSection.Groups["section"].Value; | |
646 | + | |
647 | + if (!sections.ContainsKey(currentSection)) sections[currentSection] = new Dictionary<string, string>(); | |
648 | + | |
649 | + continue; | |
650 | + } | |
651 | + } | |
652 | + return sections; | |
653 | + } | |
654 | + } | |
655 | + | |
583 | 656 | private void AboutDialog() |
584 | 657 | { |
585 | 658 | string message; |
@@ -10,7 +10,7 @@ using System.Runtime.InteropServices; | ||
10 | 10 | [assembly: AssemblyConfiguration("")] |
11 | 11 | [assembly: AssemblyCompany("")] |
12 | 12 | [assembly: AssemblyProduct("VMwPlayerTaskTray")] |
13 | -[assembly: AssemblyCopyright("Copyright © 2014 T.S. All rights reserved.")] | |
13 | +[assembly: AssemblyCopyright("Copyright © 2014-2015 T.S. All rights reserved.")] | |
14 | 14 | [assembly: AssemblyTrademark("")] |
15 | 15 | [assembly: AssemblyCulture("")] |
16 | 16 |
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices; | ||
32 | 32 | // すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を |
33 | 33 | // 既定値にすることができます: |
34 | 34 | // [assembly: AssemblyVersion("1.0.*")] |
35 | -[assembly: AssemblyVersion("1.0.1.*")] | |
36 | -[assembly: AssemblyFileVersion("1.0.1.0")] | |
35 | +[assembly: AssemblyVersion("1.0.2.*")] | |
36 | +[assembly: AssemblyFileVersion("1.0.2.0")] |
@@ -32,8 +32,9 @@ Thanks to VMware,Inc and Microsoft Corporation. | ||
32 | 32 | Rlease & modify |
33 | 33 | --- Date --- Ver. -- Modify -- |
34 | 34 | 2014/04/01 1.0.0 First release for VMware Player 6.0.2 and VMware VIX 1.13.2. |
35 | - 2014/12/26 1.0.1 Changed developping environment to VMware Player 7.0.0 and VMware VIX 1.14.0 | |
35 | + 2014/12/26 1.0.1 Changed developping environment to VMware Player 7.0.0 and VMware VIX 1.14.0. | |
36 | 36 | 2015/01/05 1.0.1 Improved await proc and added readme.txt. |
37 | + 2015/01/05 1.0.2 Coresponded to workingDir. | |
37 | 38 | |
38 | 39 | |
39 | 40 |