예제 #1
0
        /// <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);
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
        /// <summary>
        /// 创建空目录
        /// </summary>
        /// <param name="dirPath"> 路径 </param>
        public static void CreateEmptyDir(string dirPath)
        {
            if (PathUtil.GetPathState(dirPath) != PathState.None)
            {
                PathUtil.RemovePath(dirPath);
            }

            TryCreateDir(dirPath);
        }
예제 #4
0
파일: ApkTool.cs 프로젝트: kaclr/Doodle
        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}\"");
        }
예제 #5
0
파일: ApkTool.cs 프로젝트: kaclr/Doodle
        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}\"");
        }
예제 #6
0
 public static bool Exists(string path)
 {
     return(PathUtil.GetPathState(path) == PathState.Dir);
 }