internal static void Main(string[] args) { string arg = string.Join(" ", args); if (arg.Length < PREFIX.Length) { Forms.MessageBox.Show("Missing Argument. exitting...", TITLE, Forms.MessageBoxButtons.OK, Forms.MessageBoxIcon.Exclamation); return; } arg = arg.Substring(PREFIX.Length); // trim a prefix args = arg.Split('#'); string path = args[0]; #if !DEBUG // Dialog System.Reflection.Assembly asm; asm = System.Reflection.Assembly.GetExecutingAssembly(); System.Resources.ResourceManager rm = new System.Resources.ResourceManager( asm.GetName().Name + ".Properties.Resources", asm); string guardDialogMessage = rm.GetString("GuardDialog"); #endif try { if (path.EndsWith(".xlsx")) { #if !DEBUG Forms.DialogResult result = Forms.MessageBox.Show( String.Format(guardDialogMessage, "Microsoft Excel", arg), TITLE, Forms.MessageBoxButtons.YesNo, Forms.MessageBoxIcon.Exclamation, Forms.MessageBoxDefaultButton.Button2); if (result == Forms.DialogResult.No) { return; } #endif Excel._Application appl = GetExcel(); Excel.Workbooks workbooks = appl.Workbooks; Excel.Workbook workbook; appl.Visible = true; if (!path.Contains("%")) { workbook = workbooks.Open(path); } else { path = Uri.UnescapeDataString(path); workbook = workbooks.Open(path); } if (args.Length > 0) // if fragment exists { if (Exists(appl.Names, args[1])) { appl.Goto(args[1]); } else { SelectFragment(workbook, args[1]); } } // bring up workbook.Activate(); SetForegroundWindow(appl.Hwnd); } else if (path.EndsWith(".pptx")) { #if !DEBUG Forms.DialogResult result = Forms.MessageBox.Show( String.Format(guardDialogMessage, "Microsoft PowerPoint", arg), TITLE, Forms.MessageBoxButtons.YesNo, Forms.MessageBoxIcon.Exclamation, Forms.MessageBoxDefaultButton.Button2); if (result == Forms.DialogResult.No) { return; } #endif PowerPoint._Application appl = GetPowerPoint(); PowerPoint.Presentations ppts = appl.Presentations; PowerPoint.Presentation ppt; if (!path.Contains("%")) { ppt = ppts.Open(path); } else { path = Uri.UnescapeDataString(path); ppt = ppts.Open(path); } if (args.Length > 0) // if fragment exists { SelectFragment(ppt, args[1]); } // bring up appl.Activate(); appl.Visible = MsoTriState.msoTrue; SetForegroundWindow(appl.HWND); } else { // TODO: add another suffixes supporting Forms.MessageBox.Show("only .xlsx is supported. exitting.", TITLE, Forms.MessageBoxButtons.OK, Forms.MessageBoxIcon.Exclamation); return; } } catch (COMException ex) { Forms.MessageBox.Show( (GetExcel().Name.Equals(ex.Source) ? ex.Message : "ファイルを開けませんでした。") #if DEBUG + "\r\n\r\n" + ex.StackTrace #endif , TITLE, Forms.MessageBoxButtons.OK, Forms.MessageBoxIcon.Exclamation); } }