Skip to content

Commit 440b4ff

Browse files
author
David Karlaš
committed
Make loading .sqlite work
1 parent b0bd521 commit 440b4ff

13 files changed

Lines changed: 544 additions & 352 deletions

File tree

WinDirStat.Net.Wpf.Base/Model/Drives/Misc/DriveSelectMode.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ public enum DriveSelectMode {
1414
All,
1515
/// <summary>Selected drives are scanned.</summary>
1616
[Description("Individual Drives")]
17-
Individual,
18-
/// <summary>A folder path is scanned.</summary>
19-
[Description("A Folder")]
20-
Folder,
21-
}
17+
Individual,
18+
/// <summary>A folder path is scanned.</summary>
19+
[Description("A Folder")]
20+
Folder,
21+
/// <summary>A folder path is scanned.</summary>
22+
[Description("A Sqlite file")]
23+
Sqlite,
24+
}
2225
}

WinDirStat.Net.Wpf.Base/Model/Drives/Misc/DriveSelectResult.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public class DriveSelectResult {
2525
public DriveSelectResult(ScanningService scanning,
2626
DriveSelectMode mode,
2727
string[] selectedDrives,
28-
string folderPath)
28+
string folderPath,
29+
string sqlitePath)
2930
{
3031
this.scanning = scanning;
3132
Mode = mode;
@@ -38,8 +39,15 @@ public DriveSelectResult(ScanningService scanning,
3839
selectedPaths = new[] {
3940
folderPath ?? throw new ArgumentNullException(nameof(folderPath)),
4041
};
41-
}
42-
}
42+
} else if(mode == DriveSelectMode.Sqlite) {
43+
selectedPaths = new[] {
44+
sqlitePath
45+
};
46+
}
47+
else {
48+
selectedPaths = null;
49+
}
50+
}
4351

4452
#endregion
4553

