Unlink() public method

public Unlink ( string filename ) : void
filename string
return void
Beispiel #1
0
 public Compress()
 {
     var fs=new FS();
     StringBuilder sb = new StringBuilder();
     int[] lines = {0};
     var __dirname = @"C:\code\SonicImageParser\data\LevelOutput\";
     fs.Readdir(__dirname,
                (ex, ab) => {
                    foreach (var s in ab) {
                        string s1 = s;
                        fs.Readdir(__dirname + s,
                                   (ex2, ab2) => {
                                       foreach (var s2 in ab2) {
                                           Global.Console.Log(s2);
                                           string s3 = s2;
                                           fs.ReadFile(__dirname + s1 + "\\" + s2,"utf8",
                                                       (err, content) => {
                                                           if (s3.EndsWith(".min.js")) fs.Unlink(__dirname + s1 + "\\" + s3);
                                                           var fm = new Compressor().CompressText(content);
                                                         //FS.AppendFile("abcdef.js", string.Format("window.levelData[{0}] = '{1}';\r\n\r\n", lines[0]++, fm), "utf8", (ecr) => { });
                                                           var imj = ( __dirname + s1 + "\\" + s3 ).Replace(".js", ".min.js");
                                                           fs.Unlink(__dirname + s1 + "\\" + s3);
                                                           fs.WriteFile(imj, fm, (er,ecr2) => { });
                                                       });
                                       }
                                   });
                    }
                });
 }
Beispiel #2
0
        public Server()
        {
            fs = Global.Require<FS>("fs");
            var http = Global.Require<Http>("http");

            Global.SetInterval(() => { Global.Console.Log("keep alive " + new DateTime().ToString().Substring(17, 24)); }, 10 * 1000);

            //load();

            var app = http.CreateServer((req, res) => res.End());
            var io = SocketIO.Listen(app);

            string[] fileData = new string[0];
            string[] fileNames = new string[0];
            string levelsDir = "LevelData/";
            fs.Readdir(levelsDir,
                (err, files) =>
                {
                    for (int i = 0; i < files.Length; i++)
                    {
                        int i1 = i;
                        fileNames[i1] = files[i].Replace(".min.js", "");
                        Global.Console.Log(fileNames[i1] + " loaded");

                        fs.ReadFile(levelsDir + files[i], "utf8", (er, file) => { fileData[i1] = file; });
                    }
                });
            io.Set("log level", 1);
            app.Listen(8998);
            io.Sockets.On("connection",
                new Action<SocketIOConnection>((SocketIOConnection socket) =>
                                               {
                                                   int curLevel = 0;
                                                   socket.On("GetSonicLevel",
                                                       new Action<string>((levelName) =>
                                                                          {
                                                                              Global.Console.Log("Serving " + fileNames[curLevel] + "  " + curLevel);
                                                                              socket.Emit("SonicLevel", new DataObject<string>(fileData[curLevel++ % fileData.Length]));
                                                                          }));
                                                   socket.On("GetLevels.Request",
                                                       new Action(() =>
                                                                  {
                                                                      Global.Console.Log("Serving list");
                                                                      socket.Emit("GetLevels.Response", new DataObject<string[]>(fileNames));
                                                                  }));

                                                   socket.On("LoadLevel.Request",
                                                       new Action<DataObject<string>>((levelName) =>
                                                                                      {
                                                                                          Global.Console.Log("Serving Level " + levelName.Data);
                                                                                          socket.Emit("LoadLevel.Response", new DataObject<string>(fileData[fileNames.IndexOf(levelName.Data)]));
                                                                                      }));

                                                   socket.On("GetObject",
                                                       new Action<DataObject<string>>((_object) =>
                                                           fs.Exists(objDirectory + _object.Data + ".js",
                                                               (er, exists) =>
                                                                   fs.ReadFile(objDirectory + _object.Data + ".js",
                                                                       "utf8",
                                                                       (err, result) => socket.Emit("GetObject.Response", new DataObject<string>(result))))));

                                                   socket.On("SaveObject",
                                                       new Action<SaveObjectModel>((_object) =>
                                                                                   {
                                                                                       fs.Exists(objDirectory + _object.OldKey + ".js",
                                                                                           (er, exists) =>
                                                                                           {
                                                                                               if (exists)
                                                                                                   fs.Unlink(objDirectory + _object.OldKey + ".js");
                                                                                               fs.WriteFileSync(objDirectory + _object.Key + ".js", _object.Data);
                                                                                               socket.Emit("SaveObject.Response", new { Data = true });
                                                                                           });
                                                                                   }));

                                                   socket.On("GetObjects",
                                                       new Action<string[]>((_objects) =>
                                                                            {
                                                                                int ind = 0;
                                                                                socket.Emit("GetObjects.Response",
                                                                                    new
                                                                                    {
                                                                                        Data =
                                                                                            _getObjects(_objects).Select(
                                                                                                a => new { key = _objects[ind++], value = a })
                                                                                    });
                                                                            }));

                                                   socket.On("GetAllObjects",
                                                       new Action<string[]>((_objects) =>
                                                                            {
                                                                                socket.Emit("GetAllObjects.Response",
                                                                                    new
                                                                                    {
                                                                                        Data =
                                                                                            fs.ReaddirSync(objDirectory).Where(a => a.EndsWith((".js"))).Select(
                                                                                                a => a.Replace(".js", ""))
                                                                                    });
                                                                            }));


                                                   socket.On("GetAllObjectsData",
                                                       new Action(() =>
                                                                            {
                                                                                ObjectModelData[] dataObjects =
                                                                                    fs.ReaddirSync(objDirectory).Where(a => a.EndsWith((".js"))).Select(
                                                                                    a => new ObjectModelData
                                                                                    {
                                                                                        Name = a.Replace(".js", ""),
                                                                                        Data = fs.ReadFileSync(objDirectory + a, "utf8")
                                                                                    });
                                                                                Global.Console.Log("Serving objects " + dataObjects.Length);

                                                                                socket.Emit("GetAllObjectsData.Response", new DataObject<ObjectModelData[]>(dataObjects));
                                                                            }));
                                               }));
        }