Skip to content

Commit

Permalink
v1.4.4 release
Browse files Browse the repository at this point in the history
Fixed task manager
  • Loading branch information
RevoLand committed Aug 21, 2017
1 parent 12fc3dc commit 10c847a
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 75 deletions.
Binary file modified Binaries/Steam Library Manager.exe
Binary file not shown.
73 changes: 35 additions & 38 deletions Source/Steam Library Manager/Definitions/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,15 @@ public List<FileSystemInfo> GetWorkshopFiles()
return WorkShopPath.EnumerateFileSystemInfos("*", SearchOption.AllDirectories).Where(x => x is FileInfo).ToList();
}

public void CopyGameFiles(List.TaskList currentTask, CancellationToken cancellationToken)
public void CopyGameFiles(List.TaskList CurrentTask, CancellationToken cancellationToken)
{
LogToTM($"[{AppName}] Populating file list, please wait");
Functions.Logger.LogToFile(Functions.Logger.LogType.Game, "Populating file list", this);

ConcurrentBag<string> CopiedFiles = new ConcurrentBag<string>();
ConcurrentBag<string> CreatedDirectories = new ConcurrentBag<string>();
List<FileSystemInfo> GameFiles = GetFileList();
currentTask.TotalFileCount = GameFiles.Count;
System.Diagnostics.Stopwatch ElapsedTime = new System.Diagnostics.Stopwatch();
CurrentTask.TotalFileCount = GameFiles.Count;

try
{
Expand All @@ -230,16 +229,16 @@ public void CopyGameFiles(List.TaskList currentTask, CancellationToken cancellat
Interlocked.Add(ref TotalFileSize, (file as FileInfo).Length);
});

currentTask.TotalFileSize = TotalFileSize;
ElapsedTime.Start();
CurrentTask.TotalFileSize = TotalFileSize;
CurrentTask.ElapsedTime.Start();

LogToTM($"[{AppName}] File list populated, total files to move: {GameFiles.Count} - total size to move: {Functions.FileSystem.FormatBytes(TotalFileSize)}");
Functions.Logger.LogToFile(Functions.Logger.LogType.Game, $"File list populated, total files to move: {GameFiles.Count} - total size to move: {Functions.FileSystem.FormatBytes(TotalFileSize)}", this);

// If the game is not compressed and user would like to compress it
if (!IsCompressed && currentTask.Compress)
if (!IsCompressed && CurrentTask.Compress)
{
FileInfo compressedArchive = new FileInfo(CompressedArchiveName.FullName.Replace(InstalledLibrary.SteamAppsFolder.FullName, currentTask.TargetLibrary.SteamAppsFolder.FullName));
FileInfo compressedArchive = new FileInfo(CompressedArchiveName.FullName.Replace(InstalledLibrary.SteamAppsFolder.FullName, CurrentTask.TargetLibrary.SteamAppsFolder.FullName));

if (compressedArchive.Exists)
compressedArchive.Delete();
Expand All @@ -255,26 +254,26 @@ public void CopyGameFiles(List.TaskList currentTask, CancellationToken cancellat
compressed.CreateEntryFromFile(currentFile.FullName, newFileName, CompressionLevel.Optimal);

//CopiedFiles.Add(newFileName);
currentTask.MovenFileSize += (currentFile as FileInfo).Length;
CurrentTask.MovenFileSize += (currentFile as FileInfo).Length;

if (currentTask.ReportFileMovement)
if (CurrentTask.ReportFileMovement)
{
LogToTM($"[{AppName}][{CopiedFiles.Count}/{currentTask.TotalFileCount}] Moven file: {newFileName}");
LogToTM($"[{AppName}][{CopiedFiles.Count}/{CurrentTask.TotalFileCount}] Moven file: {newFileName}");
}

Functions.Logger.LogToFile(Functions.Logger.LogType.Game, $"[{CopiedFiles.Count}/{currentTask.TotalFileCount}] Moven file: {newFileName}", this);
Functions.Logger.LogToFile(Functions.Logger.LogType.Game, $"[{CopiedFiles.Count}/{CurrentTask.TotalFileCount}] Moven file: {newFileName}", this);

if (cancellationToken.IsCancellationRequested)
throw new OperationCanceledException(cancellationToken);
}
}
}
// If the game is compressed and user would like to decompress it
else if (IsCompressed && !currentTask.Compress)
else if (IsCompressed && !CurrentTask.Compress)
{
foreach (ZipArchiveEntry currentFile in ZipFile.OpenRead(CompressedArchiveName.FullName).Entries)
{
FileInfo newFile = new FileInfo(Path.Combine(currentTask.TargetLibrary.SteamAppsFolder.FullName, currentFile.FullName));
FileInfo newFile = new FileInfo(Path.Combine(CurrentTask.TargetLibrary.SteamAppsFolder.FullName, currentFile.FullName));

if (!newFile.Directory.Exists)
{
Expand All @@ -285,14 +284,14 @@ public void CopyGameFiles(List.TaskList currentTask, CancellationToken cancellat
currentFile.ExtractToFile(newFile.FullName, true);

CopiedFiles.Add(newFile.FullName);
currentTask.MovenFileSize += currentFile.Length;
CurrentTask.MovenFileSize += currentFile.Length;

if (currentTask.ReportFileMovement)
if (CurrentTask.ReportFileMovement)
{
LogToTM($"[{AppName}][{CopiedFiles.Count}/{currentTask.TotalFileCount}] Moven file: {newFile.FullName}");
LogToTM($"[{AppName}][{CopiedFiles.Count}/{CurrentTask.TotalFileCount}] Moven file: {newFile.FullName}");
}

Functions.Logger.LogToFile(Functions.Logger.LogType.Game, $"[{CopiedFiles.Count}/{currentTask.TotalFileCount}] Moven file: {newFile.FullName}", this);
Functions.Logger.LogToFile(Functions.Logger.LogType.Game, $"[{CopiedFiles.Count}/{CurrentTask.TotalFileCount}] Moven file: {newFile.FullName}", this);

if (cancellationToken.IsCancellationRequested)
throw new OperationCanceledException(cancellationToken);
Expand All @@ -305,7 +304,7 @@ public void CopyGameFiles(List.TaskList currentTask, CancellationToken cancellat

Parallel.ForEach(GameFiles.Where(x => (x as FileInfo).Length > Properties.Settings.Default.ParallelAfterSize * 1000000).OrderByDescending(x => (x as FileInfo).Length), parallelOptions, currentFile =>
{
FileInfo newFile = new FileInfo(currentFile.FullName.Replace(InstalledLibrary.SteamAppsFolder.FullName, currentTask.TargetLibrary.SteamAppsFolder.FullName));
FileInfo newFile = new FileInfo(currentFile.FullName.Replace(InstalledLibrary.SteamAppsFolder.FullName, CurrentTask.TargetLibrary.SteamAppsFolder.FullName));

if (!newFile.Exists || (newFile.Length != (currentFile as FileInfo).Length || newFile.LastWriteTime != (currentFile as FileInfo).LastWriteTime))
{
Expand All @@ -319,22 +318,21 @@ public void CopyGameFiles(List.TaskList currentTask, CancellationToken cancellat
}

CopiedFiles.Add(newFile.FullName);
currentTask.MovenFileSize += (currentFile as FileInfo).Length;
CurrentTask.MovenFileSize += (currentFile as FileInfo).Length;

if (currentTask.ReportFileMovement)
if (CurrentTask.ReportFileMovement)
{
LogToTM($"[{AppName}][{CopiedFiles.Count}/{currentTask.TotalFileCount}] Moven file: {newFile.FullName}");
LogToTM($"[{AppName}][{CopiedFiles.Count}/{CurrentTask.TotalFileCount}] Moven file: {newFile.FullName}");
}

Functions.Logger.LogToFile(Functions.Logger.LogType.Game, $"[{CopiedFiles.Count}/{currentTask.TotalFileCount}] Moven file: {newFile.FullName}", this);
Functions.Logger.LogToFile(Functions.Logger.LogType.Game, $"[{CopiedFiles.Count}/{CurrentTask.TotalFileCount}] Moven file: {newFile.FullName}", this);
});

parallelOptions.MaxDegreeOfParallelism = new Random().Next(6, 12);
LogToTM($"Parallelism degree: {parallelOptions.MaxDegreeOfParallelism}");
parallelOptions.MaxDegreeOfParallelism = -1;

Parallel.ForEach(GameFiles.Where(x => (x as FileInfo).Length <= Properties.Settings.Default.ParallelAfterSize * 1000000).OrderByDescending(x => (x as FileInfo).Length), parallelOptions, currentFile =>
{
FileInfo newFile = new FileInfo(currentFile.FullName.Replace(InstalledLibrary.SteamAppsFolder.FullName, currentTask.TargetLibrary.SteamAppsFolder.FullName));
FileInfo newFile = new FileInfo(currentFile.FullName.Replace(InstalledLibrary.SteamAppsFolder.FullName, CurrentTask.TargetLibrary.SteamAppsFolder.FullName));

if (!newFile.Exists || (newFile.Length != (currentFile as FileInfo).Length || newFile.LastWriteTime != (currentFile as FileInfo).LastWriteTime))
{
Expand All @@ -348,37 +346,36 @@ public void CopyGameFiles(List.TaskList currentTask, CancellationToken cancellat
}

CopiedFiles.Add(newFile.FullName);
currentTask.MovenFileSize += (currentFile as FileInfo).Length;
CurrentTask.MovenFileSize += (currentFile as FileInfo).Length;

if (currentTask.ReportFileMovement)
if (CurrentTask.ReportFileMovement)
{
LogToTM($"[{AppName}][{CopiedFiles.Count}/{currentTask.TotalFileCount}] Moven file: {newFile.FullName}");
LogToTM($"[{AppName}][{CopiedFiles.Count}/{CurrentTask.TotalFileCount}] Moven file: {newFile.FullName}");
}

Functions.Logger.LogToFile(Functions.Logger.LogType.Game, $"[{CopiedFiles.Count}/{currentTask.TotalFileCount}] Moven file: {newFile.FullName}", this);
Functions.Logger.LogToFile(Functions.Logger.LogType.Game, $"[{CopiedFiles.Count}/{CurrentTask.TotalFileCount}] Moven file: {newFile.FullName}", this);
});

}

CurrentTask.ElapsedTime.Stop();

ElapsedTime.Stop();

LogToTM($"[{AppName}] Time elapsed: {ElapsedTime.Elapsed} - Average speed: {Math.Round(((TotalFileSize / 1024f) / 1024f) / ElapsedTime.Elapsed.TotalSeconds, 3)} MB/sec - Average file size: {Functions.FileSystem.FormatBytes(TotalFileSize / (long)currentTask.TotalFileCount)}");
Functions.Logger.LogToFile(Functions.Logger.LogType.Game, $"Movement completed in {ElapsedTime.Elapsed} with Average Speed of {Math.Round(((TotalFileSize / 1024f) / 1024f) / ElapsedTime.Elapsed.TotalSeconds, 3)} MB/sec - Average file size: {Functions.FileSystem.FormatBytes(TotalFileSize / (long)currentTask.TotalFileCount)}", this);
LogToTM($"[{AppName}] Time elapsed: {CurrentTask.ElapsedTime.Elapsed} - Average speed: {Math.Round(((TotalFileSize / 1024f) / 1024f) / CurrentTask.ElapsedTime.Elapsed.TotalSeconds, 3)} MB/sec - Average file size: {Functions.FileSystem.FormatBytes(TotalFileSize / (long)CurrentTask.TotalFileCount)}");
Functions.Logger.LogToFile(Functions.Logger.LogType.Game, $"Movement completed in {CurrentTask.ElapsedTime.Elapsed} with Average Speed of {Math.Round(((TotalFileSize / 1024f) / 1024f) / CurrentTask.ElapsedTime.Elapsed.TotalSeconds, 3)} MB/sec - Average file size: {Functions.FileSystem.FormatBytes(TotalFileSize / (long)CurrentTask.TotalFileCount)}", this);
}
catch (OperationCanceledException)
{
Framework.TaskManager.Stop();
currentTask.Moving = false;
currentTask.Completed = true;
CurrentTask.Moving = false;
CurrentTask.Completed = true;

MessageBoxResult removeMovenFiles = MessageBox.Show($"[{AppName}] Game movement cancelled. Would you like to remove files that already moven?", "Remove moven files?", MessageBoxButton.YesNo);

if (removeMovenFiles == MessageBoxResult.Yes)
Functions.FileSystem.RemoveGivenFiles(CopiedFiles, CreatedDirectories);

LogToTM($"[{AppName}] Operation cancelled by user. Time Elapsed: {ElapsedTime.Elapsed}");
Functions.Logger.LogToFile(Functions.Logger.LogType.Game, $"Operation cancelled by user. Time Elapsed: {ElapsedTime.Elapsed}", this);
LogToTM($"[{AppName}] Operation cancelled by user. Time Elapsed: {CurrentTask.ElapsedTime.Elapsed}");
Functions.Logger.LogToFile(Functions.Logger.LogType.Game, $"Operation cancelled by user. Time Elapsed: {CurrentTask.ElapsedTime.Elapsed}", this);
}
catch (Exception ex)
{
Expand All @@ -388,7 +385,7 @@ public void CopyGameFiles(List.TaskList currentTask, CancellationToken cancellat
if (removeMovenFiles == MessageBoxResult.Yes)
Functions.FileSystem.RemoveGivenFiles(CopiedFiles, CreatedDirectories);

Main.Accessor.TaskManager_Logs.Add($"[{AppName}] An error happened while moving game files. Time Elapsed: {ElapsedTime.Elapsed}");
Main.Accessor.TaskManager_Logs.Add($"[{AppName}] An error happened while moving game files. Time Elapsed: {CurrentTask.ElapsedTime.Elapsed}");
Functions.Logger.LogToFile(Functions.Logger.LogType.SLM, $"[{AppName}][{AppID}][{AcfName}] {ex}");
}
}
Expand Down
18 changes: 17 additions & 1 deletion Source/Steam Library Manager/Definitions/Library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public void UpdateGameList()
};

FolderWD.Created += FolderWD_Created;
FolderWD.Changed += FolderWD_Changed;
FolderWD.Deleted += FolderWD_Deleted;

if (IsBackup)
Expand Down Expand Up @@ -256,13 +257,28 @@ private void FolderWD_Created(object sender, FileSystemEventArgs e)
}
}

private void FolderWD_Changed(object sender, FileSystemEventArgs e)
{
try
{
FolderWD_Deleted(sender, e);
FolderWD_Created(sender, e);
}
catch (Exception ex)
{
Debug.WriteLine(ex);
Functions.Logger.LogToFile(Functions.Logger.LogType.Library, ex.ToString());
}
}

private void FolderWD_Deleted(object sender, FileSystemEventArgs e)
{
try
{
if (Games.Count(x => x.AcfName == e.Name) > 0)
{
Games.Remove(Games.First(x => x.AcfName == e.Name));
Game GameToRemove = Games.First(x => x.AcfName == e.Name);
Games.Remove(GameToRemove);

if (SLM.selectedLibrary == this)
Functions.Games.UpdateMainForm(this, Properties.Settings.Default.SearchText);
Expand Down
9 changes: 7 additions & 2 deletions Source/Steam Library Manager/Definitions/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ public class TaskList : INotifyPropertyChanged
public bool Compress { get; set; } = Properties.Settings.Default.Global_Compress;
public bool RemoveOldFiles { get; set; } = Properties.Settings.Default.Global_RemoveOldFiles;
public bool ReportFileMovement { get; set; } = Properties.Settings.Default.Global_ReportFileMovement;
public System.Diagnostics.Stopwatch ElapsedTime = new System.Diagnostics.Stopwatch();

private double _TotalFileCount = 100;

private long _MovenFileSize = 0;
private long _TotalFileSize = 0;

private bool _Completed = false;

public string PrettyAvgSpeed
{
get => _MovenFileSize == 0 ? "" : $"{Math.Round(((_MovenFileSize / 1024f) / 1024f) / ElapsedTime.Elapsed.TotalSeconds, 3)} MB/sec";
}

public double TotalFileCount
{
get => _TotalFileCount;
Expand All @@ -47,6 +51,7 @@ public long MovenFileSize
_MovenFileSize = value;
OnPropertyChanged("MovenFileSize");
OnPropertyChanged("ProgressBarPerc");
OnPropertyChanged("PrettyAvgSpeed");
}
}

Expand Down
Loading

0 comments on commit 10c847a

Please sign in to comment.