using System;
using System.Collections.Generic;
namespace Shared.Common
{
public class Global
{
///
/// 获取住宅文件夹下面的文件
///
/// File name.
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 FileListByHomeId()
{
var list = new List { };
var path = Config.Instance.FullPath;
if (!System.IO.Directory.Exists(path)) {
return new List { };
}
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;
}
///
/// 写文件到住宅文件夹目录
///
/// File name.
/// Bytes.
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);
}
///
/// 删除住宅下面的文件
///
/// File name.
public static void DeleteFilebyHomeId(string fileName)
{
var path = System.IO.Path.Combine(Config.Instance.FullPath, fileName);
System.IO.File.Delete(path);
}
///
/// 是否存在当前文件
///
/// File name.
public static bool IsExistsByHomeId(string fileName)
{
var path = System.IO.Path.Combine(Config.Instance.FullPath, fileName);
return System.IO.File.Exists(path);
}
///
/// 更新文件名称
///
/// Old file path.
/// New file path.
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);
}
}
}
}