Skip to content

Commit

Permalink
Remove unused codes (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
gyk4j authored Feb 5, 2024
1 parent cbb6af2 commit 85b62b4
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 423 deletions.
36 changes: 0 additions & 36 deletions JShim/Java/NIO/File/Files.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ private static FileVisitResult VisitDirectory(DirectoryInfo dir, FileVisitor vis
return result;

return result;

// TODO: Shift processing logic to FileVisitor
// DateTime? creation, lastWrite, lastAccess;
// Extract(dir, out creation, out lastWrite, out lastAccess);
// Correct(dir, creation, lastWrite, lastAccess);
}

private static FileVisitResult VisitFile(FileInfo file, FileVisitor visitor)
Expand All @@ -135,37 +130,6 @@ private static FileVisitResult VisitFile(FileInfo file, FileVisitor visitor)

result = visitor.VisitFile(file);
return result;

// TODO: Shift processing logic to FileVisitor
/*
DateTime? creation, lastWrite, lastAccess;
IEnumerator<IFileDateable> e = this.parsers.Values.GetEnumerator();
while(e.MoveNext())
{
IFileDateable parser = e.Current;
try
{
parser.GetDateTimes(file, out creation, out lastWrite, out lastAccess);
}
catch(ApplicationException ex)
{
creation = lastWrite = lastAccess = null;
log.Error(ex);
}
if(creation.HasValue || lastWrite.HasValue || lastAccess.HasValue)
{
// Backup and restore Read-Only attribute prior to updating any
// timestamps.
bool readOnly = file.IsReadOnly;
file.IsReadOnly = false;
Correct(file, creation, lastWrite, lastAccess);
file.IsReadOnly = readOnly;
}
creation = lastWrite = lastAccess = null;
}
*/
}
}
}
3 changes: 1 addition & 2 deletions JShim/Javax/Swing/SwingWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public void Publish(params V[] chunks)
{
foreach(V chunk in chunks)
{
// FIXME: Calculate the progress percentage.
// Progress percentage is updated in derived classes' Process.
backgroundWorker.ReportProgress(progress, chunk);
}
}
Expand All @@ -380,7 +380,6 @@ public void RemovePropertyChangeListener(PropertyChangeListener listener)
/// </summary>
public void Run()
{
// TODO: Need to check difference between Execute() and Run().
if(!cancelled)
result = DoInBackground();
}
Expand Down
2 changes: 1 addition & 1 deletion Wreck/IO/Reader/Fs/DirectoryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public override string[] Accessed()
return LATEST;
}

// FIXME: Somehow using DirectoryInfo as key always fail to get. So using full path name string.
// HACK: get always fail with DirectoryInfo as key. Using full path name string as substitute.
private readonly IDictionary<string, List<DateTime>> fileTimes = new Dictionary<string, List<DateTime>>();

public void Add(DirectoryInfo dir, IDictionary<CorrectionEnum, DateTime> suggestions)
Expand Down
4 changes: 0 additions & 4 deletions Wreck/Service/PreviewService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,6 @@ public ITask Run(
throw new ArgumentException("Unknown correction mode");
}

