예제 #1
0
        public FileViewModel(FilePathType filePathType)
        {
            _FilePathType = filePathType;
            IsXMLInvitation = ((_FilePathType == FilePathType.Invitation) || (_FilePathType == FilePathType.Invitation_GDC) || (_FilePathType == FilePathType.Invitation_Owners));

            switch (filePathType)
            {
                case FilePathType.Source:
                    this.DirPath = FilePathType.Source.DirPath();
                    BindEventToFSW();
                    break;
                case FilePathType.Output:
                    this.DirPath = FilePathType.Output.DirPath();
                    BindEventToFSW();
                    break;
                case FilePathType.Reports:
                    this.DirPath = FilePathType.Reports.DirPath();
                    BindEventToFSW();
                    break;
                case FilePathType.Invitation:
                    this.DirPath = FilePathType.Invitation.DirPath();
                    BindEventToFSW();
                    break;
                case FilePathType.Invitation_GDC:
                    this.DirPath = FilePathType.Invitation_GDC.DirPath();
                    BindEventToFSW();
                    break;
                case FilePathType.Invitation_Owners:
                    this.DirPath = FilePathType.Invitation_Owners.DirPath();
                    BindEventToFSW();
                    break;
            }

            this.BtnRemoveFileClick = new DelegateCommand<object>(this.OnBtnRemoveFileClick);
        }
예제 #2
0
 /// <summary>
 /// 创建文件夹
 /// </summary>
 /// <param name="folderPath"></param>
 /// <param name="type"></param>
 public static void CreateFolder(string folderPath, FilePathType type = FilePathType.dataPath)
 {
     if (!IsFolderExists(GetFullFilePath(folderPath, type)))
     {
         Directory.CreateDirectory(GetFullFilePath(folderPath, type));
         Refresh();
     }
 }
