private static void setOpenedFileFullNameFrom(string[] programArgs) { openedFileFullName = null; for (int index = ProgChooser.iParam0; index < programArgs.Length; index++) { openedFileFullName = programArgs[index]; sParticiple = "getting current extension"; int iLastDot = openedFileFullName.LastIndexOf("."); if (iLastDot >= 0) { if (iLastDot + 1 < openedFileFullName.Length) { ProgChooser.openingFileExt = openedFileFullName.Substring(iLastDot + 1); } else { ProgChooser.openingFileExt = ""; } } else { ProgChooser.openingFileExt = ""; } extinfoNow = ProgChooser.getExtInfo_ByRef(ProgChooser.openingFileExt); break; } }
void runProgram(int index) { string Name = ""; foreach (Label thisLabel in progLabels) { if (index.ToString() == (string)thisLabel.Tag) { Name = thisLabel.Text; } } statusLabel.Text = "Loading " + Name + "..."; // string result=ProgChooser.launchProgram(index); // if (result=null) Application.Exit(); // else statusLabel.Text=result; bool result = ProgChooser.launchProgram(index); if (result) { Application.Exit(); } else { statusLabel.Text = "Could not launch program: " + ProgChooser.getError(); } }
public static bool AddChoice(string ext, string[] paths, string[] captions, int hotkeyI) { string sExeNow = null; int foundI = -1; Console.Error.WriteLine("checking for program for " + ext); for (int index = 0; index < paths.Length; index++) { try { if (File.Exists(paths[index])) { sExeNow = paths[index]; Console.Error.WriteLine("found " + sExeNow); foundI = index; } else { Console.Error.WriteLine("no " + paths[index]); } } catch { if (paths[index] != null) { Console.Error.WriteLine("Path " + index.ToString() + " is bad for " + ext + ": \"" + paths[index] + "\""); } else { Console.Error.WriteLine("Path " + index.ToString() + " is bad for " + ext); } } // if path is bad, don't care } if (sExeNow != null) { ProgChooser.ForceAddChoice("sln", sExeNow, captions[foundI], hotkeyI); } else { // ALWAYS add it, so that the number key corresponding // to kotkeyI opens the matching sequential version. ProgChooser.ForceAddChoice("sln", paths[0], "NONE (no " + captions[0] + " found)", hotkeyI); } return(sExeNow != null); }
public static bool launchProgram(int iProgIndex) { //isLaunched=false; lastErrorString = null; if (extinfoNow != null) { if (extinfoNow.isSlotUsed(iProgIndex)) { try { ProgChooser.IsAnswered = true; //string sCommand=proginfoarrNow[iProgIndex].FullName+" \""+programArgs[iParam0]+"\""; //ProcessStartInfo psiNow=new ProcessStartInfo(proginfoarrNow[iProgIndex].FullName,programArgs[iParam0]); //Process ps=Process.Start(psiNow); Process ps = new Process(); ps.StartInfo.FileName = extinfoNow.proginfoarr[iProgIndex].FullName; if (openedFileFullName.Contains(" ") && openedFileFullName.Length > 2 && (openedFileFullName[0] != '"' || openedFileFullName[openedFileFullName.Length - 1] != '"')) { ps.StartInfo.Arguments = "\"" + openedFileFullName + "\""; } else { ps.StartInfo.Arguments = openedFileFullName; } ps.Start(); isLaunched = true; } catch (Exception exn) { ProgChooser.Error_WriteLine("launchProgram could not finish for the following reason: " + exn.ToString()); } } else { ProgChooser.Error_WriteLine("launchProgram could not find anything in slot " + iProgIndex.ToString()); } } else { ProgChooser.Error_WriteLine("Sorry, ProgChooser has no info for that file extension"); } return(ProgChooser.isLaunched); } //end launchProgram
/// <summary> /// Load the programs for the extension of the program in the parameters /// </summary> /// <param name="programArgs"></param> /// <returns>Returns error message, otherwise null if status is good.</returns> public static string load(string[] programArgs) { lastErrorString = null; string errorString = null; //try { ProgChooser.IsAnswered = false; //int proginfoarrNow_Max=10; //ProgInfo[] proginfoarrNow=new ProgInfo[proginfoarrNow_Max]; //int extinfoNow.ProgramCount=0; //proginfoarrNow[extinfoNow.ProgramCount].Title="SharpDevelop 3.0"; //proginfoarrNow[extinfoNow.ProgramCount].FullName="C:\\PortableApps\\Programming\\SharpDevelop\\3.0\\bin\\SharpDevelop.exe"; //extinfoNow.ProgramCount++; //proginfoarrNow[extinfoNow.ProgramCount].Title="Microsoft Visual C++ 2008 Express Edition"; //proginfoarrNow[extinfoNow.ProgramCount].FullName="C:\\Program Files\\Microsoft Visual Studio 9.0\\Common7\\IDE\\VCExpress.exe"; //extinfoNow.ProgramCount++; /// ADD PROGRAMS BY EXTENSION /// sParticiple = "adding known extension"; //SharpDevelop 3.x: ProgChooser.AddExtension("sln"); sParticiple = "adding programs"; Console.Error.WriteLine(sParticiple); AddChoice( "sln", new[] { @"C:\Program Files (x86)\SharpDevelop\1.1\bin\SharpDevelop.exe", @"C:\Program Files\SharpDevelop\1.1\bin\SharpDevelop.exe" }, "SharpDevelop 1", 1 ); AddChoice( "sln", new[] { @"C:\Program Files (x86)\SharpDevelop\2.2\bin\SharpDevelop.exe", @"C:\Program Files\SharpDevelop\2.2\bin\SharpDevelop.exe" }, "SharpDevelop 2", 2 ); AddChoice( "sln", new[] { "C:\\Program Files (x86)\\SharpDevelop\\3.0\\bin\\SharpDevelop.exe", "E:\\PortableApps\\Programming\\SharpDevelop\\3.0\\bin\\SharpDevelop.exe", "C:\\PortableApps\\Programming\\SharpDevelop\\3.0\\bin\\SharpDevelop.exe", "C:\\Program Files\\SharpDevelop\\3.0\\bin\\SharpDevelop.exe" }, "SharpDevelop 3", 3 ); AddChoice( "sln", new[] { @"C:\Program Files (x86)\SharpDevelop\4.4\bin\SharpDevelop.exe", @"C:\Program Files\SharpDevelop\4.4\bin\SharpDevelop.exe", "E:\\PortableApps\\Programming\\SharpDevelop\\4.4\\bin\\SharpDevelop.exe", "C:\\PortableApps\\Programming\\SharpDevelop\\4.4\\bin\\SharpDevelop.exe" }, "SharpDevelop 4", 4 ); AddChoice( "sln", new[] { @"C:\Program Files (x86)\SharpDevelop\5.1\bin\SharpDevelop.exe", @"C:\Program Files\SharpDevelop\5.1\bin\SharpDevelop.exe" }, "SharpDevelop 5.1", 5 ); AddChoice( "sln", new[] { "C:\\Program Files\\Microsoft Visual Studio 9.0\\Common7\\IDE\\VCExpress.exe", "E:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\Common7\\IDE\\VCExpress.exe" }, "Microsoft Visual Studio 9.0 (C++ 2008) Express Edition", 9 ); AddChoice( "sln", new[] { "E:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\Common7\\IDE\\vcsexpress.exe", "C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\Common7\\IDE\\vcsexpress.exe", @"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\WDExpress.exe" }, new[] { "Microsoft Visual C# 2008 Express Edition", "Microsoft Visual C# 2008 Express Edition", "Microsoft Visual C# 2012 Express Edition" }, 0 ); //} //catch (Exception exn) { // ProgChooser.Error_WriteLine("Could not finish ProgChooserDefaults load for the following reason:"+exn.ToString()); //} ProgChooser.setOpenedFileFullNameFrom(programArgs); // if (ProgChooser.getOpenedFileFullName()!=null) { // // } // //NOTE: else setOpendFileFullNameFrom already should have set lastErrorString return(errorString); }
void MainFormLoad(object sender, EventArgs e) { participle = "during MainFormLoad"; //try { mainFlowLayoutPanel.Location = new Point(0, 0); participle = "loading args"; string result = ProgChooser.load(args); participle = "getting choices list"; if (result != null) { MessageBox.Show(result); } ArrayList thisAL = ProgChooser.showChoicesToArrayList(); int index = 0; if (thisAL != null) { participle = "showing choices"; foreach (string thisString in thisAL) //for (int index=0; index<4; index++) { { participle = "processing choice:" + ((thisString != null)?("\"" + thisString + "\""):"null"); // Button newButton=new Button(); // this.mainFlowLayoutPanel.Controls.Add(newButton); // newButton.Location = new System.Drawing.Point(3, 3); // newButton.Name = "button"+progButtons.Count.ToString(); // newButton.Size = new System.Drawing.Size(75, 23); // newButton.TabIndex = 0; // newButton.Text = "button"+progButtons.Count.ToString(); // newButton.UseVisualStyleBackColor = true; // newButton.Click += new System.EventHandler(this.AnyProgramButtonClick); // progButtons.Add(newButton); Label newLabel = new System.Windows.Forms.Label(); this.mainFlowLayoutPanel.Controls.Add(newLabel); newLabel.Location = new System.Drawing.Point(3, 0); newLabel.Name = "programLabel" + index.ToString(); newLabel.Tag = index.ToString(); newLabel.Size = new System.Drawing.Size(100, 23); newLabel.TabIndex = 0; newLabel.Text = thisString; //"item "+index.ToString(); newLabel.AutoSize = true; newLabel.Click += new System.EventHandler(this.AnyProgramLabelClick); progLabels.Add(newLabel); index++; } } else { participle = "showing program options since no args"; string thisString = "There was no file sent to ProgChooser. The purpose of the program is to send files to a program you choose using one keystroke."; if (args.Length > 1) { string extAndQuotesIfPresent_string = "no"; string temp_extAndQuotesIfPresent_string = ProgChooser.getExtensionString(); if (!string.IsNullOrEmpty(temp_extAndQuotesIfPresent_string)) { extAndQuotesIfPresent_string = "\"" + temp_extAndQuotesIfPresent_string + "\""; } thisString = "ProgChooser has not been setup for files with " + extAndQuotesIfPresent_string + " extension."; } else { this.Text = "ProgChooser"; } Label newLabel = new System.Windows.Forms.Label(); this.mainFlowLayoutPanel.Controls.Add(newLabel); newLabel.Location = new System.Drawing.Point(3, 0); newLabel.Name = "programLabel" + index.ToString(); newLabel.Tag = index.ToString(); newLabel.Size = new System.Drawing.Size(100, 23); newLabel.TabIndex = 0; newLabel.Text = thisString; //"item "+index.ToString(); newLabel.AutoSize = true; //progLabels.Add(newLabel); Console.Error.WriteLine("Got null list of programs"); } //} //catch (Exception exn) { // Console.Error.WriteLine(("Could not finish "+participle+" ").TrimEnd()+" in MainFormLoad for the following reason: "+exn.ToString()); //} }