GetRelativePath() public static method

public static GetRelativePath ( string root, string fname ) : string
root string
fname string
return string
示例#1
0
        private void button2_Click(object sender, System.EventArgs e)
        {
            openFileDialog.InitialDirectory = map.FileOnDisk.Directory.FullName;
            if (openFileDialog.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
            string f = Helper.GetRelativePath(map.FileOnDisk.Directory.FullName, openFileDialog.FileName);

            t_chrfile.Text = f;
        }
示例#2
0
        private void b_browse_Click(object sender, System.EventArgs e)
        {
            openFileDialog.Filter = "Music Files (*.s3m,*.xm,*.it,*.mod,*.mp3)|*.s3m;*.xm;*.it;*.mod;*.mp3|All Files (*.*)|*.*";
            DialogResult dr = openFileDialog.ShowDialog();

            if (dr == DialogResult.Cancel)
            {
                return;
            }
            string root = Global.ActiveMap.FileOnDisk.Directory.FullName;
            string path = Helper.GetRelativePath(root, openFileDialog.FileName);

            if (path == null)
            {
                Errors.Error("Oops", "You selected a music file that wasn't in the same directory tree as your map. " + root + " : " + openFileDialog.FileName);
                return;
            }
            t_music.Text = path;
        }
示例#3
0
        public unsafe static int WriteMap(FileInfo fi, Map map)
        {
            byte[] map3_signature = new byte[] { (byte)'V', (byte)'3', (byte)'M', (byte)'A', (byte)'P', (byte)0 };
            if (map == null)
            {
                return(-1);
            }

            string vspname = Helper.GetRelativePath(map.FileOnDisk.Directory.FullName, map.vsp.FileOnDisk.FullName);

            if (vspname == null)
            {
                throw new Exception("Unable to resolve VSP path.");
            }

            fi = new FileInfo(fi.Name);
            if (fi.Exists)
            {
                fi.Delete();
            }
            FileStream   fs        = fi.OpenWrite();
            MemoryStream ms_outbuf = new MemoryStream();
            BinaryWriter bw_o      = new BinaryWriter(ms_outbuf);

            MemoryStream ms_outbuf2 = new MemoryStream();
            BinaryWriter bw         = new BinaryWriter(ms_outbuf2);

            bw_o.Write(map3_signature);
            bw_o.Write(Global.VERSIONINFO.MAPVERSION);



            bw.Write(Helper.StringToPaddedByteArray(map.FormalName, 256));
            bw.Write(Helper.StringToPaddedByteArray(vspname, 256));
            bw.Write(Helper.StringToPaddedByteArray(map.MusicFileName, 256));
            bw.Write(Helper.StringToPaddedByteArray(map.RenderString, 256));
            bw.Write(Helper.StringToPaddedByteArray(map.AutoExecEvent, 256));


            bw.Write((short)map.PlayerStartX);
            bw.Write((short)map.PlayerStartY);


            int special_count = 0;

            foreach (MapLayer ml in map.Layers)
            {
                if (ml.type != LayerType.Tile)
                {
                    special_count++;
                }
            }
            bw.Write(map.Layers.Count - special_count);

            foreach (MapLayer ml in map.Layers)
            {
                if (ml.type != LayerType.Tile)
                {
                    continue;
                }
                bw.Write(Helper.StringToPaddedByteArray(ml.name, 256));
                bw.Write(ml.parallaxInfo.MultipleX);
                bw.Write(ml.parallaxInfo.MultipleY);
                bw.Write((short)ml.Width);
                bw.Write((short)ml.Height);
                bw.Write((byte)ml.Translucency);

                fixed(short *ptr = ml.Data)
                {
                    byte[] zdata = ZLIB.Encode((byte *)ptr, ml.Data.Length * 2);
                    bw.Write(ml.Data.Length * 2);
                    bw.Write(zdata.Length);
                    bw.Write(zdata);
                }
            }

            MapLayer zl = map.ZoneLayer, ol = map.ObsLayer;

            byte[] obsdata = new byte[ol.Data.Length];
            for (int j = 0; j < ol.Data.Length; j++)
            {
                obsdata[j] = (byte)ol.Data[j];


                fixed(byte *ptr = obsdata)
                {
                    byte[] zdata = ZLIB.Encode(ptr, obsdata.Length);
                    bw.Write(obsdata.Length);
                    bw.Write(zdata.Length);
                    bw.Write(zdata);
                }

                fixed(short *ptr = zl.Data)
                {
                    byte[] zdata = ZLIB.Encode((byte *)ptr, zl.Data.Length * 2);
                    bw.Write(zl.Data.Length * 2);
                    bw.Write(zdata.Length);
                    bw.Write(zdata);
                }

                bw.Write(map.Zones.Count);
                foreach (MapZone mz in map.Zones)
                {
                    bw.Write(Helper.StringToPaddedByteArray(mz.Name, 256));
                    bw.Write(Helper.StringToPaddedByteArray(mz.PlayerScript, 256));
                    //				bw.Write(Helper.StringToPaddedByteArray(mz.EntityScript,256));
                    bw.Write((byte)mz.Rate);
                    bw.Write((byte)mz.Delay);
                    bw.Write((byte)mz.AdjAct);
                }


                bw.Write(map.Entities.Count);
                foreach (MapEntity me in map.Entities)
                {
                    bw.Write((short)me.TileX);
                    bw.Write((short)me.TileY);
                    bw.Write((byte)me.Facing);
                    bw.Write((byte)me.ObeyObstruction);
                    bw.Write((byte)me.IsObstruction);
                    bw.Write((byte)me.AutoFace);
                    bw.Write((short)me.Speed);
                    bw.Write((byte)me.ActivationMode);
                    bw.Write((byte)me.MoveType);
                    bw.Write((short)me.WanderRectangle.x0);
                    bw.Write((short)me.WanderRectangle.y0);
                    bw.Write((short)me.WanderRectangle.x1);
                    bw.Write((short)me.WanderRectangle.y1);
                    bw.Write((short)me.WanderDelay);
                    bw.Write((int)0);//expand
                    bw.Write(Helper.StringToPaddedByteArray(me.MoveScript, 256));
                    bw.Write(Helper.StringToPaddedByteArray(me.ChrName, 256));
                    bw.Write(Helper.StringToPaddedByteArray(me.Description, 256));
                    bw.Write(Helper.StringToPaddedByteArray(me.onActivate, 256));
                }


                bw_o.Write((int)14 + (int)ms_outbuf2.Length);
                bw.Close();
                bw_o.Close();
                bw = new BinaryWriter(fs);
                bw.Write(ms_outbuf.ToArray());
                bw.Write(ms_outbuf2.ToArray());

                //write number of compiled vc functions
                bw.Write((int)0);

                bw.Close();
                return(0);
        }