using System;
|
using System.Collections.Generic;
|
|
namespace Shared.Common
|
{
|
public class Global
|
{
|
/// <summary>
|
/// 获取住宅文件夹下面的文件
|
/// </summary>
|
/// <param name="fileName">File name.</param>
|
public static byte[] ReadFileByHomeId(string fileName)
|
{
|
|
var path = System.IO.Path.Combine(Config.Instance.FullPath, fileName);
|
return Shared.IO.FileUtils.ReadFile(path);
|
}
|
|
public static List<string> FileListByHomeId()
|
{
|
var list = new List<string> { };
|
var path = Config.Instance.FullPath;
|
if (!System.IO.Directory.Exists(path)) {
|
return new List<string> { };
|
}
|
var files = System.IO.Directory.GetFiles(path);
|
foreach (var file in files)
|
{
|
var f = file.Substring(path.Length + 1);
|
System.Console.WriteLine(f);
|
list.Add(f);
|
}
|
return list;
|
}
|
|
/// <summary>
|
/// 写文件到住宅文件夹目录
|
/// </summary>
|
/// <param name="fileName">File name.</param>
|
/// <param name="bytes">Bytes.</param>
|
public static void WriteFileByBytesByHomeId(string fileName, byte[] bytes)
|
{
|
//如果没有存在住宅目录,先创建
|
if (!System.IO.Directory.Exists(Config.Instance.FullPath))
|
{
|
System.IO.Directory.CreateDirectory(Config.Instance.FullPath);
|
}
|
var path = System.IO.Path.Combine(Config.Instance.FullPath, fileName);
|
Shared.IO.FileUtils.WriteFileByBytes(path, bytes);
|
}
|
/// <summary>
|
/// 删除住宅下面的文件
|
/// </summary>
|
/// <param name="fileName">File name.</param>
|
public static void DeleteFilebyHomeId(string fileName)
|
{
|
var path = System.IO.Path.Combine(Config.Instance.FullPath, fileName);
|
System.IO.File.Delete(path);
|
}
|
|
/// <summary>
|
/// 是否存在当前文件
|
/// </summary>
|
/// <param name="fileName">File name.</param>
|
public static bool IsExistsByHomeId(string fileName)
|
{
|
var path = System.IO.Path.Combine(Config.Instance.FullPath, fileName);
|
return System.IO.File.Exists(path);
|
}
|
|
/// <summary>
|
/// 更新文件名称
|
/// </summary>
|
/// <param name="oldFilePath">Old file path.</param>
|
/// <param name="newFilePath">New file path.</param>
|
public static void ReNameFileByHomeId(string oldFilePath, string newFilePath)
|
{
|
if (oldFilePath == newFilePath)
|
{
|
return;
|
}
|
|
var fileInfo = new System.IO.FileInfo(Config.Instance.FullPath + oldFilePath);
|
if (fileInfo.Exists)
|
{
|
DeleteFilebyHomeId(newFilePath);
|
fileInfo.MoveTo(Config.Instance.FullPath + newFilePath);
|
}
|
}
|
|
public static void CreateHomeDirectory(string homeId)
|
{
|
var path= System.IO.Path.Combine(Shared.IO.FileUtils.RootPath, Config.Instance.Guid, homeId);
|
if (!System.IO.Directory.Exists(path))
|
{
|
System.IO.Directory.CreateDirectory(path);
|
}
|
}
|
}
|
}
|