mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-29 17:02:05 +13:00
Code refactor
This commit is contained in:
parent
10f4d202c5
commit
f7db2733a2
2 changed files with 11 additions and 15 deletions
|
@ -152,17 +152,19 @@ public static string GetFilenameSafe(string filePath)
|
|||
return filePath;
|
||||
}
|
||||
|
||||
public static string ChangeFilenameExtension(string filePath, string extension)
|
||||
public static string ChangeFilenameExtension(string fileName, string extension)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(filePath) && !string.IsNullOrEmpty(extension))
|
||||
if (!string.IsNullOrEmpty(fileName))
|
||||
{
|
||||
int pos = filePath.LastIndexOf('.');
|
||||
int pos = fileName.LastIndexOf('.');
|
||||
|
||||
if (pos >= 0)
|
||||
{
|
||||
filePath = filePath.Remove(pos);
|
||||
fileName = fileName.Remove(pos);
|
||||
}
|
||||
|
||||
extension = extension.Trim();
|
||||
if (!string.IsNullOrEmpty(extension))
|
||||
{
|
||||
pos = extension.LastIndexOf('.');
|
||||
|
||||
if (pos >= 0)
|
||||
|
@ -170,11 +172,11 @@ public static string ChangeFilenameExtension(string filePath, string extension)
|
|||
extension = extension.Substring(pos + 1);
|
||||
}
|
||||
|
||||
return filePath + "." + extension;
|
||||
return fileName + "." + extension;
|
||||
}
|
||||
}
|
||||
|
||||
return filePath;
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public static string AppendExtension(string filePath, string extension)
|
||||
|
|
|
@ -733,14 +733,8 @@ private void DoFileJobs()
|
|||
Info.FilePath = fileAction.Run(Info.FilePath);
|
||||
}
|
||||
|
||||
if (Path.HasExtension(Info.FilePath))
|
||||
{
|
||||
Info.FileName = Path.ChangeExtension(fileName, Path.GetExtension(Info.FilePath));
|
||||
}
|
||||
else
|
||||
{
|
||||
Info.FileName = Path.GetFileNameWithoutExtension(fileName);
|
||||
}
|
||||
string extension = Helpers.GetFilenameExtension(Info.FilePath);
|
||||
fileName = Helpers.ChangeFilenameExtension(fileName, extension);
|
||||
|
||||
LoadFileStream();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue