/// <summary> /// 尝试创建目录,会创建所有需要的父级目录 /// </summary> /// <param name="path"> 路径 </param> /// <param name="force"> 是否覆盖,如果覆盖,则当路径中存在文件时会删除它再创建需要的文件夹。 </param> /// <returns></returns> public static bool TryCreateDir(string dirPath, bool force = false) { var create = false; var dirs = dirPath.Split('/', '\\'); var rootPath = Path.GetPathRoot(dirPath); for (int i = string.IsNullOrEmpty(rootPath) ? 0 : 1; i < dirs.Length; ++i) { var dir = dirs[i]; var fullPathDir = rootPath + dir; var state = PathUtil.GetPathState(fullPathDir); if (state == PathState.File) { if (force) { PathUtil.TryRemovePath(fullPathDir); } else { throw new DoodleException("a file in the dirPath!"); } } if (state == PathState.None) { Directory.CreateDirectory(fullPathDir); create = true; } rootPath += dir + Path.DirectorySeparatorChar; } return(create); }
/// <summary> /// 创建目录,路径不为空则报错 /// </summary> public static void CreateDir(string dirPath) { if (PathUtil.GetPathState(dirPath) != PathState.None) { throw new DoodleException(string.Format("dirPath '{0}' already exists!", dirPath)); } TryCreateDir(dirPath); }
/// <summary> /// 创建空目录 /// </summary> /// <param name="dirPath"> 路径 </param> public static void CreateEmptyDir(string dirPath) { if (PathUtil.GetPathState(dirPath) != PathState.None) { PathUtil.RemovePath(dirPath); } TryCreateDir(dirPath); }
public static void UnpackAPK(string apkPath, string outputDir) { InitInner(); if (!File.Exists(apkPath)) { throw new DoodleException($"'{nameof(apkPath)}' with value '{apkPath}' is invalid, can't find any file!"); } if (PathUtil.GetPathState(outputDir) != PathState.None) { throw new DoodleException(string.Format("outputDir '{0}' already exists, please use a empty path!", outputDir)); } s_apkToolScript.Execute($"d -o \"{outputDir}\" \"{apkPath}\""); }
public static void PackAPK(string apkDir, string outputApk) { InitInner(); if (PathUtil.GetPathState(apkDir) != PathState.Dir) { throw new NotDirException(apkDir, nameof(apkDir)); } if (PathUtil.GetPathState(outputApk) != PathState.None) { throw new NotEmptyPathException(outputApk, nameof(outputApk)); } s_apkToolScript.Execute($"empty-framework-dir"); s_apkToolScript.Execute($"b -o \"{outputApk}\" \"{apkDir}\""); }
public static bool Exists(string path) { return(PathUtil.GetPathState(path) == PathState.Dir); }