Skip to content

Commit

Permalink
Skip deleting livelyproperty directory if not present & some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
rocksdanister committed Oct 25, 2023
1 parent add3278 commit 6f89a4e
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Lively/Lively.Common/Helpers/Files/FileOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public static async Task CopyFileAsync(string src, string dest)
/// <param name="initialDelay"></param>
/// <param name="retryDelay"></param>
/// <returns>True if deletion completed succesfully.</returns>
public static async Task<bool> DeleteDirectoryAsync(string folderPath, int initialDelay = 1000, int retryDelay = 4000)
public static async Task<bool> TryDeleteDirectoryAsync(string folderPath, int initialDelay, int retryDelay)
{
bool status = true;
if (Directory.Exists(folderPath))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ await Task.Run(async() =>
ErrorText = $"{i18n.GetString("TextError")}: {ex.Message}";
PreviewText = string.Empty;

await FileOperations.DeleteDirectoryAsync(destDir, 0, 1000);
await FileOperations.TryDeleteDirectoryAsync(destDir, 0, 1000);
}
finally
{
Expand Down
8 changes: 4 additions & 4 deletions src/Lively/Lively.UI.WinUI/ViewModels/LibraryViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public async Task WallpaperDelete(ILibraryModel obj, bool unsubscribe = true)
//close if running.
await desktopCore.CloseWallpaper(obj, true);
//delete wp folder.
var success = await FileOperations.DeleteDirectoryAsync(obj.LivelyInfoFolderPath, 1000, 4000);
var success = await FileOperations.TryDeleteDirectoryAsync(obj.LivelyInfoFolderPath, 1000, 4000);

if (success)
{
Expand All @@ -298,7 +298,7 @@ public async Task WallpaperDelete(ILibraryModel obj, bool unsubscribe = true)
var item = new DirectoryInfo(wpdataDir[i]).Name;
if (wpFolderName.Equals(item, StringComparison.Ordinal))
{
_ = FileOperations.DeleteDirectoryAsync(wpdataDir[i], 100, 1000);
_ = FileOperations.TryDeleteDirectoryAsync(wpdataDir[i], 100, 1000);
break;
}
}
Expand Down Expand Up @@ -367,7 +367,7 @@ await Task.Run(() =>
}
finally
{
_ = FileOperations.DeleteDirectoryAsync(tmpDir, 1000, 2000);
_ = FileOperations.TryDeleteDirectoryAsync(tmpDir, 1000, 2000);
}
}
else if (libraryItem.LivelyInfo.IsAbsolutePath)
Expand Down Expand Up @@ -420,7 +420,7 @@ await Task.Run(() =>
}
finally
{
_ = FileOperations.DeleteDirectoryAsync(tmpDir, 1000, 2000);
_ = FileOperations.TryDeleteDirectoryAsync(tmpDir, 1000, 2000);
}
}
else
Expand Down
6 changes: 3 additions & 3 deletions src/Lively/Lively.UI.WinUI/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1220,9 +1220,9 @@ await Task.Run(() =>
if (!isDestEmptyDir)
{
//not deleting the root folder, what if the user selects a folder that is not used by Lively alone!
var result1 = await FileOperations.DeleteDirectoryAsync(Path.Combine(previousDirectory, Constants.CommonPartialPaths.WallpaperInstallDir), 1000, 3000);
var result2 = await FileOperations.DeleteDirectoryAsync(Path.Combine(previousDirectory, Constants.CommonPartialPaths.WallpaperInstallTempDir), 0, 1000);
var result3 = await FileOperations.DeleteDirectoryAsync(Path.Combine(previousDirectory, Constants.CommonPartialPaths.WallpaperSettingsDir), 0, 1000);
var result1 = await FileOperations.TryDeleteDirectoryAsync(Path.Combine(previousDirectory, Constants.CommonPartialPaths.WallpaperInstallDir), 1000, 3000);
var result2 = await FileOperations.TryDeleteDirectoryAsync(Path.Combine(previousDirectory, Constants.CommonPartialPaths.WallpaperInstallTempDir), 0, 1000);
var result3 = await FileOperations.TryDeleteDirectoryAsync(Path.Combine(previousDirectory, Constants.CommonPartialPaths.WallpaperSettingsDir), 0, 1000);
if (!(result1 && result2 && result3))
{
//TODO: Dialogue
Expand Down
2 changes: 1 addition & 1 deletion src/Lively/Lively.UI.WinUI/ViewModels/ThemeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ private async Task BrowseTheme()
{
SelectedItem = SelectedItem != obj ? SelectedItem : Themes[0];
Themes.Remove(obj);
await FileOperations.DeleteDirectoryAsync(Directory.GetParent(obj.File).FullName);
await FileOperations.TryDeleteDirectoryAsync(Directory.GetParent(obj.File).FullName, 1000, 4000);
}
});

Expand Down
19 changes: 14 additions & 5 deletions src/Lively/Lively/Core/WinDesktopCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public async Task SetWallpaperAsync(ILibraryModel wallpaper, IDisplayMonitor dis
{
WallpaperUpdated?.Invoke(this, new WallpaperUpdateArgs() { Category = UpdateWallpaperType.remove, Info = wallpaper.LivelyInfo, InfoPath = wallpaper.LivelyInfoFolderPath });
//Deleting from core because incase UI client not running.
_ = FileOperations.DeleteDirectoryAsync(wallpaper.LivelyInfoFolderPath, 0, 1000);
await FileOperations.TryDeleteDirectoryAsync(wallpaper.LivelyInfoFolderPath, 0, 1000);
}
}
catch (Win32Exception ex2)
Expand Down Expand Up @@ -399,12 +399,21 @@ private async Task<bool> ShowWallpaperDialog(IWallpaper wallpaper)

if (cancelled)
{
//user cancelled/fail!
//User cancelled/fail!
wallpaper.Terminate();
DesktopUtil.RefreshDesktop();
//Deleting from core because incase UI client not running.
_ = FileOperations.DeleteDirectoryAsync(wallpaper.Model.LivelyInfoFolderPath, 0, 1000);
_ = FileOperations.DeleteDirectoryAsync(Directory.GetParent(Path.GetDirectoryName(wallpaper.LivelyPropertyCopyPath)).ToString(), 0, 1000);

try
{
//Deleting here incase UI client is not running
await FileOperations.TryDeleteDirectoryAsync(wallpaper.Model.LivelyInfoFolderPath, 0, 1000);
if (wallpaper.LivelyPropertyCopyPath != null)
await FileOperations.TryDeleteDirectoryAsync(Directory.GetParent(Path.GetDirectoryName(wallpaper.LivelyPropertyCopyPath)).FullName, 0, 1000);
}
catch (Exception ie)
{
Logger.Error(ie);
}
}

return !cancelled;
Expand Down

0 comments on commit 6f89a4e

Please sign in to comment.