Skip to content

Commit

Permalink
Important fix for Task Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
RevoLand committed Oct 8, 2017
1 parent d7e63f6 commit 43a8a34
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 32 deletions.
Binary file modified Binaries/Steam Library Manager.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion Binaries/Version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.4.0|ACF File Detection, search function and some other fixes & improvements
1.4.4.1|Important fix for Task Manager
17 changes: 9 additions & 8 deletions Source/Steam Library Manager/Definitions/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ public class TaskList : INotifyPropertyChanged
{
public Steam.AppInfo TargetApp { get; set; }
public Steam.Library TargetLibrary { get; set; }
public bool ErrorHappened = false;
public bool Moving = false;
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 _movedFileSize = 0;
private long _TotalFileSize = 0;
private bool _Completed = false;

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

public double TotalFileCount
{
Expand All @@ -40,13 +41,13 @@ public double TotalFileCount
}
}

public long MovenFileSize
public long movedFileSize
{
get => _MovenFileSize;
get => _movedFileSize;
set
{
_MovenFileSize = value;
OnPropertyChanged("MovenFileSize");
_movedFileSize = value;
OnPropertyChanged("movedFileSize");
OnPropertyChanged("ProgressBarPerc");
OnPropertyChanged("PrettyAvgSpeed");
}
Expand All @@ -66,7 +67,7 @@ public double ProgressBarPerc
{
get
{
double perc = Math.Ceiling((double)(100 * _MovenFileSize) / _TotalFileSize);
double perc = Math.Ceiling((double)(100 * _movedFileSize) / _TotalFileSize);
Main.FormAccessor.TaskbarItemInfo.ProgressValue = perc / 100;

if (perc == 100)
Expand All @@ -75,7 +76,7 @@ public double ProgressBarPerc
Main.FormAccessor.TaskbarItemInfo.ProgressValue = 0;
}

return _MovenFileSize == 0 ? 0 : perc;
return _movedFileSize == 0 ? 0 : perc;
}
}

Expand Down
42 changes: 24 additions & 18 deletions Source/Steam Library Manager/Definitions/Steam.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ private void FolderWD_Deleted(object sender, FileSystemEventArgs e)
{
if (Apps.Count(x => x.AcfName == e.Name) > 0)
{
AppInfo RemovenApp = Apps.First(x => x.AcfName == e.Name);
Apps.Remove(RemovenApp);
AppInfo RemovedApp = Apps.First(x => x.AcfName == e.Name);
Apps.Remove(RemovedApp);

if (SLM.CurrentSelectedLibrary == this)
Functions.App.UpdateAppPanel(this);
Expand Down Expand Up @@ -824,14 +824,14 @@ 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.movedFileSize += (currentFile as FileInfo).Length;

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

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

if (cancellationToken.IsCancellationRequested)
throw new OperationCanceledException(cancellationToken);
Expand All @@ -854,14 +854,14 @@ public void CopyGameFiles(List.TaskList CurrentTask, CancellationToken cancellat
currentFile.ExtractToFile(newFile.FullName, true);

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

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

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

if (cancellationToken.IsCancellationRequested)
throw new OperationCanceledException(cancellationToken);
Expand All @@ -888,14 +888,14 @@ public void CopyGameFiles(List.TaskList CurrentTask, CancellationToken cancellat
}

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

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

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

parallelOptions.MaxDegreeOfParallelism = -1;
Expand All @@ -916,14 +916,14 @@ public void CopyGameFiles(List.TaskList CurrentTask, CancellationToken cancellat
}

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

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

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

}
Expand All @@ -935,24 +935,30 @@ public void CopyGameFiles(List.TaskList CurrentTask, CancellationToken cancellat
}
catch (OperationCanceledException)
{
CurrentTask.ErrorHappened = true;
Framework.TaskManager.Stop();
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);
MessageBoxResult removemovedFiles = MessageBox.Show($"[{AppName}] Game movement cancelled. Would you like to remove files that already moved?", "Remove moved files?", MessageBoxButton.YesNo);

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

LogToTM($"[{AppName}] Operation cancelled by user. Time Elapsed: {CurrentTask.ElapsedTime.Elapsed}");
Functions.Logger.LogToFile(Functions.Logger.LogType.App, $"Operation cancelled by user. Time Elapsed: {CurrentTask.ElapsedTime.Elapsed}", this);
}
catch (Exception ex)
{
CurrentTask.ErrorHappened = true;
Framework.TaskManager.Stop();
CurrentTask.Moving = false;
CurrentTask.Completed = true;

MessageBox.Show(ex.ToString());
MessageBoxResult removeMovenFiles = MessageBox.Show($"[{AppName}] An error happened while moving game files. Would you like to remove files that already moven?", "Remove moven files?", MessageBoxButton.YesNo);
MessageBoxResult removemovedFiles = MessageBox.Show($"[{AppName}] An error happened while moving game files. Would you like to remove files that already moved?", "Remove moved files?", MessageBoxButton.YesNo);

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

Main.FormAccessor.TaskManager_Logs.Add($"[{AppName}] An error happened while moving game files. Time Elapsed: {CurrentTask.ElapsedTime.Elapsed}");
Expand Down
2 changes: 1 addition & 1 deletion Source/Steam Library Manager/Forms/Main.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ private void TaskManager_ContextMenu_Click(object sender, RoutedEventArgs e)
foreach (Definitions.List.TaskList CurrentTask in SelectedItems)
{
if (CurrentTask.Moving && Framework.TaskManager.Status && !CurrentTask.Completed)
MessageBox.Show($"[{CurrentTask.TargetApp.AppName}] You can't remove an app from Task Manager which is currently being moven.\n\nPlease Stop the Task Manager first.");
MessageBox.Show($"[{CurrentTask.TargetApp.AppName}] You can't remove an app from Task Manager which is currently being moved.\n\nPlease Stop the Task Manager first.");
else
{
Framework.TaskManager.RemoveTask(CurrentTask);
Expand Down
6 changes: 3 additions & 3 deletions Source/Steam Library Manager/Framework/TaskManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public static void ProcessTask(Definitions.List.TaskList CurrentTask)
CurrentTask.Moving = true;
CurrentTask.TargetApp.CopyGameFiles(CurrentTask, CancellationToken.Token);

if (!CancellationToken.IsCancellationRequested)
if (!CancellationToken.IsCancellationRequested && !CurrentTask.ErrorHappened)
{
if (CurrentTask.RemoveOldFiles)
{
Main.FormAccessor.TaskManager_Logs.Add($"[{DateTime.Now}] [{CurrentTask.TargetApp.AppName}] Removing moven files as requested. This may take a while, please wait.");
Main.FormAccessor.TaskManager_Logs.Add($"[{DateTime.Now}] [{CurrentTask.TargetApp.AppName}] Removing moved files as requested. This may take a while, please wait.");
CurrentTask.TargetApp.DeleteFiles();
Main.FormAccessor.TaskManager_Logs.Add($"[{DateTime.Now}] [{CurrentTask.TargetApp.AppName}] Files removen, task is completed now.");
Main.FormAccessor.TaskManager_Logs.Add($"[{DateTime.Now}] [{CurrentTask.TargetApp.AppName}] Files removed, task is completed now.");
}

if (!CurrentTask.TargetLibrary.IsBackup)
Expand Down
2 changes: 1 addition & 1 deletion Source/Steam Library Manager/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.4.6.0")]
[assembly: AssemblyFileVersion("1.4.4.1")]

0 comments on commit 43a8a34

Please sign in to comment.