コード例 #1
0
 public Form1(int w, int h, bool mx, bool sz, string nm)
 {
     InitializeComponent();
     try
     {
         byte[]       ic = ResourceLocator.getResources().getResource("favicon.ico");
         MemoryStream ms = new MemoryStream(ic);
         this.Icon = new System.Drawing.Icon(ms);
         ms.Close();
     }
     catch (Exception)
     {
         this.Icon = System.Drawing.Icon.ExtractAssociatedIcon(Application.ExecutablePath);
     }
     Text = nm;
     if (!sz)
     {
         FormBorderStyle = FormBorderStyle.FixedSingle;
         MaximizeBox     = false;
     }
     if (mx)
     {
         WindowState = FormWindowState.Maximized;
     }
     else
     {
         Width  = w;
         Height = h;
     }
     webBrowser1.Navigate("http://localhost:34567/");
     obj = this;
 }
コード例 #2
0
        public void applymap(int m)
        {
            string     fl   = maps[m].fname;
            FileStream fin  = new FileStream(fl, FileMode.Open);
            FileStream fout = new FileStream(fl + ".tmp", FileMode.Create);

            foreach (MapCmd c in maps[m].cmds)
            {
                StreamCopy(fin, fout, c.ofs - (int)fin.Position);
                fin.Position += c.oldsz;
                switch (c.cmd)
                {
                case MapCmd.Cmd.INSERT_RES:
                    byte[] data = ResourceLocator.getResources().getResource(c.sdata);
                    fout.Write(data, 0, data.Length);
                    break;

                case MapCmd.Cmd.INSERT_VALUE:
                    fout.Write(c.bdata, 0, c.bdata.Length);
                    break;

                case MapCmd.Cmd.INSERT_FILE:
                    FileStream fs = new FileStream(c.sdata, FileMode.Open);
                    StreamCopy(fs, fout, (int)fs.Length);
                    fs.Close();
                    break;
                }
            }
            StreamCopy(fin, fout, (int)(fin.Length - fin.Position));
            fin.Close();
            fout.Close();
            File.Delete(fl);
            File.Move(fl + ".tmp", fl);
        }
コード例 #3
0
        public string resopen(Paths p, Parameters prms)
        {
            string fn = getParam(prms, "res");
            int    i  = getId();

            xfiles.Add(i, new FileDescr(ResourceLocator.getResources().getResource(fn)));
            return(retIdSize(i, (int)xfiles[i].ms.Length));
        }
コード例 #4
0
        public string getResName(Parameters prms)
        {
            string nm = getParam(prms, "res");

            if (!ResourceLocator.getResources().hasResource(nm))
            {
                throw new NoResException(nm);
            }
            return(nm);
        }
コード例 #5
0
        public string mapres(Paths p, Parameters prms)
        {
            int    m     = getMap(prms);
            string rname = getResName(prms);

            int[] os = getOfsOsz(prms);
            maps[m].cmds.Add(new MapCmd(MapCmd.Cmd.INSERT_RES, os[0], os[1], rname));
            uint rsize = ResourceLocator.getResources().resSize(rname);

            Logger.getLogger().dbg("map " + m.ToString() + " res " + rname + " ofs=0x" + os[0].ToString("X"));
            return(retDelta((int)rsize, os));
        }