// TODO: To update factory method to instantiate ProgressWorker sub-class implementations
// ProgressWorker pw = new ProgressWorker(task, startPath);
// pw.addPropertyChangeListener(pcl); // Belongs to Java Beans
// pw.execute(); // Belongs to Java SwingWorker
return task;
}
}
Expand Down
264 changes: 1 addition & 263 deletions Wreck/Wreck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,271 +16,9 @@ namespace Wreck
/// <summary>
/// Description of Wreck.
/// </summary>
public class Wreck : IDisposable
public class Wreck //: IDisposable
{
public const string NAME = "WRECK.NET";
public const string VERSION = "1.00a";

private static readonly ILog log = LogManager.GetLogger(typeof(Wreck));

private ILogger logger;

private Statistics stats;
public enum FileInfoTools {
ExifTool,
MediaInfo,
SevenZip
};
private Dictionary<FileInfoTools, IFileDateable> parsers;
private ICorrector corrector;

public Wreck(ILogger logger, ICorrector corrector)
{
this.logger = logger;
this.stats = new Statistics();

this.parsers = new Dictionary<FileInfoTools, IFileDateable>();

try
{
this.parsers.Add(FileInfoTools.ExifTool, new ExifToolParser());
}
catch(ApplicationException ex)
{
log.Error(ex);
}

this.parsers.Add(FileInfoTools.MediaInfo, new MediaInfoParser());
this.parsers.Add(FileInfoTools.SevenZip, new SevenZipParser());

this.corrector = corrector;
}

public void Dispose()
{
IFileDateable exifToolParser;
if(this.parsers.TryGetValue(FileInfoTools.ExifTool, out exifToolParser))
{
((ExifToolParser) exifToolParser).Dispose();
}

GC.SuppressFinalize(this);
}

public Statistics GetStatistics()
{
return stats;
}

public void Walk(string startingPath)
{
FileSystemInfo start;

if(Directory.Exists(startingPath))
start = new DirectoryInfo(startingPath);
else if(File.Exists(startingPath))
start = new FileInfo(startingPath);
else
throw new IOException(startingPath + " is neither directory or file.");

// TODO: Migrate to using PreviewService and ProgressWorker
FileVisitor visitor = new Wreck.EchoFileVisitor(this);
Files.WalkFileTree(start, visitor);
}

// HACK: To be replaced by actual implementation.
public class EchoFileVisitor : SimpleFileVisitor
{
private Wreck outer;

public EchoFileVisitor(Wreck outer)
{
this.outer = outer;
}

public override FileVisitResult PreVisitDirectory(DirectoryInfo dir)
{
log.InfoFormat("PreVisitDirectory: {0}", dir.FullName);

outer.logger.CurrentDirectory(dir);

return base.PreVisitDirectory(dir);
}

public override FileVisitResult VisitFile(FileInfo file)
{
log.InfoFormat("VisitFile: {0}", file.Name);

outer.logger.CurrentFile(file);
outer.stats.Count(file);

return base.VisitFile(file);
}

public override FileVisitResult VisitFileFailed(FileSystemInfo file, IOException exc)
{
log.ErrorFormat("VisitFileFailed: {0}, Exception: {1}", file.FullName, exc.Message);

if(file is FileInfo)
{
outer.stats.Skip((FileInfo) file);
outer.logger.SkipReparsePoint((FileInfo) file);
}
else if(file is DirectoryInfo)
{
outer.stats.Skip((DirectoryInfo) file);
outer.logger.SkipReparsePoint((DirectoryInfo) file);
}
else
outer.logger.UnknownPathType(file.FullName);

return base.VisitFileFailed(file, exc);
}

public override FileVisitResult PostVisitDirectory(DirectoryInfo dir, IOException exc)
{
log.InfoFormat("PostVisitDirectory: {0}", dir.FullName);

outer.stats.Count(dir);

return base.PostVisitDirectory(dir, exc);
}
}

/// <summary>
/// Extract metadata by piping a file or directory through the
/// appropriate third party tool(s) e.g. exiftool, mediainfo.
///
/// Extracted metadata time are returned in creation, lastWrite and
/// lastAccess passed by reference. Null value reflects absence of
/// usable metadata date time tag or value.
/// </summary>
/// <param name="fsi">FileSystemInfo object representing a file or directory</param>
/// <param name="creation">Metadata creation time</param>
/// <param name="lastWrite">Metadata modification time</param>
/// <param name="lastAccess">Metadata access time</param>
public void Extract(
FileSystemInfo fsi,
out DateTime? creation,
out DateTime? lastWrite,
out DateTime? lastAccess)
{
// TODO: To be updated with real metadata extraction calls
DateTime test = new DateTime(1980, 1, 1, 0, 0, 0);
creation = test;
lastWrite = test;
lastAccess = test;
}

/// <summary>
/// Correct the creation, last write and last access file time according
/// to precedence order: embedded metadata, or relative to last write
/// time.
///
/// Creation time will be reset to last write time if it is a copy that
/// reflects the copying date time.
///
/// Last Access time will be reset to last write time as a conservative
/// estimate of the active time period of use, rather than some sporadic
/// random access reset by ad-hoc document retrievals.
/// </summary>
/// <param name="fsi">FileSystemInfo object representing a file or directory</param>
/// <param name="creation">Metadata creation time</param>
/// <param name="lastWrite">Metadata modification time</param>
/// <param name="lastAccess">Metadata access time</param>
public void Correct(
FileSystemInfo fsi,
DateTime? creation,
DateTime? lastWrite,
DateTime? lastAccess)
{
// Fix modification time.
try
{
if (lastWrite.HasValue && !fsi.LastWriteTime.Equals(lastWrite.Value))
{
corrector.ByLastWriteMetadata(fsi, lastWrite.Value);
logger.CorrectedByLastWriteMetadata(fsi, lastWrite.Value);
}
}
catch(UnauthorizedAccessException ex)
{
logger.UnauthorizedAccessException(ex);
}


// Fix creation time using specified time,
try
{
if (creation.HasValue && !fsi.CreationTime.Equals(creation.Value))
{
corrector.ByCreationMetadata(fsi, creation.Value);
logger.CorrectedByCreationMetadata(fsi, creation.Value);
}
}
catch(UnauthorizedAccessException ex)
{
logger.UnauthorizedAccessException(ex);
}

// Fix access time using specified time, or from modified time.
try
{
if (lastAccess.HasValue && !fsi.LastAccessTime.Equals(lastAccess.Value))
{
corrector.ByLastAccessMetadata(fsi, lastAccess.Value);
logger.CorrectedByLastAccessMetadata(fsi, lastAccess.Value);
}
}
catch(UnauthorizedAccessException ex)
{
logger.UnauthorizedAccessException(ex);
}

// Fix creation time from modified time.
// Creation time will always be earlier than modification time.
/*
try
{
if (fsi.CreationTime.CompareTo(fsi.LastWriteTime) > 0)
{
corrector.ByLastWriteTime(fsi, fsi.CreationTime);
logger.CorrectedByLastWriteTime(fsi, fsi.CreationTime);
}
}
catch(UnauthorizedAccessException ex)
{
logger.UnauthorizedAccessException(ex);
}
*/
// Fix last access time from modified time.
// Last access time will always be earlier than modification time.
/*
try
{
if(fsi.LastAccessTime.CompareTo(fsi.LastWriteTime) > 0)
{
corrector.ByLastWriteTime(fsi, fsi.LastAccessTime);
logger.CorrectedByLastWriteTime(fsi, fsi.LastAccessTime);
}
}
catch(UnauthorizedAccessException ex)
{
logger.UnauthorizedAccessException(ex);
}
*/
}

/// <summary>
/// Does nothing for now after the file system time stamps are corrected.
/// Perhaps for some future post-processing tasks like:
/// - packaging into a ZIP archive
/// - generating a file manifest or hash file like md5sum
/// </summary>
public void Keep()
{

}
}
}
3 changes: 0 additions & 3 deletions WreckCli/Controller/CliController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,15 @@ private void Run(CorrectionMode mode, string[] args)
continue;
}

// FIXME: More like MakeTask or CreateTask
Dictionary<SourceEnum, bool> sources = new Dictionary<SourceEnum, bool>();
foreach(SourceEnum s in SourceEnum.Values)
{
// FIXME: To check GUI control checkbox
sources.Add(s, true);
}

Dictionary<CorrectionEnum, bool> corrections = new Dictionary<CorrectionEnum, bool>();
foreach(CorrectionEnum c in CorrectionEnum.Values)
{
// FIXME: To check GUI control checkbox
corrections.Add(c, true);
}

Expand Down
Loading

0 comments on commit 85b62b4

Please sign in to comment.