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