mirror of
https://github.com/dredx/prole.git
synced 2026-09-24 18:54:32 +00:00
- Moved prole-tools-app to prole-app at the project root to make it self-contained for transition to its own repository. - Created prole-tools-app/dist/ directory to host build artifacts. - Generated distribution artifacts (Prole Tools.app and Prole Tools.zip) using prole-app/build.sh package. - Checked in the generated artifacts to prole-tools-app/dist/ (bypassing .gitignore for temporary release process). Changes Summary • Renamed directory prole-tools-app/ to prole-app/. • Populated prole-tools-app/dist/ with the latest build output from prole-app/build.sh. • Staged all changes, including the forced addition of ignored artifacts in prole-tools-app/dist/.
78 lines
3.1 KiB
Swift
78 lines
3.1 KiB
Swift
import Foundation
|
|
|
|
struct PortMappingXML: Equatable {
|
|
var id: String
|
|
var namespace: String
|
|
var target: String
|
|
var address: String
|
|
var hostPort: String
|
|
var servicePort: String
|
|
var proto: String
|
|
var description: String
|
|
}
|
|
|
|
enum PortMappingsXMLStore {
|
|
private static func configURL() -> URL {
|
|
// Determine PROLE_HOME similarly to PFScriptBridge
|
|
let env = ProcessInfo.processInfo.environment
|
|
if let home = env["PROLE_HOME"], !home.isEmpty {
|
|
return URL(fileURLWithPath: home).appendingPathComponent("conf/port-mappings.properties")
|
|
}
|
|
let defaultHome = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent("dev/prole")
|
|
return defaultHome.appendingPathComponent("conf/port-mappings.properties")
|
|
}
|
|
|
|
static func load() -> [PortMappingXML] {
|
|
let url = configURL()
|
|
guard let data = try? Data(contentsOf: url) else { return [] }
|
|
let parser = XMLParser(data: data)
|
|
let delegate = ParserDelegate()
|
|
parser.delegate = delegate
|
|
if parser.parse() { return delegate.items }
|
|
return []
|
|
}
|
|
|
|
static func save(_ items: [PortMappingXML]) throws {
|
|
let url = configURL()
|
|
var xml = """
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<portMappings>
|
|
"""
|
|
for m in items {
|
|
xml += " <mapping id=\"\(escape(m.id))\" namespace=\"\(escape(m.namespace))\" target=\"\(escape(m.target))\" address=\"\(escape(m.address))\" hostPort=\"\(escape(m.hostPort))\" servicePort=\"\(escape(m.servicePort))\" protocol=\"\(escape(m.proto))\" description=\"\(escape(m.description))\"/>\n"
|
|
}
|
|
xml += """
|
|
</portMappings>
|
|
"""
|
|
try FileManager.default.createDirectory(at: url.deletingLastPathComponent(), withIntermediateDirectories: true)
|
|
try xml.data(using: .utf8)?.write(to: url)
|
|
}
|
|
|
|
private static func escape(_ s: String) -> String {
|
|
return s.replacingOccurrences(of: "&", with: "&")
|
|
.replacingOccurrences(of: "\"", with: """)
|
|
.replacingOccurrences(of: "<", with: "<")
|
|
.replacingOccurrences(of: ">", with: ">")
|
|
}
|
|
|
|
private final class ParserDelegate: NSObject, XMLParserDelegate {
|
|
var items: [PortMappingXML] = []
|
|
|
|
func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String] = [:]) {
|
|
if elementName == "mapping" {
|
|
let m = PortMappingXML(
|
|
id: attributeDict["id"] ?? "",
|
|
namespace: attributeDict["namespace"] ?? "default",
|
|
target: attributeDict["target"] ?? "",
|
|
address: attributeDict["address"] ?? "127.0.0.1",
|
|
hostPort: attributeDict["hostPort"] ?? "",
|
|
servicePort: attributeDict["servicePort"] ?? "",
|
|
proto: attributeDict["protocol"] ?? "TCP",
|
|
description: attributeDict["description"] ?? ""
|
|
)
|
|
items.append(m)
|
|
}
|
|
}
|
|
}
|
|
}
|