-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
102 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// | ||
// CleanupDocumentDirectoryUtil.swift | ||
// DiffuserStick | ||
// | ||
// Created by 윤범태 on 3/1/24. | ||
// | ||
|
||
import Foundation | ||
|
||
class CleanupDocumentDirectoryUtil { | ||
/// 1.3.0 이전 버전에서 삭제되지 않은 Document 디렉토리의 이미지 파일을 삭제 | ||
func doCleanup() { | ||
let activeData = try? readCoreData(isArchive: false) | ||
let archiveData = try? readCoreData(isArchive: true) | ||
|
||
let documentDir = getDocumentsDirectory() | ||
var validImageFiles: [URL] = [] | ||
|
||
if let activeData { | ||
activeData.forEach { diffuser in | ||
validImageFiles.append(documentDir.appendingPathComponent(diffuser.photoName)) | ||
print(#function, "Added valid image file:", diffuser.photoName) | ||
} | ||
} | ||
|
||
if let archiveData { | ||
archiveData.forEach { diffuser in | ||
validImageFiles.append(documentDir.appendingPathComponent(diffuser.photoName)) | ||
print(#function, "Added valid image file:", diffuser.photoName) | ||
} | ||
} | ||
|
||
do { | ||
// Get the directory contents urls (including subfolders urls) | ||
let directoryContents = try FileManager.default.contentsOfDirectory( | ||
at: documentDir, | ||
includingPropertiesForKeys: nil | ||
) | ||
|
||
directoryContents.forEach { url in | ||
if !validImageFiles.contains(url) { | ||
removeFile(from: url) | ||
print(#function, "This file has been disconnected from the database. Delete:", url.lastPathComponent) | ||
} else { | ||
print(#function, "This file is valid so we will not delete it:", url.lastPathComponent) | ||
} | ||
} | ||
} catch { | ||
print(#function, error) | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// FirstRunUtil.swift | ||
// DiffuserStick | ||
// | ||
// Created by 윤범태 on 3/1/24. | ||
// | ||
|
||
import Foundation | ||
|
||
func checkAppFirstrunOrUpdateStatus(firstrun: () -> (), updated: () -> (), nothingChanged: () -> ()) { | ||
let currentVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as? String | ||
let versionOfLastRun = UserDefaults.standard.object(forKey: "VersionOfLastRun") as? String | ||
|
||
if versionOfLastRun == nil { | ||
// First start after installing the app | ||
firstrun() | ||
} else if versionOfLastRun != currentVersion { | ||
// App was updated since last run | ||
updated() | ||
} else { | ||
// nothing changed | ||
nothingChanged() | ||
} | ||
|
||
UserDefaults.standard.set(currentVersion, forKey: "VersionOfLastRun") | ||
UserDefaults.standard.synchronize() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters