Skip to content

Commit

Permalink
Merge pull request #2 from franc6/franc6_issue_3
Browse files Browse the repository at this point in the history
Stop using explicit \ as directory separator
  • Loading branch information
floele committed Mar 2, 2019
2 parents e3fe6de + ac39a06 commit ac918aa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
12 changes: 8 additions & 4 deletions ApplicationJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace Ketarin
public class ApplicationJob
{
private string m_Name;
private string m_TargetPath = string.Empty;
private DateTime? m_LastUpdated;
private UrlVariableCollection m_Variables;
private bool m_ShareApplication;
Expand Down Expand Up @@ -665,7 +666,7 @@ public bool TargetIsFolder
{
if (string.IsNullOrEmpty(this.TargetPath)) return false;

return this.TargetPath.EndsWith("\\") || Directory.Exists(this.TargetPath);
return this.TargetPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal);
}
}

Expand Down Expand Up @@ -694,7 +695,10 @@ public bool TargetIsFolder
}

[XmlElement("TargetPath")]
public string TargetPath { get; set; } = string.Empty;
public string TargetPath {
get { return m_TargetPath; }
set { m_TargetPath = PathEx.FixDirectorySeparator(value); }
}

[XmlElement("FixedDownloadUrl")]
public string FixedDownloadUrl { get; set; } = string.Empty;
Expand Down Expand Up @@ -1481,10 +1485,10 @@ public void Save()
try
{
Uri uri1 = new Uri(this.PreviousLocation);
Uri uri2 = new Uri(Application.StartupPath + "\\");
Uri uri2 = new Uri(Application.StartupPath + Path.DirectorySeparatorChar);

Uri relativeUri = uri2.MakeRelativeUri(uri1);
string relativePath = relativeUri.ToString().Replace("/", "\\");
string relativePath = PathEx.FixDirectorySeparator(relativeUri.ToString());
// If result returns out to be not relative, no need to save
if (!Path.IsPathRooted(relativePath))
{
Expand Down
2 changes: 1 addition & 1 deletion CDBurnerXP/Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private static string LogFilePath
{
get
{
string dir = Path.Combine(PathEx.TryGetFolderPath(Environment.SpecialFolder.ApplicationData), "Canneverbe Limited\\CDBurnerXP");
string dir = Path.Combine(PathEx.TryGetFolderPath(Environment.SpecialFolder.ApplicationData), "Canneverbe Limited", "CDBurnerXP");
Directory.CreateDirectory(dir);

return Path.Combine(dir, "Errors.log");
Expand Down
23 changes: 16 additions & 7 deletions CDBurnerXP/PathEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,17 @@ public static string GetFullPath(string basePath, string file)
{
if (Path.IsPathRooted(file))
{
file = file.Replace("/", "\\");
file = PathEx.FixDirectorySeparator(file);

if (file.StartsWith("\\\\"))
{
// UNC path
return file;
}
else if (file.StartsWith("\\"))
else if (file.StartsWith(Path.DirectorySeparatorChar.ToString()))
{
// If path is rooted relatively, combine with playlist file location
return Path.Combine(Path.GetPathRoot(basePath), file.TrimStart('\\'));
return Path.Combine(Path.GetPathRoot(basePath), file.TrimStart(Path.DirectorySeparatorChar));
}
else
{
Expand Down Expand Up @@ -273,18 +273,27 @@ public static bool IsExtension(string fileName, string ext)

public static string GetLastPathItem(string strPath)
{
return strPath.Substring(strPath.LastIndexOf("\\") + 1);
return Path.GetFileName(strPath);
}

public static string FixDirectorySeparator(string sPath)
{
if (Path.DirectorySeparatorChar == '/')
return sPath.Replace('\\', Path.DirectorySeparatorChar);

return sPath.Replace('/', Path.DirectorySeparatorChar);
}

public static string QualifyPath(string sPath)
{
if (sPath.EndsWith("\\"))
sPath = FixDirectorySeparator(sPath);
if (sPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
{
return sPath;
}
else
{
return sPath + "\\";
return sPath + Path.DirectorySeparatorChar;
}
}

Expand Down Expand Up @@ -457,7 +466,7 @@ public static string TryGetFolderPath(Environment.SpecialFolder folder)
key = key.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders");
if ((key != null) & (key.GetValue(folderName) != null))
{
result = key.GetValue(folderName).ToString().TrimEnd('\\');
result = key.GetValue(folderName).ToString().TrimEnd(Path.DirectorySeparatorChar);
}
}
catch (Exception)
Expand Down
2 changes: 1 addition & 1 deletion DbManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public static SQLiteConnection NewConnection
if (m_DatabasePath == null)
{
// Only determine the path once
string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\Ketarin\\jobs.db";
string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Ketarin", "jobs.db");
// Is a special path set in the registry?
string regPath = Settings.GetValue("Ketarin", "DatabasePath", "") as string;
if (!string.IsNullOrEmpty(regPath) && File.Exists(regPath))
Expand Down

0 comments on commit ac918aa

Please sign in to comment.