Esempio n. 1
0
        static public void Main(string[] args)
        {
            if (args.Length == 0 || (args.Length == 1 && (args[0] == "?" || args[0] == "/?" || args[0] == "-?" || args[0].ToLower() == "help")))
            {
                Console.WriteLine(usage);
            }
            else if (args[0].Trim().ToLower() == "/i")
            {
                SharpDevelopIDE.InstallShellExtension();
            }
            else if (args[0].Trim().ToLower() == "/u")
            {
                SharpDevelopIDE.UninstallShellExtension();
            }
            else
            {
                try
                {
                    FileInfo info = new FileInfo(args[0]);
                    scriptFile = info.FullName;
                    string srcProjDir = @"Lib\Debug\#D1.1";                     //relative to CSSCRIPT_DIR
                    string scHomeDir  = SharpDevelopIDE.GetEnvironmentVariable("CSSCRIPT_DIR");
                    string tempDir    = Path.Combine(Path.Combine(Path.GetTempPath(), "CSSCRIPT"), Environment.TickCount.ToString());

                    string projFile     = Path.Combine(tempDir, "DebugScript.prjx");
                    string solutionFile = Path.Combine(tempDir, "DebugScript.cmbx");


                    //copy project template
                    Directory.CreateDirectory(tempDir);

                    foreach (string file in Directory.GetFiles(Path.Combine(scHomeDir, srcProjDir)))
                    {
                        File.Copy(file, Path.Combine(tempDir, Path.GetFileName(file)), true);
                    }

                    //update project template with script specific data
                    SharpDevelopIDE  ide         = new SharpDevelopIDE();
                    ScriptParser     parser      = new ScriptParser(scriptFile, SearchDirs);
                    AssemblyResolver asmResolver = new AssemblyResolver();

                    ide.InsertFile(scriptFile, projFile);

                    string[] importerdScripts = parser.SaveImportedScripts();
                    foreach (string file in importerdScripts)
                    {
                        ide.InsertFile(file, projFile);
                    }

                    System.Diagnostics.Debug.Assert(false);
                    foreach (string name in parser.ReferencedNamespaces)
                    {
                        bool ignore = false;
                        foreach (string ignoreName in parser.IgnoreNamespaces)
                        {
                            if (ignore = (name == ignoreName))
                            {
                                break;
                            }
                        }

                        if (ignore)
                        {
                            continue;
                        }

                        string[] asmFiles = AssemblyResolver.FindAssembly(name, SearchDirs);

                        foreach (string file in asmFiles)
                        {
                            ide.InsertReference(file, projFile);
                        }
                    }

                    foreach (string asmName in parser.ReferencedAssemblies)                     //some assemblies were referenced from code
                    {
                        string[] asmFiles = AssemblyResolver.FindAssembly(asmName, SearchDirs);
                        foreach (string file in asmFiles)
                        {
                            ide.InsertReference(file, projFile);
                        }
                    }

                    //open project
                    Environment.CurrentDirectory = Path.GetDirectoryName(scriptFile);

                    Process myProcess = new Process();
                    myProcess.StartInfo.FileName  = SharpDevelopIDE.GetIDEFile();
                    myProcess.StartInfo.Arguments = "\"" + solutionFile + "\" ";
                    myProcess.Start();
                    myProcess.WaitForExit();

                    //do clean up
                    Directory.Delete(tempDir, true);
                    foreach (string file in importerdScripts)
                    {
                        if (Path.GetFileName(file).StartsWith("i_"))                         //imported modified files have name "i_file_XXXXXX.cs>"
                        {
                            File.SetAttributes(file, FileAttributes.Normal);
                            File.Delete(file);
                        }
                    }
                }
                catch (Exception e)
                {
                    MessageBox.Show("Specified file could not be linked to the temp project:\n" + e.Message);
                }
            }
        }