ReplaceParamsFlat() public static method

public static ReplaceParamsFlat ( string s, string>.Dictionary subs ) : string
s string
subs string>.Dictionary
return string
コード例 #1
0
        bool SendCaptivePortalHTML(HttpListenerRequest req, HttpListenerResponse res, string sessionId, string path)
        {
            //var fullPath = path.normalize(path.join(this.options.baseDir, opt_path));
            byte[] content = null;
            if (!m_webServerUtils.GetGameFile(path, out content))
            {
                res.StatusCode = (int)HttpStatusCode.NotFound;
                return(true);
            }

            string str = System.Text.Encoding.UTF8.GetString(content);
            Dictionary <string, string> subs = new Dictionary <string, string>();

            subs["startUrl"]  = GetBaseUrl(req) + m_firstPath + "?sessionId=" + sessionId;
            subs["sessionId"] = sessionId;
            str = HFTUtil.ReplaceParamsFlat(str, subs);
            m_log.Info("SCPH: Sending " + path);
            return(m_webServerUtils.SendContent(res, path, str));
        }
コード例 #2
0
        void StartExternalServer(bool admin)
        {
            TextAsset serverData = LoadTextAsset("HFTOSXServer");
            TextAsset shaData    = LoadTextAsset("HFTOSXServer.sha256");

            if (serverData == null || shaData == null)
            {
                return;
            }

            string serverPath = Application.persistentDataPath + "/hft-server";
            string shaPath    = Application.persistentDataPath + "/hft-server.sha";

            if (!FileExistsAndSame(serverPath, shaPath, shaData.text))
            {
                HFTUtil.WriteBytes(serverPath, serverData.bytes);
                HFTUtil.WriteText(shaPath, shaData.text);
                m_log.Info("wrote new webserver: " + serverPath + ", size: " + serverData.bytes.Length);
            }

            string cmdString = @"-e '
set myFile to quoted form of ""%(serverPath)s""
do shell script ""chmod -R 700 "" & myFile
do shell script myFile %(admin)s
'";
            Dictionary <string, string> dict = new Dictionary <string, string>();

            dict["serverPath"] = serverPath;
            dict["admin"]      = admin ? "with administrator privileges" : "";
            string script = HFTUtil.ReplaceParamsFlat(cmdString, dict);

            System.Diagnostics.Process          p   = new System.Diagnostics.Process();
            System.Diagnostics.ProcessStartInfo psi = p.StartInfo;
            psi.EnvironmentVariables.Add("HFT_ARGS", Serializer.Serialize(m_options));
            psi.UseShellExecute        = false;
            psi.FileName               = "/usr/bin/osascript";
            psi.Arguments              = script;
            psi.RedirectStandardError  = true;
            psi.RedirectStandardOutput = true;
            p.ErrorDataReceived       += new System.Diagnostics.DataReceivedEventHandler((sender, e) => {
                if (m_listening && !String.IsNullOrEmpty(e.Data))
                {
                    m_log.Tell("webserver: stderr: " + e.Data);
                }
            });
            p.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler((sender, e) => {
                if (m_listening && !String.IsNullOrEmpty(e.Data))
                {
                    m_log.Info("webserver: stdout: " + e.Data);
                }
            });
            p.Start();
            p.BeginOutputReadLine();
            p.BeginErrorReadLine();
            if (p.WaitForExit(2000))
            {
                // If it exited there was an error
                m_log.Tell("error starting webserver: exit code = " + p.ExitCode);
            }
            m_webServerProcess = p;
        }