Skip to content

Commit

Permalink
Move MBM conversion into a PsiLuaEnv extension
Browse files Browse the repository at this point in the history
  • Loading branch information
jbmorley committed Jul 24, 2024
1 parent 8bda2a9 commit 62d892b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 16 deletions.
4 changes: 4 additions & 0 deletions Reconnect.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
D89071912C4B025D00C11DE8 /* ArgumentParser in Frameworks */ = {isa = PBXBuildFile; productRef = D89071902C4B025D00C11DE8 /* ArgumentParser */; };
D89071932C4B02D900C11DE8 /* ReconnectCore in Frameworks */ = {isa = PBXBuildFile; productRef = D89071922C4B02D900C11DE8 /* ReconnectCore */; };
D89B5E8E2C2AA8680014A5B6 /* Sidebar.swift in Sources */ = {isa = PBXBuildFile; fileRef = D89B5E8D2C2AA8680014A5B6 /* Sidebar.swift */; };
D8A37AE22C50CED600076AC1 /* PsiLuaEnv.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8A37AE12C50CED600076AC1 /* PsiLuaEnv.swift */; };
D8CBAC652C4A02580035FC3D /* ReconnectCore in Frameworks */ = {isa = PBXBuildFile; productRef = D8CBAC642C4A02580035FC3D /* ReconnectCore */; };
D8D3E79F2C2540D9003E696D /* Interact in Frameworks */ = {isa = PBXBuildFile; productRef = D8D3E79E2C2540D9003E696D /* Interact */; };
D8DF2C112C3CE8AC006E56BA /* OpoLua in Frameworks */ = {isa = PBXBuildFile; productRef = D8DF2C102C3CE8AC006E56BA /* OpoLua */; };
Expand Down Expand Up @@ -136,6 +137,7 @@
D89071882C4B01FC00C11DE8 /* screenshot-sis */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "screenshot-sis"; sourceTree = BUILT_PRODUCTS_DIR; };
D890718A2C4B01FC00C11DE8 /* Command.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Command.swift; sourceTree = "<group>"; };
D89B5E8D2C2AA8680014A5B6 /* Sidebar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sidebar.swift; sourceTree = "<group>"; };
D8A37AE12C50CED600076AC1 /* PsiLuaEnv.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PsiLuaEnv.swift; sourceTree = "<group>"; };
D8AD8B532C2379A10063A613 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
D8D3E7A02C25410E003E696D /* MainMenu.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainMenu.swift; sourceTree = "<group>"; };
D8E31EB42C26E10900350082 /* Licensable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Licensable.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -336,6 +338,7 @@
isa = PBXGroup;
children = (
D8E31EB42C26E10900350082 /* Licensable.swift */,
D8A37AE12C50CED600076AC1 /* PsiLuaEnv.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -606,6 +609,7 @@
D88FA1502C2CE29900805DBD /* ContentView.swift in Sources */,
D83B4DE12C2F99C3003C3DC1 /* CheckForUpdatesViewModel.swift in Sources */,
D8FFE85F2C49F2FB001F7D8A /* TransfersWindow.swift in Sources */,
D8A37AE22C50CED600076AC1 /* PsiLuaEnv.swift in Sources */,
D83658B92C298C4F00B45693 /* NavigationStack.swift in Sources */,
D8631DAB2C36867400344DC3 /* BrowserDetailView.swift in Sources */,
D8184C472C253C59008FA79B /* ApplicationModel.swift in Sources */,
Expand Down
48 changes: 48 additions & 0 deletions Reconnect/Extensions/PsiLuaEnv.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Reconnect -- Psion connectivity for macOS
//
// Copyright (C) 2024 Jason Morley
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

import Foundation

import OpoLua

import ReconnectCore

extension PsiLuaEnv {

func convertMultiBitmap(at url: URL, removeSource: Bool = false) throws {
let directoryURL = (url as NSURL).deletingLastPathComponent!
let basename = (url.lastPathComponent as NSString).deletingPathExtension
let bitmaps = PsiLuaEnv().getMbmBitmaps(path: url.path) ?? []
for (index, bitmap) in bitmaps.enumerated() {
let identifier = if index < 1 {
basename
} else {
"\(basename) \(index)"
}
let conversionURL = directoryURL
.appendingPathComponent(identifier)
.appendingPathExtension("png")
let image = CGImage.from(bitmap: bitmap)
try CGImageWritePNG(image, to: conversionURL)
}
if removeSource {
try FileManager.default.removeItem(at: url)
}
}

}
17 changes: 1 addition & 16 deletions Reconnect/Model/TransfersModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,7 @@ class TransfersModel {
// reasonable point to hook an initial implementation.
if convertFiles {
if directoryEntry.fileType == .mbm {
let directoryURL = (downloadURL as NSURL).deletingLastPathComponent!
let basename = (downloadURL.lastPathComponent as NSString).deletingPathExtension
let bitmaps = PsiLuaEnv().getMbmBitmaps(path: downloadURL.path) ?? []
for (index, bitmap) in bitmaps.enumerated() {
let identifier = if index < 1 {
basename
} else {
"\(basename) \(index)"
}
let conversionURL = directoryURL
.appendingPathComponent(identifier)
.appendingPathExtension("png")
let image = CGImage.from(bitmap: bitmap)
try CGImageWritePNG(image, to: conversionURL)
}
try fileManager.removeItem(at: downloadURL)
try PsiLuaEnv().convertMultiBitmap(at: downloadURL, removeSource: true)
}
}

Expand Down

0 comments on commit 62d892b

Please sign in to comment.