Skip to content

Commit ecdbf29

Browse files
authored
Fix: Fixed issue where date created is updated when the file is updated (#14050)
1 parent 4805088 commit ecdbf29

File tree

12 files changed

+30
-20
lines changed

12 files changed

+30
-20
lines changed

src/Files.App/Data/Models/ItemViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,13 +2295,13 @@ private async Task AddFileOrFolderAsync(ListedItem? item)
22952295
var properties = await storageItem.AsBaseStorageFile().GetBasicPropertiesAsync();
22962296
size = (long)properties.Size;
22972297
modified = properties.DateModified;
2298-
created = properties.ItemDate;
2298+
created = properties.DateCreated;
22992299
}
23002300
else if (storageItem.IsOfType(StorageItemTypes.Folder))
23012301
{
23022302
var properties = await storageItem.AsBaseStorageFolder().GetBasicPropertiesAsync();
23032303
modified = properties.DateModified;
2304-
created = properties.ItemDate;
2304+
created = properties.DateCreated;
23052305
}
23062306

23072307
return (item, syncStatus, size, created, modified);

src/Files.App/Utils/Storage/StorageBaseItems/BaseBasicProperties.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class BaseBasicProperties : BaseStorageItemExtraProperties
88
public virtual ulong Size
99
=> 0;
1010

11-
public virtual DateTimeOffset ItemDate
11+
public virtual DateTimeOffset DateCreated
1212
=> DateTimeOffset.Now;
1313

1414
public virtual DateTimeOffset DateModified

src/Files.App/Utils/Storage/StorageBaseItems/BaseBasicStorageItemExtraProperties.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public override IAsyncOperation<IDictionary<string, object>> RetrievePropertiesA
3030
var basicProps = ret is not null ? await ret : null;
3131

3232
props["System.ParsingPath"] = _item?.Path;
33-
props["System.DateCreated"] = basicProps?.ItemDate;
33+
props["System.DateCreated"] = basicProps?.DateCreated;
3434
props["System.DateModified"] = basicProps?.DateModified;
3535

3636
return props;

src/Files.App/Utils/Storage/StorageItems/FtpStorageFile.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,20 +296,20 @@ private class FtpFileBasicProperties : BaseBasicProperties
296296
{
297297
public override ulong Size { get; }
298298

299-
public override DateTimeOffset ItemDate { get; }
299+
public override DateTimeOffset DateCreated { get; }
300300
public override DateTimeOffset DateModified { get; }
301301

302302
public FtpFileBasicProperties(FtpItem item)
303303
{
304304
Size = (ulong)item.FileSizeBytes;
305-
ItemDate = item.ItemDateCreatedReal;
305+
DateCreated = item.ItemDateCreatedReal;
306306
DateModified = item.ItemDateModifiedReal;
307307
}
308308

309309
public FtpFileBasicProperties(FtpListItem item)
310310
{
311311
Size = (ulong)item.Size;
312-
ItemDate = item.RawCreated < DateTime.FromFileTimeUtc(0) ? DateTimeOffset.MinValue : item.RawCreated;
312+
DateCreated = item.RawCreated < DateTime.FromFileTimeUtc(0) ? DateTimeOffset.MinValue : item.RawCreated;
313313
DateModified = item.RawModified < DateTime.FromFileTimeUtc(0) ? DateTimeOffset.MinValue : item.RawModified;
314314
}
315315
}

src/Files.App/Utils/Storage/StorageItems/FtpStorageFolder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,14 +366,14 @@ private class FtpFolderBasicProperties : BaseBasicProperties
366366
{
367367
public override ulong Size { get; }
368368

369-
public override DateTimeOffset ItemDate { get; }
369+
public override DateTimeOffset DateCreated { get; }
370370
public override DateTimeOffset DateModified { get; }
371371

372372
public FtpFolderBasicProperties(FtpListItem item)
373373
{
374374
Size = (ulong)item.Size;
375375

376-
ItemDate = item.RawCreated < DateTime.FromFileTimeUtc(0) ? DateTimeOffset.MinValue : item.RawCreated;
376+
DateCreated = item.RawCreated < DateTime.FromFileTimeUtc(0) ? DateTimeOffset.MinValue : item.RawCreated;
377377
DateModified = item.RawModified < DateTime.FromFileTimeUtc(0) ? DateTimeOffset.MinValue : item.RawModified;
378378
}
379379
}

src/Files.App/Utils/Storage/StorageItems/ShellStorageFile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private class ShellFileBasicProperties : BaseBasicProperties
182182

183183
public override ulong Size => file.FileSizeBytes;
184184

185-
public override DateTimeOffset ItemDate => file.ModifiedDate;
185+
public override DateTimeOffset DateCreated => file.CreatedDate;
186186
public override DateTimeOffset DateModified => file.ModifiedDate;
187187
}
188188
}

src/Files.App/Utils/Storage/StorageItems/ShellStorageFolder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ private class ShellFolderBasicProperties : BaseBasicProperties
300300

301301
public override ulong Size => folder.FileSizeBytes;
302302

303-
public override DateTimeOffset ItemDate => folder.ModifiedDate;
303+
public override DateTimeOffset DateCreated => folder.CreatedDate;
304304
public override DateTimeOffset DateModified => folder.ModifiedDate;
305305
}
306306
}

