Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.IO;
- using System.Xml;
- using System.Threading;
- namespace SharpDevelop
- {
- class Program
- {
- public static void Main()
- {
- /*
- For use on portable installations of SharpDevelop on USB or student documents or school shared network drive.
- It changes the setting for the 'New Project' location then launches \bin\SharpDevelop.exe.
- It uses the PortableApps structure, where the SharpDevelop folder is inside PortableApps folder,
- and the .exe file is expected within this folder in order for PortableApps to start it.
- On a USB the project save path is in X:\Documents\Projects\CSharp
- On student documents the save path is <mapped drive>:\Documents\Projects\CSharp (if .exe allowed)
- On a shared drive at schools the save path is <mapped drive>:\Users\<username>\CSharp. (.exe allowed on this drive only)
- This allows multiple users to use the same install, but save their projects under their own username.
- Place the .exe generated from this code at the root of the SharpDevelop folder
- This project is called 'SharpDevelop' and located in a sub-folder of the 'SharpDevelop'
- install folder, called 'SharpDevelopPortableLauncher'.
- When compiled it creates an .exe file called SharpDevelop.exe in
- SharpDevelopPortableLauncher\SharpDevelop\bin\Debug\SharpDevelop.exe
- This file should be copied to the root folder of the SharpDevelop installation folder:
- <folder>\SharpDevelop\SharpDevelop.exe
- Assume location of this exe is either in same folder as SharpDevelop in PortableApps
- IDE: <folder>\PortableApps\SharpDevelop\SharpDevelopPortableLauncher\SharpDevelop\bin\Debug\SharpDevelop.exe
- Compiled: <folder>\PortableApps\SharpDevelop\SharpDevelop.exe
- --> either one launches <folder>\PortableApps\SharpDevelop\bin\SharpDevelop.exe to run the IDE
- need to adjust SharpDevelop\Settings\SharpDevelopProperties.xml for 'NewProjectDialog'
- SharpDevelop could be in:
- 1-<any folder or root of drive>\SharpDevelop - Do not alter the settings!
- 2-<folder or drive>\PortableApps\SharpDevelop with <folder or drive>\Documents
- = on USB or User Profile on school system. Set save location to \Documents\Projects\CSharp
- 3-<folder or drive>\PortableApps\SharpDevelop with <folder or drive>\Users
- = on shared drive. Set save location to \Users\UserName\CSharp
- */
- Console.WriteLine("PortableApps Launcher for SharpDevelop");
- string driveLetter = Path.GetPathRoot(Environment.CurrentDirectory); // X:\
- Console.WriteLine("Drive Letter: " + driveLetter);
- //full startup of .exe eg in .bin folder
- string AppPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
- Console.WriteLine("App Path: " + AppPath);
- string SDPath = AppPath.Substring(0, AppPath.IndexOf(@"\SharpDevelop")) + @"\SharpDevelop"; // e.g W:\ICT-CLUB\PortableApps\
- Console.WriteLine("SharpDevelop.exe (launcher) located at: " + SDPath);
- Console.WriteLine("SharpDevelop.exe (executable) located at: " + SDPath + @"\bin\SharpDevelop.exe");
- string RootPath = string.Empty;
- string SavesFolder = string.Empty;
- // Check for \PortableApps eg W:\ICT-CLUB\PortableApps\
- if(AppPath.Contains("PortableApps")) //inside PortableApps, so change settings
- {
- RootPath = AppPath.Substring(0, AppPath.IndexOf(@"\PortableApps") + 1); // X:\, W:\ICT-CLUB\
- Console.WriteLine("RootPath = " + RootPath);
- // Check for \Documents
- if(Directory.Exists(Path.Combine(RootPath, @"Documents"))) //on USB OR school user space. Create CSharp folder (No effect if exists)
- {
- //if on usb RootPath = driveLetter
- if(RootPath == driveLetter) // on USB
- {
- Console.WriteLine("Running from USB (" + driveLetter + ")");
- }
- else // not on usb: student space
- {
- Console.WriteLine("Running from Documents: (" + RootPath + ")");
- }
- if(Directory.Exists(Path.Combine(RootPath, @"Documents\Projects"))) // Documents\Projects already exists
- {
- if(!Directory.Exists(Path.Combine(RootPath, @"Documents\Projects\CSharp")))
- {
- Console.WriteLine("Creating saves folders");
- Directory.CreateDirectory(Path.Combine(RootPath, @"\Documents\Projects\CSharp"));
- }
- SavesFolder = Path.Combine(RootPath, @"Documents\Projects\CSharp");
- }
- else if(Directory.Exists(Path.Combine(RootPath, @"Documents\CSharp"))) // Documents\Projects\CSharp already exists
- {
- SavesFolder = Path.Combine(RootPath, @"Documents\CSharp");
- }
- else
- {
- SavesFolder = Path.Combine(RootPath, @"Documents\Projects\CSharp");
- Console.WriteLine("Creating / checking saves folders");
- Directory.CreateDirectory(Path.Combine(RootPath, @"\Documents\Projects\"));
- Directory.CreateDirectory(Path.Combine(RootPath, @"\Documents\Projects\CSharp"));
- }
- }
- else if(Directory.Exists(Path.Combine(RootPath, @"Users"))) // on shared folder: create folder from username
- {
- //Create saves folder based on username for school shared drives
- Console.WriteLine("Creating / checking saves folders");
- // CreateDirectory is ignored if the folder already exists
- Directory.CreateDirectory(Path.Combine(RootPath, @"Users\" + Environment.UserName));
- Directory.CreateDirectory(Path.Combine(RootPath, @"Users\" + Environment.UserName + @"\CSharp"));
- //Can also create folders for portable versions of other IDEs
- Directory.CreateDirectory(Path.Combine(RootPath, @"Users\" + Environment.UserName + @"\HTML"));
- Directory.CreateDirectory(Path.Combine(RootPath, @"Users\" + Environment.UserName + @"\Lua"));
- Directory.CreateDirectory(Path.Combine(RootPath, @"Users\" + Environment.UserName + @"\Java"));
- Directory.CreateDirectory(Path.Combine(RootPath, @"Users\" + Environment.UserName + @"\Python"));
- Directory.CreateDirectory(Path.Combine(RootPath, @"Users\" + Environment.UserName + @"\Scratch"));
- SavesFolder = Path.Combine(RootPath, @"Users\" + Environment.UserName + @"\CSharp");
- }
- Console.WriteLine("Saves Folder: " + SavesFolder);
- // now alter settings
- string settingsFilePath = Path.Combine(SDPath, @"Settings\SharpDevelopProperties.xml");
- XmlDocument SharpDevelopProperties = new XmlDocument();
- SharpDevelopProperties.Load(settingsFilePath);
- try
- {
- XmlElement DefaultPath =
- (XmlElement)SharpDevelopProperties.SelectSingleNode(
- "//Properties/Property[@key='ICSharpCode.SharpDevelop.Gui.Dialogs.NewProjectDialog.DefaultPath']");
- if (DefaultPath != null)
- {
- DefaultPath.InnerText = SavesFolder;
- }
- SharpDevelopProperties.Save(settingsFilePath);
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- }
- }
- else
- {
- RootPath = AppPath;
- Console.WriteLine("RootPath = " + RootPath);
- }
- Console.WriteLine("Launching SharpDevelop\n\nHold tight!");
- try
- {
- System.Diagnostics.Process.Start(Path.Combine(SDPath, @"bin\SharpDevelop.exe"));
- Console.WriteLine("\nClosing in 30 seconds...");
- Thread.Sleep(30000);
- }
- catch (Exception e)
- {
- Console.WriteLine(e.Message);
- Console.WriteLine("Press enter to exit");
- Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement