Create methods to check whether a file/dir exists
This commit is contained in:
parent
fe2fe0befe
commit
34a11ee555
|
@ -52,7 +52,7 @@ namespace de4dot {
|
|||
}
|
||||
|
||||
void readMethodsFile() {
|
||||
if (new FileInfo(methodsFilename).Exists) {
|
||||
if (Utils.fileExists(methodsFilename)) {
|
||||
using (var reader = new BinaryReader(File.Open(methodsFilename, FileMode.Open, FileAccess.Read, FileShare.Read))) {
|
||||
dumpedMethods = new DumpedMethodsReader(reader).read();
|
||||
}
|
||||
|
|
|
@ -72,22 +72,13 @@ namespace de4dot {
|
|||
static void addIfExists(string basePath, string extraPath) {
|
||||
try {
|
||||
var path = Path.Combine(basePath, extraPath);
|
||||
if (pathExists(path))
|
||||
if (Utils.pathExists(path))
|
||||
Instance.addSearchDirectory(path);
|
||||
}
|
||||
catch (Exception) {
|
||||
}
|
||||
}
|
||||
|
||||
static bool pathExists(string path) {
|
||||
try {
|
||||
return new DirectoryInfo(path).Exists;
|
||||
}
|
||||
catch (Exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void addSearchDirectory(string dir) {
|
||||
if (!addedDirectories.ContainsKey(dir)) {
|
||||
addedDirectories[dir] = true;
|
||||
|
|
|
@ -95,7 +95,7 @@ namespace de4dot {
|
|||
miscOptions.Add(new OneArgOption("r", null, "Scan for .NET files in all subdirs", "dir", (val) => {
|
||||
addSearchDir();
|
||||
searchDir = new FilesDeobfuscator.SearchDir();
|
||||
if (!new DirectoryInfo(val).Exists)
|
||||
if (!Utils.pathExists(val))
|
||||
exitError(string.Format("Directory {0} does not exist", val));
|
||||
searchDir.InputDirectory = val;
|
||||
}));
|
||||
|
@ -152,7 +152,7 @@ namespace de4dot {
|
|||
|
||||
defaultOption = new OneArgOption("f", null, "Name of .NET file", "file", (val) => {
|
||||
addFile();
|
||||
if (!new FileInfo(val).Exists)
|
||||
if (!Utils.fileExists(val))
|
||||
exitError(string.Format("File \"{0}\" does not exist.", val));
|
||||
newFileOptions = new ObfuscatedFile.Options {
|
||||
Filename = val,
|
||||
|
@ -168,7 +168,7 @@ namespace de4dot {
|
|||
fileOptions.Add(new OneArgOption("m", null, "Name of .methods file", "file", (val) => {
|
||||
if (newFileOptions == null)
|
||||
exitError("Missing input file");
|
||||
if (!new FileInfo(val).Exists)
|
||||
if (!Utils.fileExists(val))
|
||||
exitError(string.Format("File \"{0}\" does not exist.", val));
|
||||
newFileOptions.MethodsFilename = val;
|
||||
}));
|
||||
|
|
|
@ -300,10 +300,16 @@ namespace de4dot {
|
|||
void createDirectories(string path) {
|
||||
if (string.IsNullOrEmpty(path))
|
||||
return;
|
||||
try {
|
||||
var di = new DirectoryInfo(path);
|
||||
if (!di.Exists)
|
||||
di.Create();
|
||||
}
|
||||
catch (System.Security.SecurityException) {
|
||||
}
|
||||
catch (ArgumentException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void deobfuscateAllFiles(IEnumerable<IObfuscatedFile> allFiles) {
|
||||
|
|
|
@ -198,5 +198,23 @@ namespace de4dot {
|
|||
return name;
|
||||
return name.Substring(0, i);
|
||||
}
|
||||
|
||||
public static bool pathExists(string path) {
|
||||
try {
|
||||
return new DirectoryInfo(path).Exists;
|
||||
}
|
||||
catch (Exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool fileExists(string path) {
|
||||
try {
|
||||
return new FileInfo(path).Exists;
|
||||
}
|
||||
catch (Exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user