-
Notifications
You must be signed in to change notification settings - Fork 136
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
1 parent
3a63762
commit b42ab55
Showing
28 changed files
with
509 additions
and
52 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
File renamed without changes.
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
File renamed without changes.
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,23 @@ | ||
// | ||
// OptionType.swift | ||
// wallpapper-exif | ||
// | ||
// Created by Marcin Czachurski on 21/10/2021. | ||
// Copyright © 2021 Marcin Czachurski. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
enum OptionType: String { | ||
case help = "-h" | ||
case version = "-v" | ||
case unknown | ||
|
||
init(value: String) { | ||
switch value { | ||
case "-h": self = .help | ||
case "-v": self = .version | ||
default: self = .unknown | ||
} | ||
} | ||
} |
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,110 @@ | ||
// | ||
// Program.swift | ||
// wallpapper-exif | ||
// | ||
// Created by Marcin Czachurski on 21/10/2021. | ||
// Copyright © 2021 Marcin Czachurski. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import WallpapperLib | ||
|
||
class Program { | ||
let consoleIO = ConsoleIO() | ||
var inputFileNames: [String] = [] | ||
var wallpapperItems: [WallpapperItem] = [] | ||
|
||
func run() throws -> Bool { | ||
|
||
let (shouldBreak, resultCode) = self.proceedCommandLineArguments() | ||
if shouldBreak { | ||
return resultCode | ||
} | ||
|
||
for inputFileName in inputFileNames { | ||
let fileURL = try getPathToInputFile(inputFileName: inputFileName) | ||
let inputFileContents = try Data(contentsOf: fileURL) | ||
|
||
let locationExtractor = LocationExtractor() | ||
let imageLocation = try locationExtractor.extract(imageData: inputFileContents) | ||
|
||
let sc = SunCalculations(date: imageLocation.createDate, | ||
latitude: imageLocation.latitude, | ||
longitude: imageLocation.longitude) | ||
|
||
let position = sc.getSunPosition() | ||
|
||
let wallpapperItem = WallpapperItem(fileName: inputFileName, | ||
altitude: position.altitude, | ||
azimuth: position.azimuth) | ||
|
||
wallpapperItems.append(wallpapperItem) | ||
} | ||
|
||
let encoder = JSONEncoder() | ||
encoder.outputFormatting = .prettyPrinted | ||
let jsonData = try encoder.encode(wallpapperItems) | ||
let jsonOptionslString = String(bytes: jsonData, encoding: .utf8) | ||
|
||
guard let jsonString = jsonOptionslString else { | ||
return false | ||
} | ||
|
||
self.consoleIO.writeMessage(jsonString, to: .standard) | ||
return true | ||
} | ||
|
||
private func getPathToInputFile(inputFileName: String) throws -> URL { | ||
return URL(fileURLWithPath: inputFileName) | ||
} | ||
|
||
private func proceedCommandLineArguments() -> (Bool, Bool) { | ||
if CommandLine.arguments.count == 1 { | ||
self.printUsage() | ||
return (true, false) | ||
} | ||
|
||
var optionIndex = 1 | ||
while optionIndex < CommandLine.arguments.count { | ||
|
||
let option = CommandLine.arguments[optionIndex] | ||
let optionType = OptionType(value: option) | ||
|
||
switch optionType { | ||
case .help: | ||
self.printUsage() | ||
return (true, true) | ||
case .version: | ||
self.printVersion() | ||
return (true, true) | ||
default: | ||
let fileName = CommandLine.arguments[optionIndex] | ||
inputFileNames.append(fileName) | ||
break; | ||
} | ||
|
||
optionIndex = optionIndex + 1 | ||
} | ||
|
||
if self.inputFileNames.count == 0 { | ||
self.consoleIO.writeMessage("unknown input file names.", to: .error) | ||
return (true, false) | ||
} | ||
|
||
return (false, false) | ||
} | ||
|
||
private func printVersion() { | ||
self.consoleIO.writeMessage("1.0.0") | ||
} | ||
|
||
private func printUsage() { | ||
|
||
let executableName = (CommandLine.arguments[0] as NSString).lastPathComponent | ||
|
||
self.consoleIO.writeMessage("\(executableName): [file1] [file2]") | ||
self.consoleIO.writeMessage("Command options are:") | ||
self.consoleIO.writeMessage(" -h\t\t\tshow this message and exit") | ||
self.consoleIO.writeMessage(" -v\t\t\tshow program version and exit") | ||
} | ||
} |
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,14 @@ | ||
// | ||
// main.swift | ||
// wallpapper-exif | ||
// | ||
// Created by Marcin Czachurski on 21/10/2021. | ||
// Copyright © 2021 Marcin Czachurski. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
let program = Program() | ||
let result = try program.run() | ||
|
||
exit(result ? EXIT_SUCCESS : EXIT_FAILURE) |
14 changes: 9 additions & 5 deletions
14
.../wallpapper/ConsoleOutput/ConsoleIO.swift → ...llpapperLib/ConsoleOutput/ConsoleIO.swift
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,15 @@ | ||
// | ||
// OutputType.swift | ||
// WallpapperLib | ||
// | ||
// Created by Marcin Czachurski on 22/01/2021. | ||
// Copyright © 2021 Marcin Czachurski. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public enum OutputType { | ||
case error | ||
case standard | ||
case debug | ||
} |
4 changes: 2 additions & 2 deletions
4
.../Errors/ImageMetadataGeneratorError.swift → .../Errors/ImageMetadataGeneratorError.swift
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
6 changes: 3 additions & 3 deletions
6
...s/wallpapper/ImageMetadataGenerator.swift → ...perGenerator/ImageMetadataGenerator.swift
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
4 changes: 2 additions & 2 deletions
4
...s/wallpapper/PropertyList/Apperance.swift → ...WallpaperGenerator/Models/Apperance.swift
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
4 changes: 2 additions & 2 deletions
4
Sources/wallpapper/Model/PictureInfo.swift → ...llpaperGenerator/Models/PictureInfo.swift
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
4 changes: 2 additions & 2 deletions
4
...allpapper/PropertyList/SequenceInfo.swift → ...lpaperGenerator/Models/SequenceInfo.swift
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
4 changes: 2 additions & 2 deletions
4
...allpapper/PropertyList/SequenceItem.swift → ...lpaperGenerator/Models/SequenceItem.swift
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
4 changes: 2 additions & 2 deletions
4
...es/wallpapper/PropertyList/TimeInfo.swift → ...cWallpaperGenerator/Models/TimeInfo.swift
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
2 changes: 1 addition & 1 deletion
2
Sources/wallpapper/Extensions/NSImage.swift → ...es/WallpapperLib/Extensions/NSImage.swift
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
Oops, something went wrong.