Esempio n. 1
0
 private string _redirect(string folder)
 {
     for (int i = 0; i < _disks.Count; i++)
     {
         FileFolderInfo item = _disks[i];
         int            n    = _findPosition(item.name, folder);
         if (n != -1)
         {
             folder = item.path + folder.Substring(n + ("~" + item.name).Length);
             return(folder);
         }
     }
     return(folder);
 }
Esempio n. 2
0
        private void SendFolderContent(HttpListenerContext context)
        {
            //	string mime;
            try
            {
                _loadPublicFolders();
                string x      = context.Request.RawUrl.Substring("/get.folder?".Length);
                string u      = System.Web.HttpUtility.UrlDecode(x);
                string folder = System.Web.HttpUtility.ParseQueryString(u).Get("folder");

                string result = "[";
                if (folder == "root")
                {
                    for (int i = 0; i < _disks.Count; i++)
                    {
                        FileFolderInfo item = _disks[i];
                        result += (i == 0 ? "" : ",") + "{\"name\": \"~" + item.name + "\",d:1}";
                    }
                }
                else
                {
                    string   dir     = _redirect(folder + "/");
                    string   strdirs = "";
                    string[] dirs    = System.IO.Directory.GetDirectories(dir);
                    for (int i = 0; i < dirs.Length; i++)
                    {
                        string item = dirs[i].Replace('\\', '/');
                        item     = item.Substring(dir.Length);
                        strdirs += (i == 0 ? "" : ",") + "{\"name\":\"" + item + "\",d:1,size:0}";
                    }
                    string[] files    = System.IO.Directory.GetFiles(dir);
                    string   strfiles = "";
                    for (int i = 0; i < files.Length; i++)
                    {
                        string item = files[i].Replace('\\', '/');
                        long   size = new System.IO.FileInfo(item).Length;
                        item      = item.Substring(dir.Length);
                        strfiles += (i == 0 ? "" : ",") + "{\"name\":\"" + item + "\",d:0,size:" + size.ToString() + "}";
                    }
                    string mask = (strdirs.Length == 0 ? "0" : "1") + (strfiles.Length == 0 ? "0" : "1");
                    switch (mask)
                    {
                    case "00":
                        break;

                    case "01":
                        result += strfiles;
                        break;

                    case "10":
                        result += strdirs;
                        break;

                    case "11":
                        result += strdirs + "," + strfiles;
                        break;

                    default:
                        break;
                    }
                }

                result += "]";
                this.SendJson(context, result);
            }
            catch (Exception ex)
            {
                Console.WriteLine("exception : " + ex.ToString());
                context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
            }
        }