CreateDirectoryFromFilePath

and CreateDirectoryFromDirectoryPath
This commit is contained in:
Michael Delpach 2016-02-22 07:15:23 +08:00
parent 8d34f380ff
commit 0f17aeeec2
15 changed files with 36 additions and 36 deletions

View file

@ -54,7 +54,7 @@ public void Encode(string sourceFilePath, string targetFilePath)
targetFilePath += "." + OutputExtension.TrimStart('.');
}
Helpers.CreateDirectoryIfNotExist(targetFilePath);
Helpers.CreateDirectoryFromFilePath(targetFilePath);
using (Process process = new Process())
{

View file

@ -107,7 +107,7 @@ public static bool WriteToFile(this Stream stream, string filePath)
{
if (stream.Length > 0 && !string.IsNullOrEmpty(filePath))
{
Helpers.CreateDirectoryIfNotExist(filePath);
Helpers.CreateDirectoryFromFilePath(filePath);
using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Read))
{

View file

@ -69,7 +69,7 @@ public static bool ExtractFFmpeg(string zipPath, string extractPath)
SevenZipExtractor.SetLibraryPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "7z.dll"));
}
Helpers.CreateDirectoryIfNotExist(extractPath);
Helpers.CreateDirectoryFromFilePath(extractPath);
using (SevenZipExtractor zip = new SevenZipExtractor(zipPath))
{

View file

@ -732,27 +732,27 @@ public static bool IsFileLocked(string path)
return false;
}
public static void CreateDirectoryIfNotExist(string path, bool isFilePath = true)
public static void CreateDirectoryFromDirectoryPath(string path)
{
if (!string.IsNullOrEmpty(path) && !Directory.Exists(path))
{
try
{
Directory.CreateDirectory(path);
}
catch (Exception e)
{
DebugHelper.WriteException(e);
MessageBox.Show(Resources.Helpers_CreateDirectoryIfNotExist_Create_failed_ + "\r\n\r\n" + e, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
public static void CreateDirectoryFromFilePath(string path)
{
if (!string.IsNullOrEmpty(path))
{
if (isFilePath)
{
path = Path.GetDirectoryName(path);
}
if (!string.IsNullOrEmpty(path) && !Directory.Exists(path))
{
try
{
Directory.CreateDirectory(path);
}
catch (Exception e)
{
DebugHelper.WriteException(e);
MessageBox.Show(Resources.Helpers_CreateDirectoryIfNotExist_Create_failed_ + "\r\n\r\n" + e, "ShareX", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
CreateDirectoryFromDirectoryPath(Path.GetDirectoryName(path));
}
}
@ -767,7 +767,7 @@ public static void BackupFileMonthly(string filepath, string destinationFolder)
if (!File.Exists(newFilepath))
{
CreateDirectoryIfNotExist(newFilepath);
CreateDirectoryFromFilePath(newFilepath);
File.Copy(filepath, newFilepath, false);
}
}
@ -785,7 +785,7 @@ public static void BackupFileWeekly(string filepath, string destinationFolder)
if (!File.Exists(newFilepath))
{
CreateDirectoryIfNotExist(newFilepath);
CreateDirectoryFromFilePath(newFilepath);
File.Copy(filepath, newFilepath, false);
}
}

View file

@ -53,7 +53,7 @@ public Logger(string logFilePath)
{
FileWrite = true;
LogFilePath = logFilePath;
Helpers.CreateDirectoryIfNotExist(LogFilePath);
Helpers.CreateDirectoryFromFilePath(LogFilePath);
}
protected void OnMessageAdded(string message)

View file

@ -121,7 +121,7 @@ private static bool SaveInternal(object obj, string filePath, bool createBackup)
{
lock (obj)
{
Helpers.CreateDirectoryIfNotExist(filePath);
Helpers.CreateDirectoryFromFilePath(filePath);
string tempFilePath = filePath + ".temp";

View file

@ -93,7 +93,7 @@ public bool Append(params HistoryItem[] historyItems)
{
lock (thisLock)
{
Helpers.CreateDirectoryIfNotExist(FilePath);
Helpers.CreateDirectoryFromFilePath(FilePath);
using (FileStream fs = File.Open(FilePath, FileMode.Append, FileAccess.Write, FileShare.Read))
using (XmlTextWriter writer = new XmlTextWriter(fs, Encoding.UTF8))

View file

@ -44,7 +44,7 @@ public FFmpegCLIManager(string ffmpegPath)
Output = new StringBuilder();
OutputDataReceived += FFmpeg_DataReceived;
ErrorDataReceived += FFmpeg_DataReceived;
Helpers.CreateDirectoryIfNotExist(FFmpegPath);
Helpers.CreateDirectoryFromFilePath(FFmpegPath);
}
private void FFmpeg_DataReceived(object sender, DataReceivedEventArgs e)

View file

@ -162,7 +162,7 @@ private string GetOutputDirectory()
break;
}
Helpers.CreateDirectoryIfNotExist(directory, false);
Helpers.CreateDirectoryFromDirectoryPath(directory);
return directory;
}

View file

@ -58,7 +58,7 @@ public FFmpegHelper(ScreencastOptions options)
OutputDataReceived += FFmpegHelper_DataReceived;
ErrorDataReceived += FFmpegHelper_DataReceived;
Options = options;
Helpers.CreateDirectoryIfNotExist(Options.OutputPath);
Helpers.CreateDirectoryFromFilePath(Options.OutputPath);
}
private void FFmpegHelper_DataReceived(object sender, DataReceivedEventArgs e)

View file

@ -52,7 +52,7 @@ public int Count
public HardDiskCache(ScreencastOptions options)
{
Options = options;
Helpers.CreateDirectoryIfNotExist(Options.OutputPath);
Helpers.CreateDirectoryFromFilePath(Options.OutputPath);
fsCache = new FileStream(Options.OutputPath, FileMode.Create, FileAccess.Write, FileShare.Read);
indexList = new List<LocationInfo>();
}

View file

@ -204,7 +204,7 @@ public void SaveAsGIF(string path, GIFQuality quality)
{
if (imgCache != null && imgCache is HardDiskCache && !IsRecording)
{
Helpers.CreateDirectoryIfNotExist(path);
Helpers.CreateDirectoryFromFilePath(path);
HardDiskCache hdCache = imgCache as HardDiskCache;
@ -229,7 +229,7 @@ public void SaveAsGIF(string path, GIFQuality quality)
public bool FFmpegEncodeAsGIF(string path)
{
Helpers.CreateDirectoryIfNotExist(path);
Helpers.CreateDirectoryFromFilePath(path);
return ffmpegCli.EncodeGIF(Options.OutputPath, path);
}

View file

@ -43,7 +43,7 @@ public override UploadResult Upload(Stream stream, string fileName)
string filePath = account.GetLocalhostPath(fileName);
Helpers.CreateDirectoryIfNotExist(filePath);
Helpers.CreateDirectoryFromFilePath(filePath);
using (FileStream fs = new FileStream(filePath, FileMode.Create))
{

View file

@ -42,7 +42,7 @@ public ChromeForm()
private void CreateChromeHostManifest(string filepath)
{
Helpers.CreateDirectoryIfNotExist(filepath);
Helpers.CreateDirectoryFromFilePath(filepath);
var manifest = new
{

View file

@ -672,7 +672,7 @@ private void DoTextJobs()
if (!string.IsNullOrEmpty(filePath))
{
Info.FilePath = filePath;
Helpers.CreateDirectoryIfNotExist(Info.FilePath);
Helpers.CreateDirectoryFromFilePath(Info.FilePath);
File.WriteAllText(Info.FilePath, tempText, Encoding.UTF8);
DebugHelper.WriteLine("Text saved to file: " + Info.FilePath);
}
@ -1361,7 +1361,7 @@ private bool DownloadAndUpload()
try
{
Helpers.CreateDirectoryIfNotExist(Info.FilePath);
Helpers.CreateDirectoryFromFilePath(Info.FilePath);
using (WebClient wc = new WebClient())
{