src/Files.App/Utils/Storage/StorageItems/SystemStorageFile.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public override IAsyncOperation<BaseStorageFolder> GetParentAsync()
4848

4949
public override IAsyncOperation<BaseBasicProperties> GetBasicPropertiesAsync()
5050
=> AsyncInfo.Run<BaseBasicProperties>(async (cancellationToken)
51-
=> new SystemFileBasicProperties(await File.GetBasicPropertiesAsync())
51+
=> new SystemFileBasicProperties(await File.GetBasicPropertiesAsync(), DateCreated)
5252
);
5353

5454
public override IAsyncOperation<BaseStorageFile> CopyAsync(IStorageFolder destinationFolder)
@@ -176,13 +176,18 @@ public override IAsyncOperation<StorageItemThumbnail> GetThumbnailAsync(Thumbnai
176176
private class SystemFileBasicProperties : BaseBasicProperties
177177
{
178178
private readonly IStorageItemExtraProperties basicProps;
179+
private readonly DateTimeOffset? dateCreated;
179180

180181
public override ulong Size => (basicProps as BasicProperties)?.Size ?? 0;
181182

182-
public override DateTimeOffset ItemDate => (basicProps as BasicProperties)?.ItemDate ?? DateTimeOffset.Now;
183+
public override DateTimeOffset DateCreated => dateCreated ?? DateTimeOffset.Now;
183184
public override DateTimeOffset DateModified => (basicProps as BasicProperties)?.DateModified ?? DateTimeOffset.Now;
184185

185-
public SystemFileBasicProperties(IStorageItemExtraProperties basicProps) => this.basicProps = basicProps;
186+
public SystemFileBasicProperties(IStorageItemExtraProperties basicProps, DateTimeOffset dateCreated)
187+
{
188+
this.basicProps = basicProps;
189+
this.dateCreated = dateCreated;
190+
}
186191

187192
public override IAsyncOperation<IDictionary<string, object>> RetrievePropertiesAsync(IEnumerable<string> propertiesToRetrieve)
188193
=> basicProps.RetrievePropertiesAsync(propertiesToRetrieve);

src/Files.App/Utils/Storage/StorageItems/SystemStorageFolder.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static IAsyncOperation<BaseStorageFolder> FromPathAsync(string path)
3737
public override IAsyncOperation<BaseStorageFolder> GetParentAsync()
3838
=> AsyncInfo.Run<BaseStorageFolder>(async (cancellationToken) => new SystemStorageFolder(await Folder.GetParentAsync()));
3939
public override IAsyncOperation<BaseBasicProperties> GetBasicPropertiesAsync()
40-
=> AsyncInfo.Run<BaseBasicProperties>(async (cancellationToken) => new SystemFolderBasicProperties(await Folder.GetBasicPropertiesAsync()));
40+
=> AsyncInfo.Run<BaseBasicProperties>(async (cancellationToken) => new SystemFolderBasicProperties(await Folder.GetBasicPropertiesAsync(), DateCreated));
4141

4242
public override IAsyncOperation<IndexedState> GetIndexedStateAsync() => Folder.GetIndexedStateAsync();
4343

@@ -128,13 +128,18 @@ public override IAsyncOperation<StorageItemThumbnail> GetThumbnailAsync(Thumbnai
128128
private class SystemFolderBasicProperties : BaseBasicProperties
129129
{
130130
private readonly IStorageItemExtraProperties basicProps;
131+
private readonly DateTimeOffset? dateCreated;
131132

132133
public override ulong Size => (basicProps as BasicProperties)?.Size ?? 0;
133134

134-
public override DateTimeOffset ItemDate => (basicProps as BasicProperties)?.ItemDate ?? DateTimeOffset.Now;
135+
public override DateTimeOffset DateCreated => dateCreated ?? DateTimeOffset.Now;
135136
public override DateTimeOffset DateModified => (basicProps as BasicProperties)?.DateModified ?? DateTimeOffset.Now;
136137

137-
public SystemFolderBasicProperties(IStorageItemExtraProperties basicProps) => this.basicProps = basicProps;
138+
public SystemFolderBasicProperties(IStorageItemExtraProperties basicProps, DateTimeOffset dateCreated)
139+
{
140+
this.basicProps = basicProps;
141+
this.dateCreated = dateCreated;
142+
}
138143

139144
public override IAsyncOperation<IDictionary<string, object>> RetrievePropertiesAsync(IEnumerable<string> propertiesToRetrieve)
140145
=> basicProps.RetrievePropertiesAsync(propertiesToRetrieve);

src/Files.App/Utils/Storage/StorageItems/ZipStorageFile.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ private class ZipFileBasicProperties : BaseBasicProperties
526526

527527
public override DateTimeOffset DateModified => entry.LastWriteTime == DateTime.MinValue ? DateTimeOffset.MinValue : entry.LastWriteTime;
528528

529-
public override DateTimeOffset ItemDate => entry.CreationTime == DateTime.MinValue ? DateTimeOffset.MinValue : entry.CreationTime;
529+
public override DateTimeOffset DateCreated => entry.CreationTime == DateTime.MinValue ? DateTimeOffset.MinValue : entry.CreationTime;
530530

531531
public override ulong Size => entry.Size;
532532
}

0 commit comments

Comments
 (0)