WinDirStat.Net.Wpf.Base/Model/Files/FileItemBase.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ public abstract class FileItemBase : IComparable<FileItemBase>, IComparable, ITr
4444
/// If this is a container, it returns the most recent time of all children.
4545
/// </summary>
4646
public DateTime LastWriteTimeUtc { get; private protected set; }
47-
/// <summary>Gets the name of the file.</summary>
48-
public string Name { get; }
47+
public DateTime LastAccessTimeUtc { get; private protected set; }
48+
public DateTime CreationTimeUtc { get; private protected set; }
49+
/// <summary>Gets the name of the file.</summary>
50+
public string Name { get; }
4951
/// <summary>Gets the total size of the file and all of its children.</summary>
5052
public long Size { get; private protected set; }
5153
/// <summary>Gets the rectangle of the file for drawing in the treemap.</summary>
@@ -102,8 +104,12 @@ private protected FileItemBase(FileSystemInfo info, FileItemType type, FileItemF
102104
private protected FileItemBase(IScanFileInfo info, FileItemType type, FileItemFlags flags)
103105
: this(info.Name, type, flags)
104106
{
105-
LastWriteTimeUtc = info.LastWriteTimeUtc;
106-
Attributes = info.Attributes;
107+
LastWriteTimeUtc = info.LastWriteTimeUtc;
108+
CreationTimeUtc = info.CreationTimeUtc;
109+
if(info.CreationTimeUtc> DateTime.MinValue)
110+
Console.WriteLine();
111+
LastAccessTimeUtc = info.LastAccessTimeUtc;
112+
Attributes = info.Attributes;
107113

108114
if (!info.IsDirectory && !info.IsSymbolicLink)
109115
Size = info.Size;
@@ -280,10 +286,13 @@ public FolderItem FileParent {
280286
/// Gets the local time of when the file was last written to.<para/>
281287
/// If this is a container, it returns the most recent time of all children.
282288
/// </summary>
283-
public DateTime LastWriteTime => LastWriteTimeUtc.ToLocalTime();
284-
285-
/// <summary>Gets the visible level of the item in the tree.</summary>
286-
public int VisibleLevel => Parent != null ? Parent.VisibleLevel + 1 : 0;
289+
public DateTime LastWriteTime => LastWriteTimeUtc.ToLocalTime();
290+
291+
public DateTime LastAccessTime => LastAccessTimeUtc.ToLocalTime();
292+
public DateTime CreationTime => CreationTimeUtc.ToLocalTime();
293+
294+
/// <summary>Gets the visible level of the item in the tree.</summary>
295+
public int VisibleLevel => Parent != null ? Parent.VisibleLevel + 1 : 0;
287296

288297
/// <summary>Gets the file level of the item in the tree.</summary>
289298
public int FileLevel => Parent != null ? (Parent.FileLevel + (Parent.IsFileType ? 1 : 0)) : 0;

WinDirStat.Net.Wpf.Base/Model/Files/FolderItem.cs

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ public class FolderItem : FileItemBase {
2929
/// Always use the list modification methods to add or remove from the list. This is important
3030
/// because they account for if <see cref="FileItemBase.EmptyChildren"/> is being used.
3131
/// </summary>
32-
protected volatile List<FileItemBase> children = EmptyChildren;
33-
34-
/// <summary>Gets the number of files this folder contains.</summary>
35-
public override sealed int FileCount { get; protected set; }
32+
protected volatile List<FileItemBase> children = EmptyChildren;
33+
private volatile FolderItem _fileCollection;
34+
35+
/// <summary>Gets the number of files this folder contains.</summary>
36+
public override sealed int FileCount { get; protected set; }
3637
/// <summary>Gets the number of directories this folder contains.</summary>
3738
public override sealed int SubdirCount { get; protected set; }
3839

@@ -311,13 +312,7 @@ private bool IsStoringOneContainer {
311312
public FolderItem GetFileCollection() {
312313
if (Type == FileItemType.FileCollection)
313314
return this;
314-
int count = children.Count;
315-
for (int i = 0; i < count; i++) {
316-
FileItemBase child = children[i];
317-
if (child.Type == FileItemType.FileCollection)
318-
return (FolderItem) child;
319-
}
320-
return null;
315+
return _fileCollection;
321316
}
322317

323318
/// <summary>Gets the first file in this folder.</summary>
@@ -425,8 +420,8 @@ public void AddItem(FileItemBase item) {
425420
/// <param name="firstFile">
426421
/// The container's first file. Keep track of this when scanning this directory.
427422
/// </param>
428-
public void AddItem(FileItemBase item, ref FolderItem fileCollection, ref FileItem firstFile) {
429-
if (Type == FileItemType.FileCollection)
423+
public void AddItem(FileItemBase item, ref FolderItem fileCollection, ref FileItem firstFile) {
424+
if (Type == FileItemType.FileCollection)
430425
throw new InvalidOperationException($"Cannot call {nameof(AddItem)} from a File Collection!");
431426

432427
// We know we're adding an item to children, make sure it's setup
@@ -452,9 +447,10 @@ public void AddItem(FileItemBase item, ref FolderItem fileCollection, ref FileIt
452447
else if (IsStoringContainers) {
453448
// We've hit our limit of only one visible file when a
454449
// folder is storing non-files. Move to FileCollection.
455-
fileCollection = new FolderItem();
456-
Remove(firstFile);
457-
Add(fileCollection);
450+
fileCollection = new FolderItem();
451+
_fileCollection = fileCollection;
452+
Remove(firstFile);
453+
Add(fileCollection);
458454
fileCollection.Add(firstFile);
459455
fileCollection.Add(item);
460456
fileCollection.Invalidate();
@@ -495,6 +491,7 @@ public void AddItem(FileItemBase item, ref FolderItem fileCollection, ref FileIt
495491
// Setup file collection if the folder needs to store a container item
496492
Debug.Assert(fileCollection == null);
497493
fileCollection = new FolderItem();
494+
_fileCollection = fileCollection;
498495
List<FileItemBase> files = ClearAndGetFiles();
499496
Add(fileCollection);
500497
fileCollection.AddRange(files);
@@ -701,8 +698,11 @@ private void ClearFileCollectionItems() {
701698
protected void Add(FileItemBase item) {
702699
//EnsureChildren();
703700
int index = children.Count;
704-
children.Add(item);
705-
item.Parent = this;
701+
if(item.Type == FileItemType.FileCollection && _fileCollection == null)
702+
Console.WriteLine();
703+
704+
children.Add(item);
705+
item.Parent = this;
706706
if (IsWatched)
707707
RaiseChanged(FileItemAction.ChildrenAdded, item, index);
708708
}
@@ -926,11 +926,15 @@ private protected bool ValidateImpl(bool force) {
926926
if (IsFileType) {
927927
DirectoryInfo directoryInfo = new DirectoryInfo(FullName);
928928
// Use the directory's LastWriteTime when empty
929-
LastWriteTimeUtc = directoryInfo.LastWriteTimeUtc;
929+
LastWriteTimeUtc = directoryInfo.LastWriteTimeUtc;
930+
LastAccessTimeUtc = directoryInfo.LastAccessTimeUtc;
931+
CreationTimeUtc = directoryInfo.CreationTimeUtc;
930932
}
931933
else {
932-
LastWriteTimeUtc = DateTime.MinValue;
933-
}
934+
LastWriteTimeUtc = DateTime.MinValue;
935+
LastAccessTimeUtc = DateTime.MinValue;
936+
CreationTimeUtc = DateTime.MinValue;
937+
}
934938
if (IsWatched)
935939
RaiseChanged(FileItemAction.ValidatedSortOrder);
936940
IsValidating = false;
@@ -939,9 +943,11 @@ private protected bool ValidateImpl(bool force) {
939943

940944
// True, if any of the sort orders that can change, have changed
941945
bool sortOrderChanged = false;
942-
long oldSize = Size;
943-
DateTime oldLastChangeTime = LastWriteTimeUtc;
944-
bool thisIsDone = IsDone;
946+
long oldSize = Size;
947+
DateTime oldLastChangeTime = LastWriteTimeUtc;
948+
DateTime oldLastAccessTimeUtc = LastAccessTimeUtc;
949+
DateTime oldCreationTimeUtc = CreationTimeUtc;
950+
bool thisIsDone = IsDone;
945951
bool isDone = true;
946952

947953
lock (children) {
@@ -973,7 +979,9 @@ private protected bool ValidateImpl(bool force) {
973979
Size += child.Size;
974980
//LastAccessTime = Max(LastAccessTime, child.LastAccessTime);
975981
LastWriteTimeUtc = MaxDateTime(LastWriteTimeUtc, child.LastWriteTimeUtc);
976-
if (child.Type == FileItemType.File || child.Type == FileItemType.FreeSpace) {
982+
LastAccessTimeUtc = MaxDateTime(LastAccessTimeUtc, child.LastAccessTimeUtc);
983+
CreationTimeUtc = MaxDateTime(CreationTimeUtc, child.CreationTimeUtc);
984+
if (child.Type == FileItemType.File || child.Type == FileItemType.FreeSpace) {
977985
FileCount++;
978986
}
979987
else {
@@ -1004,7 +1012,7 @@ private protected bool ValidateImpl(bool force) {
10041012
else
10051013
RaiseChanged(FileItemAction.Validated);
10061014
}
1007-
return sortOrderChanged || (oldLastChangeTime != LastWriteTimeUtc);
1015+
return sortOrderChanged || (oldLastChangeTime != LastWriteTimeUtc) || (oldLastAccessTimeUtc != LastAccessTimeUtc) || (oldCreationTimeUtc != CreationTimeUtc);
10081016
}
10091017

10101018
/// <summary>Fully validates the file item tree and prepares it for use.</summary>

WinDirStat.Net.Wpf.Base/Services/IMyDialogService.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ public interface IMyDialogService {
2424
/// <param name="selectedPath">The currently selected path. Use an empty string for nothing.</param>
2525
/// <returns>The selected path on success, otherwise null.</returns>
2626
string ShowFolderBrowser(Window owner, string description, bool showNewFolder, string selectedPath = "");
27-
28-
/// <summary>Shows a message with no icon.</summary>
29-
///
30-
/// <param name="owner">The owner window for this dialog message.</param>
31-
/// <param name="message">The text message.</param>
32-
/// <param name="title">The message window title.</param>
33-
/// <param name="button">The message buttons to display.</param>
34-
MessageBoxResult ShowMessage(Window owner, string message, string title, MessageBoxButton button = MessageBoxButton.OK);
27+
28+
string ShowFileBrowser(Window owner, string description, string selectedPath = null);
29+
30+
/// <summary>Shows a message with no icon.</summary>
31+
///
32+
/// <param name="owner">The owner window for this dialog message.</param>
33+
/// <param name="message">The text message.</param>
34+
/// <param name="title">The message window title.</param>
35+
/// <param name="button">The message buttons to display.</param>
36+
MessageBoxResult ShowMessage(Window owner, string message, string title, MessageBoxButton button = MessageBoxButton.OK);
3537

3638
/// <summary>Shows a message with an information icon.</summary>
3739
///

0 commit comments

Comments
 (0)