예제 #3
0
 private static string GetDefaultErrorMessage(FilePathType filePathType)
 {
     return(filePathType switch
     {
         FilePathType.File => "The file '{0}' already exists.",
         FilePathType.Directory => "The directory '{0}' already exists.",
         _ => "The file path '{0}' already exists."
     });
예제 #4
0
 /// <summary>
 /// 删除文件夹
 /// </summary>
 /// <param name="folderPath"></param>
 /// <param name="type"></param>
 public static void DeleteFolder(string folderPath, FilePathType type = FilePathType.dataPath)
 {
     if (IsFolderExists(GetFullFilePath(folderPath, type)))
     {
         Directory.Delete(GetFullFilePath(folderPath, type), true);
         Refresh();
     }
 }
예제 #5
0
 /// <summary>
 /// 复制文件
 /// </summary>
 /// <param name="srcFileName"></param>
 /// <param name="destFileName"></param>
 public static void CopyFile(string srcFileName, string destFileName, FilePathType type = FilePathType.dataPath)
 {
     if (IsFileExists(srcFileName, type) && !srcFileName.Equals(destFileName))
     {
         string folderPath = GetFullFilePath(destFileName, type);
         CreateFolder(folderPath.Substring(0, folderPath.LastIndexOf('/')));
         File.Copy(GetFullFilePath(srcFileName, type), GetFullFilePath(destFileName, type), true);
         Refresh();
     }
 }
예제 #6
0
        public static string GetAbsoluteFilePath(string filePath, FilePathType filePathType = FilePathType.Relative)
        {
            switch (filePathType)
            {
            case FilePathType.Absolute:
                return(filePath);

            case FilePathType.Relative:
                return(BaseDirectory + filePath);
            }
            return(null);
        }
예제 #7
0
    /// <summary>
    /// 写入数据到对应文件
    /// </summary>
    /// <param name="fileName"></param>
    /// <param name="contents"></param>
    public static void Write(string fileName, string contents, FilePathType type = FilePathType.dataPath)
    {
        string folderPath = GetFullFilePath(fileName, type);

        CreateFolder(folderPath.Substring(0, folderPath.LastIndexOf('\\')));
        using (StreamWriter sw = new StreamWriter(GetFullFilePath(fileName, type)))
        {
            sw.Write(contents);
            sw.Close();
        }
        Refresh();
    }
예제 #8
0
        private static string GetDefaultErrorMessage(FilePathType filePathType)
        {
            if (filePathType == FilePathType.File)
            {
                return("The file '{0}' does not exist.");
            }

            if (filePathType == FilePathType.Directory)
            {
                return("The directory '{0}' does not exist.");
            }

            return("The file path '{0}' does not exist.");
        }
예제 #9
0
    public static void CreateFile(string fileName, FilePathType type = FilePathType.dataPath)
    {
        if (!IsFileExists(fileName, type))
        {
            string folderPath = GetFullFilePath(fileName, type);
            CreateFolder(folderPath.Substring(0, folderPath.LastIndexOf('/')));
#if UNITY_4 || UNITY_5
            using (FileStream stream = File.Create(GetFullFilePath(fileName, type)))
            {
                stream.Close();
            }
#else
            File.Create(GetFullFilePath(fileName, type));
#endif
        }
    }
예제 #10
0
 /// <summary>
 /// 从对应文件读取数据
 /// </summary>
 /// <param name="fileName"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 public static string Read(string fileName, FilePathType type = FilePathType.dataPath)
 {
     if (IsFileExists(fileName, type))
     {
         using (StreamReader streamReader = new StreamReader(GetFullFilePath(fileName, type)))
         {
             string data = streamReader.ReadToEnd();
             streamReader.Close();
             return(data);
         }
         //return File.ReadAllText(GetFullFilePath(fileName, type));
     }
     else
     {
         return(string.Empty);
     }
 }
예제 #11
0
 /// <summary>
 /// 文件全目录
 /// </summary>
 /// <param name="folderPath"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 public static string GetFullFilePath(string folderPath, FilePathType type = FilePathType.dataPath)
 {
     if (type == FilePathType.dataPath)
     {
         return(Path.Combine(Application.dataPath, folderPath));
     }
     else if (type == FilePathType.persistentDataPath)
     {
         return(Path.Combine(Application.persistentDataPath, folderPath));
     }
     else if (type == FilePathType.streamingAssetsPath)
     {
         return(Path.Combine(mStreamingAssetsPath, folderPath));
     }
     else
     {
         return(Path.Combine(Application.temporaryCachePath, folderPath));
     }
 }
예제 #12
0
 public static bool IsFileLocked(string filePath, FilePathType filePathType = FilePathType.Relative)
 {
     try
     {
         var file = new FileInfo(GetAbsoluteFilePath(filePath, filePathType));
         using (var stream = file.Open(FileMode.Open, FileAccess.Read, FileShare.None))
         {
             stream.Close();
         }
     }
     catch (IOException)
     {
         return(true);
     }
     catch (Exception ex)
     {
         ErrorLogger.GenerateErrorRecord(ex);
     }
     return(false);
 }
예제 #13
0
    /// <summary>
    /// 复制文件夹
    /// </summary>
    /// <param name="srcFolderPath"></param>
    /// <param name="destFolderPath"></param>
    /// <param name="type"></param>
    public static void CopyFolder(string srcFolderPath, string destFolderPath, FilePathType type = FilePathType.dataPath)
    {
        if (!IsFolderExists(srcFolderPath, type))
        {
            DebugHelper.LogInfo(string.Format("文件夹:{0} 不存在", srcFolderPath));
            return;
        }
        CreateFolder(destFolderPath, type);
        srcFolderPath  = GetFullFilePath(srcFolderPath, type);
        destFolderPath = GetFullFilePath(destFolderPath, type);

        // 创建所有的对应目录
        foreach (string dirPath in Directory.GetDirectories(srcFolderPath, "*", SearchOption.AllDirectories))
        {
            Directory.CreateDirectory(dirPath.Replace(srcFolderPath, destFolderPath));
        }
        // 复制原文件夹下所有内容到目标文件夹,直接覆盖
        foreach (string newPath in Directory.GetFiles(srcFolderPath, "*.*", SearchOption.AllDirectories))
        {
            File.Copy(newPath, newPath.Replace(srcFolderPath, destFolderPath), true);
        }
        Refresh();
    }
예제 #14
0
 /// <summary>
 /// Initializes an instance of <see cref="FilePathExistsAttributeBase"/>.
 /// </summary>
 /// <param name="filePathType">Acceptable file path types</param>
 public FilePathExistsAttributeBase(FilePathType filePathType)
     : base(GetDefaultErrorMessage(filePathType))
 {
     _filePathType = filePathType;
 }
예제 #15
0
 public static bool FileExists(string filePath, FilePathType filePathType = FilePathType.Relative)
 {
     return(File.Exists(GetAbsoluteFilePath(filePath, filePathType)));
 }
예제 #16
0
 /// <summary>
 /// Returns true if the file is "Null" (doesn't exist) or "Empty" (Length == 0)
 /// </summary>
 public static bool IsNullOrEmpty(string filePath, FilePathType filePathType = FilePathType.Relative)
 {
     return(!FileExists(filePath, filePathType) || IsFileEmpty(filePath, filePathType));
 }
예제 #17
0
 /// <summary>
 /// 文件是否存在
 /// </summary>
 /// <param name="fileName"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 public static bool IsFileExists(string fileName, FilePathType type = FilePathType.dataPath)
 {
     return(File.Exists(GetFullFilePath(fileName, type)));
 }
예제 #18
0
 /// <summary>
 /// 检测文件夹是否存在
 /// </summary>
 /// <param name="folderPath"></param>
 /// <param name="type"></param>
 /// <returns></returns>
 private static bool IsFolderExists(string folderPath, FilePathType type = FilePathType.dataPath)
 {
     return(Directory.Exists(GetFullFilePath(folderPath, type)));
 }
 /// <summary>
 /// Initializes an instance of <see cref="FilePathNotExistsAttributeBase"/>.
 /// </summary>
 /// <param name="filePathType">Acceptable file path types</param>
 internal FilePathNotExistsAttributeBase(FilePathType filePathType)
     : base(GetDefaultErrorMessage(filePathType))
 {
     _filePathType = filePathType;
 }
예제 #20
0
 public static bool IsFileEmpty(string filePath, FilePathType filePathType = FilePathType.Relative)
 {
     return(new FileInfo(GetAbsoluteFilePath(filePath, filePathType)).Length == 0);
 }