mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
Sync Compress and RVIO with latest from RVWorld
This commit is contained in:
@@ -34,7 +34,7 @@ namespace RVIO
|
||||
}
|
||||
}
|
||||
|
||||
public static class unix
|
||||
public static class Unix
|
||||
{
|
||||
public static bool IsUnix
|
||||
{
|
||||
@@ -51,10 +51,15 @@ namespace RVIO
|
||||
public string Name;
|
||||
public string FullName;
|
||||
public long LastWriteTime;
|
||||
public long LastAccessTime;
|
||||
public long CreationTime;
|
||||
public long Length;
|
||||
|
||||
public FileInfo()
|
||||
{ }
|
||||
public FileInfo(string name, string fullName)
|
||||
{
|
||||
Name = name;
|
||||
FullName = fullName;
|
||||
}
|
||||
|
||||
public FileInfo(string path)
|
||||
{
|
||||
@@ -66,7 +71,9 @@ namespace RVIO
|
||||
if (!fi.Exists) return;
|
||||
|
||||
Length = fi.Length;
|
||||
LastWriteTime = fi.LastWriteTimeUtc.Ticks;
|
||||
try { LastWriteTime = fi.LastWriteTimeUtc.Ticks; } catch { LastWriteTime = 0; }
|
||||
try { LastAccessTime = fi.LastAccessTimeUtc.Ticks; } catch { LastAccessTime = 0; }
|
||||
try { CreationTime = fi.CreationTimeUtc.Ticks; } catch { CreationTime = 0; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,9 +82,14 @@ namespace RVIO
|
||||
public string Name;
|
||||
public string FullName;
|
||||
public long LastWriteTime;
|
||||
public long LastAccessTime;
|
||||
public long CreationTime;
|
||||
|
||||
public DirectoryInfo()
|
||||
{ }
|
||||
public DirectoryInfo(string name, string fullName)
|
||||
{
|
||||
Name = name;
|
||||
FullName = fullName;
|
||||
}
|
||||
public DirectoryInfo(string path)
|
||||
{
|
||||
FullName = path;
|
||||
@@ -87,7 +99,9 @@ namespace RVIO
|
||||
|
||||
if (!fi.Exists) return;
|
||||
|
||||
LastWriteTime = fi.LastWriteTimeUtc.Ticks;
|
||||
try { LastWriteTime = fi.LastWriteTimeUtc.Ticks; } catch { LastWriteTime = 0; }
|
||||
try { LastAccessTime = fi.LastAccessTimeUtc.Ticks; } catch { LastAccessTime = 0; }
|
||||
try { CreationTime = fi.CreationTimeUtc.Ticks; } catch { CreationTime = 0; }
|
||||
}
|
||||
|
||||
public DirectoryInfo[] GetDirectories()
|
||||
@@ -103,16 +117,19 @@ namespace RVIO
|
||||
System.IO.DirectoryInfo[] arrDi = di.GetDirectories();
|
||||
foreach (System.IO.DirectoryInfo tDi in arrDi)
|
||||
{
|
||||
DirectoryInfo lDi = new DirectoryInfo
|
||||
try
|
||||
{
|
||||
Name = tDi.Name,
|
||||
FullName = Path.Combine(FullName, tDi.Name),
|
||||
LastWriteTime = tDi.LastWriteTimeUtc.Ticks
|
||||
};
|
||||
dirs.Add(lDi);
|
||||
DirectoryInfo lDi = new DirectoryInfo(tDi.Name, Path.Combine(FullName, tDi.Name));
|
||||
try { lDi.LastWriteTime = tDi.LastWriteTimeUtc.Ticks; } catch { lDi.LastWriteTime = 0; }
|
||||
try { lDi.LastAccessTime = tDi.LastAccessTimeUtc.Ticks; } catch { lDi.LastAccessTime = 0; }
|
||||
try { lDi.CreationTime = tDi.CreationTimeUtc.Ticks; } catch { lDi.CreationTime = 0; }
|
||||
|
||||
dirs.Add(lDi);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
@@ -132,17 +149,19 @@ namespace RVIO
|
||||
System.IO.FileInfo[] arrDi = di.GetFiles(SearchPattern);
|
||||
foreach (System.IO.FileInfo tDi in arrDi)
|
||||
{
|
||||
FileInfo lDi = new FileInfo
|
||||
try
|
||||
{
|
||||
Name = tDi.Name,
|
||||
FullName = Path.Combine(FullName, tDi.Name),
|
||||
Length = tDi.Length,
|
||||
LastWriteTime = tDi.LastWriteTimeUtc.Ticks
|
||||
};
|
||||
files.Add(lDi);
|
||||
FileInfo lFi = new FileInfo(tDi.Name, Path.Combine(FullName, tDi.Name)) { Length = tDi.Length };
|
||||
try { lFi.LastWriteTime = tDi.LastWriteTimeUtc.Ticks; } catch { lFi.LastWriteTime = 0; }
|
||||
try { lFi.LastAccessTime = tDi.LastAccessTimeUtc.Ticks; } catch { lFi.LastAccessTime = 0; }
|
||||
try { lFi.CreationTime = tDi.CreationTimeUtc.Ticks; } catch { lFi.CreationTime = 0; }
|
||||
|
||||
files.Add(lFi);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
@@ -201,6 +220,16 @@ namespace RVIO
|
||||
|
||||
}
|
||||
|
||||
public static void WriteAllBytes(string path, byte[] data)
|
||||
{
|
||||
System.IO.File.WriteAllBytes(NameFix.AddLongPathPrefix(path), data);
|
||||
}
|
||||
public static void WriteAllText(string path, string contents)
|
||||
{
|
||||
System.IO.File.WriteAllText(NameFix.AddLongPathPrefix(path), contents);
|
||||
}
|
||||
|
||||
|
||||
public static bool SetAttributes(string path, FileAttributes fileAttributes)
|
||||
{
|
||||
try
|
||||
@@ -224,6 +253,15 @@ namespace RVIO
|
||||
int errorCode = FileStream.OpenFileRead(filename, out Stream fStream);
|
||||
return errorCode != 0 ? null : new StreamReader(fStream, Enc);
|
||||
}
|
||||
|
||||
public static string ReadAllText(string filename)
|
||||
{
|
||||
return System.IO.File.ReadAllText(NameFix.AddLongPathPrefix(filename));
|
||||
}
|
||||
public static byte[] ReadAllBytes(string filename)
|
||||
{
|
||||
return System.IO.File.ReadAllBytes(NameFix.AddLongPathPrefix(filename));
|
||||
}
|
||||
}
|
||||
|
||||
public static class Path
|
||||
@@ -234,7 +272,12 @@ namespace RVIO
|
||||
|
||||
public static char DirSeparatorChar
|
||||
{
|
||||
get { return unix.IsUnix ? AltDirectorySeparatorChar : DirectorySeparatorChar; }
|
||||
get { return Unix.IsUnix ? AltDirectorySeparatorChar : DirectorySeparatorChar; }
|
||||
}
|
||||
|
||||
public static string FixSlash(string path)
|
||||
{
|
||||
return !Unix.IsUnix ? path : path.Replace(DirectorySeparatorChar, AltDirectorySeparatorChar);
|
||||
}
|
||||
|
||||
public static string GetExtension(string path)
|
||||
@@ -243,7 +286,7 @@ namespace RVIO
|
||||
}
|
||||
public static string Combine(string path1, string path2)
|
||||
{
|
||||
if (unix.IsUnix)
|
||||
if (Unix.IsUnix)
|
||||
return System.IO.Path.Combine(path1, path2);
|
||||
|
||||
if (path1 == null || path2 == null)
|
||||
@@ -312,10 +355,10 @@ namespace RVIO
|
||||
stream = new System.IO.FileStream(NameFix.AddLongPathPrefix(path), FileMode.Open, FileAccess.Read);
|
||||
return 0;
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception e)
|
||||
{
|
||||
stream = null;
|
||||
return Marshal.GetLastWin32Error();
|
||||
return e.HResult;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,55 +369,19 @@ namespace RVIO
|
||||
stream = new System.IO.FileStream(NameFix.AddLongPathPrefix(path), FileMode.Create, FileAccess.ReadWrite);
|
||||
return 0;
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception e)
|
||||
{
|
||||
stream = null;
|
||||
return Marshal.GetLastWin32Error();
|
||||
return e.HResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class NameFix
|
||||
{
|
||||
public static string GetShortPath(string path)
|
||||
public static string AddLongPathPrefix(string path)
|
||||
{
|
||||
if (unix.IsUnix)
|
||||
return path;
|
||||
|
||||
int remove = 0;
|
||||
string retPath;
|
||||
if (path.StartsWith(@"\\"))
|
||||
{
|
||||
retPath = @"\\?\UNC\" + path.Substring(2);
|
||||
remove = 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
retPath = path;
|
||||
if (path.Substring(1, 1) != ":")
|
||||
retPath = Path.Combine(System.IO.Directory.GetCurrentDirectory(), retPath);
|
||||
|
||||
retPath = cleandots(retPath);
|
||||
retPath = @"\\?\" + retPath;
|
||||
remove = 4;
|
||||
}
|
||||
|
||||
const int MAX_PATH = 300;
|
||||
StringBuilder shortPath = new StringBuilder(MAX_PATH);
|
||||
Win32Native.GetShortPathName(retPath, shortPath, MAX_PATH);
|
||||
retPath = shortPath.ToString();
|
||||
|
||||
retPath = retPath.Substring(remove);
|
||||
if (remove == 8) retPath = "\\" + retPath;
|
||||
|
||||
return retPath;
|
||||
}
|
||||
|
||||
|
||||
|
||||
internal static string AddLongPathPrefix(string path)
|
||||
{
|
||||
if (unix.IsUnix)
|
||||
if (Unix.IsUnix)
|
||||
return path;
|
||||
|
||||
if (string.IsNullOrEmpty(path) || path.StartsWith(@"\\?\"))
|
||||
@@ -387,12 +394,12 @@ namespace RVIO
|
||||
if (path.Substring(1, 1) != ":")
|
||||
retPath = Path.Combine(System.IO.Directory.GetCurrentDirectory(), retPath);
|
||||
|
||||
retPath = cleandots(retPath);
|
||||
retPath = CleanDots(retPath);
|
||||
|
||||
return @"\\?\" + retPath;
|
||||
}
|
||||
|
||||
private static string cleandots(string path)
|
||||
private static string CleanDots(string path)
|
||||
{
|
||||
string retPath = path;
|
||||
while (retPath.Contains(@"\..\"))
|
||||
@@ -409,4 +416,4 @@ namespace RVIO
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
/******************************************************
|
||||
* ROMVault3 is written by Gordon J. *
|
||||
* Contact gordon@romvault.com *
|
||||
* Copyright 2020 *
|
||||
* Copyright 2022 *
|
||||
******************************************************/
|
||||
|
||||
using System;
|
||||
|
||||
Reference in New Issue
Block a user