2016-11-14 12:17:07 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using Yavsc.Helpers;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Yavsc.ViewModels.UserFiles
|
|
|
|
|
|
{
|
|
|
|
|
|
public class UserDirectoryInfo
|
|
|
|
|
|
{
|
2016-11-14 14:09:24 +01:00
|
|
|
|
public string UserName { get; private set; }
|
2016-11-14 12:17:07 +01:00
|
|
|
|
public string SubPath { get; private set; }
|
2017-01-13 16:31:40 +01:00
|
|
|
|
public DefaultFileInfo [] Files {
|
2016-11-14 12:17:07 +01:00
|
|
|
|
get; private set;
|
|
|
|
|
|
}
|
|
|
|
|
|
public string [] SubDirectories {
|
|
|
|
|
|
get; private set;
|
|
|
|
|
|
}
|
|
|
|
|
|
private DirectoryInfo dInfo;
|
|
|
|
|
|
public UserDirectoryInfo(string username, string path)
|
|
|
|
|
|
{
|
2017-04-11 01:17:55 +02:00
|
|
|
|
if (string.IsNullOrWhiteSpace(username))
|
|
|
|
|
|
throw new NotSupportedException("No user name, no user dir.");
|
2016-11-14 14:09:24 +01:00
|
|
|
|
UserName = username;
|
2017-04-11 01:17:55 +02:00
|
|
|
|
var finalPath = username;
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(path))
|
|
|
|
|
|
finalPath += Path.DirectorySeparatorChar + path;
|
|
|
|
|
|
if (!finalPath.IsValidPath())
|
2016-11-14 12:17:07 +01:00
|
|
|
|
throw new InvalidOperationException(
|
2017-01-13 16:31:40 +01:00
|
|
|
|
$"File name contains invalid chars, using path {finalPath}");
|
2017-04-11 01:17:55 +02:00
|
|
|
|
|
2016-11-14 12:17:07 +01:00
|
|
|
|
dInfo = new DirectoryInfo(
|
2017-04-11 01:17:55 +02:00
|
|
|
|
Startup.UserFilesDirName+Path.DirectorySeparatorChar+finalPath);
|
2017-04-25 13:11:20 +02:00
|
|
|
|
if (!dInfo.Exists) dInfo.Create();
|
2016-11-14 12:17:07 +01:00
|
|
|
|
Files = dInfo.GetFiles().Select
|
2017-04-11 01:17:55 +02:00
|
|
|
|
( entry => new DefaultFileInfo { Name = entry.Name, Size = entry.Length,
|
2016-11-14 12:17:07 +01:00
|
|
|
|
CreationTime = entry.CreationTime, LastModified = entry.LastWriteTime }).ToArray();
|
2017-04-11 01:17:55 +02:00
|
|
|
|
SubDirectories = dInfo.GetDirectories().Select
|
2016-11-14 12:17:07 +01:00
|
|
|
|
( d=> d.Name ).ToArray();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-04-11 01:17:55 +02:00
|
|
|
|
}
|