2011-12-18 16:24:29 -08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2011-11-17 22:52:50 -08:00
|
|
|
using System.Web.Mvc;
|
2011-11-12 20:07:06 -08:00
|
|
|
using NzbDrone.Common;
|
2011-06-08 18:45:06 -07:00
|
|
|
|
|
|
|
namespace NzbDrone.Web.Controllers
|
|
|
|
{
|
|
|
|
public class DirectoryController : Controller
|
|
|
|
{
|
|
|
|
private readonly DiskProvider _diskProvider;
|
|
|
|
|
|
|
|
public DirectoryController(DiskProvider diskProvider)
|
|
|
|
{
|
|
|
|
_diskProvider = diskProvider;
|
|
|
|
}
|
|
|
|
|
|
|
|
[HttpPost]
|
2012-01-18 21:01:47 -08:00
|
|
|
public JsonResult _autoCompletePath(string text, int? filterMode)
|
2011-06-08 18:45:06 -07:00
|
|
|
{
|
|
|
|
var data = GetDirectories(text);
|
|
|
|
|
|
|
|
return new JsonResult
|
|
|
|
{
|
|
|
|
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
|
|
|
|
Data = data
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-06-29 23:15:06 -07:00
|
|
|
[HttpGet]
|
2011-09-08 20:26:48 -07:00
|
|
|
public JsonResult GetDirectories(string term)
|
2011-06-08 18:45:06 -07:00
|
|
|
{
|
2011-11-17 22:52:50 -08:00
|
|
|
IEnumerable<string> dirs = null;
|
2011-06-10 14:55:58 -07:00
|
|
|
try
|
2011-06-08 18:45:06 -07:00
|
|
|
{
|
2011-06-10 14:55:58 -07:00
|
|
|
//Windows (Including UNC)
|
2011-09-08 20:26:48 -07:00
|
|
|
var windowsSep = term.LastIndexOf('\\');
|
2011-06-10 14:55:58 -07:00
|
|
|
|
|
|
|
if (windowsSep > -1)
|
|
|
|
{
|
2011-09-08 20:26:48 -07:00
|
|
|
dirs = _diskProvider.GetDirectories(term.Substring(0, windowsSep + 1));
|
2011-07-01 13:59:25 -07:00
|
|
|
|
2011-06-10 14:55:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
//Unix
|
2011-09-08 20:26:48 -07:00
|
|
|
var index = term.LastIndexOf('/');
|
2011-06-10 14:55:58 -07:00
|
|
|
|
|
|
|
if (index > -1)
|
|
|
|
{
|
2011-09-08 20:26:48 -07:00
|
|
|
dirs = _diskProvider.GetDirectories(term.Substring(0, index + 1));
|
2011-06-10 14:55:58 -07:00
|
|
|
}
|
2011-06-08 18:45:06 -07:00
|
|
|
}
|
2012-02-04 22:34:36 -08:00
|
|
|
catch (Exception)
|
2011-06-08 18:45:06 -07:00
|
|
|
{
|
2011-12-18 16:24:29 -08:00
|
|
|
return Json(new List<string>(), JsonRequestBehavior.AllowGet);
|
2011-06-10 14:55:58 -07:00
|
|
|
//Swallow the exceptions so proper JSON is returned to the client (Empty results)
|
2011-06-08 18:45:06 -07:00
|
|
|
}
|
|
|
|
|
2011-07-01 13:59:25 -07:00
|
|
|
return Json(dirs, JsonRequestBehavior.AllowGet);
|
2011-06-08 18:45:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|