2016-11-14 12:17:07 +01:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
2018-01-16 13:35:54 +01:00
|
|
|
|
using Yavsc.Abstract.FileSystem;
|
2016-11-14 12:17:07 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Yavsc.ViewModels.UserFiles
|
|
|
|
|
|
{
|
|
|
|
|
|
public class UserDirectoryInfo
|
|
|
|
|
|
{
|
2018-01-26 13:51:09 +01:00
|
|
|
|
public string UserName { get; set; }
|
|
|
|
|
|
public string SubPath { get; set; }
|
2018-01-16 13:35:54 +01:00
|
|
|
|
public RemoteFileInfo [] Files {
|
2018-01-26 13:51:09 +01:00
|
|
|
|
get; set;
|
2016-11-14 12:17:07 +01:00
|
|
|
|
}
|
2018-01-26 13:51:09 +01:00
|
|
|
|
public DirectoryShortInfo [] SubDirectories {
|
|
|
|
|
|
get; set;
|
2016-11-14 12:17:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
private DirectoryInfo dInfo;
|
2018-01-26 13:51:09 +01:00
|
|
|
|
|
|
|
|
|
|
// for deserialization
|
|
|
|
|
|
public UserDirectoryInfo()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2018-01-16 13:35:54 +01:00
|
|
|
|
public UserDirectoryInfo(string userReposPath, string username, string path)
|
2016-11-14 12:17:07 +01:00
|
|
|
|
{
|
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;
|
2018-01-16 13:35:54 +01:00
|
|
|
|
if (!finalPath.IsValidYavscPath())
|
2016-11-14 12:17:07 +01:00
|
|
|
|
throw new InvalidOperationException(
|
2018-12-12 12:32:09 +00:00
|
|
|
|
$"File name contains invalid chars ({finalPath})");
|
2017-04-11 01:17:55 +02:00
|
|
|
|
|
2016-11-14 12:17:07 +01:00
|
|
|
|
dInfo = new DirectoryInfo(
|
2018-08-05 04:16:21 +02:00
|
|
|
|
userReposPath+Path.DirectorySeparatorChar+finalPath);
|
2018-07-30 09:41:41 +02:00
|
|
|
|
if (dInfo.Exists) {
|
|
|
|
|
|
|
|
|
|
|
|
Files = dInfo.GetFiles().Select
|
|
|
|
|
|
( entry => new RemoteFileInfo { Name = entry.Name, Size = entry.Length,
|
|
|
|
|
|
CreationTime = entry.CreationTime, LastModified = entry.LastWriteTime }).ToArray();
|
|
|
|
|
|
SubDirectories = dInfo.GetDirectories().Select
|
|
|
|
|
|
( d=> new DirectoryShortInfo { Name= d.Name, IsEmpty=false } ).ToArray();
|
2018-08-05 04:16:21 +02:00
|
|
|
|
}
|
|
|
|
|
|
else {
|
|
|
|
|
|
// don't return null, but empty arrays
|
|
|
|
|
|
Files = new RemoteFileInfo[0];
|
|
|
|
|
|
SubDirectories = new DirectoryShortInfo[0];
|
2018-07-30 09:41:41 +02:00
|
|
|
|
}
|
2016-11-14 12:17:07 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-01-26 13:51:09 +01:00
|
|
|
|
|
|
|
|
|
|
public class DirectoryShortInfo: IDirectoryShortInfo {
|
|
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
|
public bool IsEmpty { get; set; }
|
|
|
|
|
|
}
|
2017-04-11 01:17:55 +02:00
|
|
|
|
}
|