From cdac1e3af77b8c2a904b4869cc4bc2f18a4fca25 Mon Sep 17 00:00:00 2001 From: ruidajo Date: Mon, 4 Apr 2022 19:06:21 -0500 Subject: [PATCH] Improved store contents for NitterUser. --- .../instance/storeContents.st | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Socialmetrica.package/NitterUser.class/instance/storeContents.st b/Socialmetrica.package/NitterUser.class/instance/storeContents.st index bbbf6da..3aea2a2 100644 --- a/Socialmetrica.package/NitterUser.class/instance/storeContents.st +++ b/Socialmetrica.package/NitterUser.class/instance/storeContents.st @@ -1,6 +1,23 @@ accessing storeContents - | objectString | + | objectString directory tempFile oldFile | objectString := STON toStringPretty: self. - ^ MarkupFile exportAsFileOn: self folder/ self userName, 'ston' containing: objectString. \ No newline at end of file + directory := (FileLocator userData / 'Socialmetrica' / self userName) ensureCreateDirectory. + oldFile := directory / self userName, 'ston'. + + oldFile exists ifFalse: [ + ^ MarkupFile exportAsFileOn: oldFile containing: objectString ]. + + tempFile := MarkupFile + exportAsFileOn: FileLocator temp / self userName, 'ston' + containing: objectString. + + (tempFile contents hash hex = oldFile contents hash hex) ifFalse: [ + oldFile copyTo: directory / + (oldFile basenameWithoutExtension , '-', + ('-' join:((oldFile creationTime asLocalStringYMDHM) splitOn: ' ')), + '.ston'). + oldFile ensureDelete. + ^ { 'Profile changed' -> (tempFile moveTo: oldFile)} asDictionary ]. + ^ { 'Same Profile' -> oldFile } asDictionary. \ No newline at end of file