コード例 #6
0
        public static void OnRequests(IAsyncResult res)
        {
            HttpListenerContext con = null;

            try
            {
                con = ((HttpListener)res.AsyncState).EndGetContext(res);
            }
            catch (Exception ex)
            {
                Logger.getLogger().dbg("SVR ERROR:" + ex.Message);
                return;
            }
            lastcon = DateTime.Now;
            String what = con.Request.RawUrl;

            if (what == "/")
            {
                what = "/index.html";
            }
            byte[] buffer = null;
            string tp     = "";

            if (what.StartsWith("/api/"))
            {
                tp   = "application/json; encoding=UTF-8";
                what = what.Remove(0, 5);
                if (what != "hb")
                {
                    buffer = InstApi.getApi().process(what);
                }
                else
                {
                    buffer = Encoding.UTF8.GetBytes("{r:0}");
                }
                con.Response.AddHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT");
                con.Response.AddHeader("Cache-Control", "no-store, no-cache, must-revalidate");
                //con.Response.AddHeader("Expires", "-1");
                con.Response.AddHeader("Pragma", "no-cache");
            }
            else
            {
                what = what.Split('?')[0].Remove(0, 1);
                Logger.getLogger().dbg("request " + what);
                try
                {
                    buffer = ResourceLocator.getResources().getResource(what);
                }
                catch (Exception)
                {
                    try
                    {
                        con.Response.StatusCode = 404;
                        con.Response.Close();
                    }
                    catch (Exception)
                    {
                    }
                    return;
                }
                string ext = Path.GetExtension(what).Remove(0, 1);
                switch (ext)
                {
                case "html":
                case "xml":
                case "css":
                    tp = "text/" + ext + "; charset=UTF-8";
                    break;

                case "jpg":
                    tp = "image/jpeg";
                    break;

                case "bmp":
                case "png":
                    tp = "image/" + ext;
                    break;

                case "js":
                    tp = "application/javascript; charset=UTF-8";
                    break;

                case "mid":
                    tp = "audio/midi";
                    break;

                case "wav":
                    tp = "audio/x-wav";
                    break;
                }
            }
            try
            {
                con.Response.ContentType     = tp;
                con.Response.ContentLength64 = buffer.Length;
                con.Response.OutputStream.Write(buffer, 0, buffer.Length);
                con.Response.OutputStream.Close();
                con.Response.Close();
            }
            catch (Exception)
            {
                try
                {
                    con.Response.Close();
                }
                catch (Exception)
                {
                }
            }
        }
コード例 #7
0
 public string getsize(Paths p, Parameters prms)
 {
     return(retOK((int)ResourceLocator.getResources().resSize(getResName(prms))));
 }
コード例 #8
0
 public byte[] getRes(Parameters prms)
 {
     return(ResourceLocator.getResources().getResource(getResName(prms)));
 }
コード例 #9
0
 public string hasres(Paths p, Parameters prms)
 {
     return(retOK(ResourceLocator.getResources().hasResource(getParam(prms, "res"))));
 }
コード例 #10
0
ファイル: Program.cs プロジェクト: winterheart/game-utilities
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            bool   window = false;
            int    w      = 0;
            int    h      = 0;
            bool   mx     = false;
            bool   sz     = false;
            string nm     = "installer";
            bool   dbg    = false;
            bool   con    = false;
            bool   log    = false;

            try{
                ResourceLocator.locateReader();
                XmlDocument doc  = ResourceLocator.readXmlResource("install.cfg", "icfg");
                XmlNode     root = doc.DocumentElement;
                nm     = root.Attributes["nm"].Value;
                window = (root.Attributes["w"] != null);
                if (window)
                {
                    string ws = root.Attributes["w"].Value;
                    if (ws == "mx")
                    {
                        mx = true;
                    }
                    else
                    {
                        w = int.Parse(ws);
                        h = int.Parse(root.Attributes["h"].Value);
                    }
                    sz = (root.Attributes["sz"] != null);
                }
                if (root.Attributes["l"] != null)
                {
                    int lgs = int.Parse(root.Attributes["l"].Value);
                    dbg = (lgs & 1) != 0;
                    con = (lgs & 2) != 0;
                    log = (lgs & 4) != 0;
                }
                Logger.getLogger().setOptions(log, con, dbg);
            }catch (Exception ex)
            {
                MessageBox.Show("ERROR:" + ex.GetType().Name + "\r\n" + ex.Message);
                return;
            }
            Logger.getLogger().dbg("config loaded 4 app " + nm);
            Logger.getLogger().dbg("starting server");
            Server.getServer().start();
#if !NO_EXPLORER
            if (window)
            {
                try
                {
                    Application.Run(new Form1(w, h, mx, sz, nm));
                }
                catch (Exception ex)
                {
                    MessageBox.Show("ERROR  " + ex.Message);
                    Application.Run(new BrowserController());
                }
            }
            else
#endif
            Application.Run(new BrowserController());
            Logger.getLogger().dbg("stopping server");
            Server.getServer().stop();
            Logger.getLogger().free();
        }