Ejemplo n.º 1
0
        public static void StartUpServer()
        {
            string archivePath     = Path.Combine(ModPath.Instsance.AssemblyPath, "SkylinesRemotePython.zip");
            bool   useShellExecute = ModInfo.ShowRemoteConsole.value;
            bool   createNoWindow  = !ModInfo.ShowRemoteConsole.value;

            using (var unzip = new Unzip(archivePath))
            {
                unzip.ExtractToDirectory(ModInfo.RemotePythonFolder);
            }

            if (ModInfo.DoNotLaunchRemoteConsole.value)
            {
                return;
            }

            process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName               = Path.Combine(ModInfo.RemotePythonFolder, "SkylinesRemotePythonDotnet.exe"),
                    Arguments              = "-port " + GetPortNumber(),
                    UseShellExecute        = useShellExecute,
                    CreateNoWindow         = createNoWindow,
                    RedirectStandardOutput = false,
                    RedirectStandardError  = false
                }
            };
            process.Start();
        }
Ejemplo n.º 2
0
        public void ReloadProjectWorkspace()
        {
            AbortFileActions();
            bool   isDefaultPath = false;
            string configPath    = UnityPythonObject.Instance.Config.ScriptWorkspacePath;

            projectWorkspacePath = configPath;
            string defaultPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "SkylinesPython");

            if (configPath == null || configPath == "")
            {
                projectWorkspacePath = defaultPath;
            }
            isDefaultPath = Util.NormalizePath(projectWorkspacePath) == Util.NormalizePath(defaultPath);
            if (projectWorkspacePath.Length == 0)
            {
                contextMsg = "Invalid project workspace path";
                return;
            }

            var exampleFileExists = false;

            projectFiles.Clear();
            System.IO.Directory.CreateDirectory(projectWorkspacePath);

            try
            {
                foreach (var file in FileUtil.ListFilesInDirectory(projectWorkspacePath))
                {
                    if (Path.GetExtension(file) == ".py")
                    {
                        var fileContent = new ScriptEditorFile(File.ReadAllText(file), file);
                        projectFiles.Add(fileContent);
                        if (Path.GetFileName(file) == ExampleScriptFileName)
                        {
                            exampleFileExists = true;
                            currentFile       = fileContent;
                        }
                    }
                }

                if (!exampleFileExists)
                {
                    var exampleFile = new ScriptEditorFile(ScriptEditorFile.DefaultSource, Path.Combine(projectWorkspacePath, ExampleScriptFileName));
                    projectFiles.Add(exampleFile);
                    SaveProjectFile(exampleFile);
                    if (currentFile == null)
                    {
                        currentFile = exampleFile;
                    }
                }

                if (isDefaultPath)
                {
                    try {
                        string archivePath = Path.Combine(ModPath.Instsance.AssemblyPath, "ExamplePythonScripts.zip");
                        string destPath    = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Path.Combine("SkylinesPython", "Examples"));
                        using (var unzip = new Unzip(archivePath)) {
                            unzip.ExtractToDirectory(destPath);
                        }
                    } catch { }
                }
            }
            catch (Exception ex)
            {
                contextMsg = ex.Message;
                return;
            }

            contextMsg = string.Empty;
        }