2011-06-09 04:45:06 +03:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Web;
|
2011-06-30 09:15:06 +03:00
|
|
|
using System.Web.Helpers;
|
2011-06-09 04:45:06 +03:00
|
|
|
using System.Web.Mvc;
|
|
|
|
using NzbDrone.Core.Providers.Core;
|
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
{
|
|
|
|
public class DirectoryController : Controller
|
|
|
|
{
|
|
|
|
private readonly DiskProvider _diskProvider;
|
|
|
|
|
|
|
|
public DirectoryController(DiskProvider diskProvider)
|
|
|
|
{
|
|
|
|
_diskProvider = diskProvider;
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
public ActionResult _autoCompletePath(string text, int? filterMode)
|
|
|
|
{
|
|
|
|
var data = GetDirectories(text);
|
|
|
|
|
|
|
|
return new JsonResult
|
|
|
|
{
|
|
|
|
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
|
|
|
|
Data = data
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-06-30 09:15:06 +03:00
|
|
|
[HttpGet]
|
2011-09-09 06:26:48 +03:00
|
|
|
public JsonResult GetDirectories(string term)
|
2011-06-09 04:45:06 +03:00
|
|
|
{
|
2011-07-01 23:59:25 +03:00
|
|
|
string[] dirs = null;
|
2011-06-11 00:55:58 +03:00
|
|
|
try
|
2011-06-09 04:45:06 +03:00
|
|
|
{
|
2011-06-11 00:55:58 +03:00
|
|
|
//Windows (Including UNC)
|
2011-09-09 06:26:48 +03:00
|
|
|
var windowsSep = term.LastIndexOf('\\');
|
2011-06-11 00:55:58 +03:00
|
|
|
|
|
|
|
if (windowsSep > -1)
|
|
|
|
{
|
2011-09-09 06:26:48 +03:00
|
|
|
dirs = _diskProvider.GetDirectories(term.Substring(0, windowsSep + 1));
|
2011-07-01 23:59:25 +03:00
|
|
|
|
2011-06-11 00:55:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//Unix
|
2011-09-09 06:26:48 +03:00
|
|
|
var index = term.LastIndexOf('/');
|
2011-06-11 00:55:58 +03:00
|
|
|
|
|
|
|
if (index > -1)
|
|
|
|
{
|
2011-09-09 06:26:48 +03:00
|
|
|
dirs = _diskProvider.GetDirectories(term.Substring(0, index + 1));
|
2011-06-11 00:55:58 +03:00
|
|
|
}
|
2011-06-09 04:45:06 +03:00
|
|
|
}
|
2011-06-19 23:43:47 +03:00
|
|
|
catch
|
2011-06-09 04:45:06 +03:00
|
|
|
{
|
2011-06-11 00:55:58 +03:00
|
|
|
//Swallow the exceptions so proper JSON is returned to the client (Empty results)
|
2011-06-09 04:45:06 +03:00
|
|
|
}
|
|
|
|
|
2011-07-01 23:59:25 +03:00
|
|
|
return Json(dirs, JsonRequestBehavior.AllowGet);
|
2011-06-09 04:45:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|