/// <summary> /// 获得虚拟路径 /// </summary> /// <param name="localPath">本地路径</param> /// <returns>返回相对路径,失败返回NULL</returns> internal string MapLocalPathToVirtualPath(string localDir) { if (!localDir.EndsWith(localPathSpliter.ToString())) { localDir += localPathSpliter.ToString(); } if (!HomeDir.EndsWith(localPathSpliter.ToString())) { HomeDir += localPathSpliter.ToString(); } if (localDir == HomeDir) { return(Root); } else { //Unix上的文件名需要大小写匹配 if (localDir.IndexOf(HomeDir) == -1) { NetDebuger.PrintErrorMessage(this, "MAP LOCAL DIR:" + localDir + " TO HOME DIR:" + HomeDir + " FAIL"); return(Root); } else { localDir = localDir.Replace(HomeDir, Root); //把本地路径的分隔符号,替换为虚拟路径的分隔符号 return(localDir.Replace(new string(localPathSpliter, 1), new string(virtualPathSpliter, 1)). Replace(new string(virtualPathSpliter, 2), new string(virtualPathSpliter, 1))); } } }
/// <summary> /// Connects to the FTP server /// </summary> public override void Connect() { // Init wininet and get the base handle m_hInternet = WinInet.InternetOpen( null, // The 'user-agent' making the request INTERNET_OPEN.TYPE_PRECONFIG, // Use the default proxy settings null, // proxy name (no proxy) null, // proxy bypass (no bypass) 0 // Flags for the connection ); // Validate the connection and throw an exception if necessary ValidateConnection(m_hInternet); // Get a FTP handle to use to put files m_hFtp = WinInet.InternetConnect( m_hInternet, // The internet connection to use m_ftpAddress, m_ftpPort, // The FTP port number m_userName, m_passWord, INTERNET_SERVICE.FTP, // Open the connection for this type of service FtpConnectionFlags, // FTP Flags 0 // Application Context ); // Validate the handle and throw an exception if necessary ValidateConnection(m_hFtp); //save the home dir HomeDir = WinInet.GetFtpCurrentDirectory(m_hFtp); // Set the current directory to the path. If the path is empty, don't set // the current directory as this is invalid. if (m_path != "") { if (!m_path.StartsWith("/", StringComparison.OrdinalIgnoreCase)) { string homeDir = HomeDir; if (!homeDir.EndsWith("/", StringComparison.OrdinalIgnoreCase)) { homeDir = homeDir + "/"; } m_path = homeDir + m_path + "/"; } if (!m_path.EndsWith("/", StringComparison.OrdinalIgnoreCase)) { //Mindspring's FTP behaves strangely if the current //directory isn't set with a trailing "/" m_path += "/"; } if (!RawDirectoryExists(m_path)) { if (!(HomeDir != null && HomeDir.StartsWith(m_path, StringComparison.OrdinalIgnoreCase) && m_path != "" && m_path.EndsWith("/", StringComparison.OrdinalIgnoreCase))) { throw new NoSuchDirectoryException(m_path); } } // Some FTP servers don't let you cwd to /, but we // still need to use it as our m_path. // // ValidateFTPCommand(pushDirectory(m_path)); } else { //remember what the default working directory assigned by the server was. m_path = HomeDir; } }
public override bool Init() { Operation init = Begin("Initializing embedded Python interpreter"); if (PythonEngine.IsInitialized && (HomeDir != string.Empty || ModulePath != string.Empty || Args.Count > 0)) { Error("Python engine is already initialized and cannot be initilaized with another script or aditional arguments."); init.Cancel(); return(false); } string originalDirectory = Directory.GetCurrentDirectory(); try { SetVirtualEnvDir(); SetBinDir(); if (binDir.IsNotEmpty()) { Directory.SetCurrentDirectory(binDir); } SetPythonPath(); PythonEngine.Initialize(Args); } catch (DllNotFoundException dnfe) { if (HomeDir.IsEmpty()) { Error(dnfe, $"Could not find the system-wide python36 shared library. Add Python 3.6 to your PATH environment variable or use the -P option to set the path to a Python 3.6 interpreter directory."); } else { Error(dnfe, $"Could not find python36 shared library in {HomeDir}."); } } catch (Exception e) { Error(e, "Exception thrown initalizing Python engine."); } finally { if (Directory.GetCurrentDirectory() != originalDirectory) { Directory.SetCurrentDirectory(originalDirectory); } } if (!PythonEngine.IsInitialized) { Error("Could not initalize Python engine."); init.Cancel(); return(false); } Info("Python version {0} from {1}.", PythonEngine.Version.Trim(), binDir.IsEmpty() ? Runtime.PythonDLL : Path.Combine(binDir, Runtime.PythonDLL.WithDllExt())); Modules = GetModules(); Info("{0} Python modules installed.", Modules.Count(m => !m.StartsWith("__"))); HasPipModule = Modules.Contains("pip"); if (!HasPipModule) { Warn("Python pip module is not installed."); } else { PipModules = GetPipModules(); Info("{0} pip modules installed.", PipModules.Count); } foreach (string m in RequiredModules) { if (!Modules.Contains(m)) { Error("Python {0} module is not installed.", m); init.Cancel(); return(false); } } init.Complete(); return(true); }