Skip to content

Commit b4629cf

Browse files
committed
cache dir
1 parent 572cdaa commit b4629cf

4 files changed

Lines changed: 25 additions & 21 deletions

File tree

OpenDocumentReader/CoreWrapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@property NSArray *pagePaths;
1818
@property NSNumber *errorCode;
1919

20-
- (bool)translate:(NSString *)inputPath into:(NSString *)outputPath with:(NSString *)password editable:(bool)editable;
20+
- (bool)translate:(NSString *)inputPath cache:(NSString *)cachePath into:(NSString *)outputPath with:(NSString *)password editable:(bool)editable;
2121
- (bool)backTranslate:(NSString *)diff into:(NSString *)outputPath;
2222
@end
2323

OpenDocumentReader/CoreWrapper.mm

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ @implementation CoreWrapper {
2828
std::optional<odr::Html> html;
2929
}
3030

31-
- (bool)translate:(NSString *)inputPath into:(NSString *)outputPath with:(NSString *)password editable:(bool)editable {
31+
- (bool)translate:(NSString *)inputPath cache:(NSString *)cachePath into:(NSString *)outputPath with:(NSString *)password editable:(bool)editable {
3232
@synchronized(self) {
3333
try {
3434
_errorCode = 0;
@@ -67,6 +67,9 @@ - (bool)translate:(NSString *)inputPath into:(NSString *)outputPath with:(NSStri
6767
auto outputPathC = [outputPath cStringUsingEncoding:NSUTF8StringEncoding];
6868
auto outputPathCpp = std::string(outputPathC);
6969

70+
auto cachePathC = [cachePath cStringUsingEncoding:NSUTF8StringEncoding];
71+
auto cachePathCpp = std::string(cachePathC);
72+
7073
odr::DecodedFile file = odr::open(inputPathCpp);
7174
if (file.password_encrypted()) {
7275
try {
@@ -82,7 +85,7 @@ - (bool)translate:(NSString *)inputPath into:(NSString *)outputPath with:(NSStri
8285
}
8386
document = file.document_file().document();
8487

85-
html = odr::html::translate(*document, outputPathCpp, config).bring_offline(outputPathCpp);
88+
html = odr::html::translate(*document, cachePathCpp, config).bring_offline(outputPathCpp);
8689

8790
NSMutableArray *pageNames = [[NSMutableArray alloc] init];
8891
NSMutableArray *pagePaths = [[NSMutableArray alloc] init];

OpenDocumentReader/Document.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ class Document: UIDocument {
6767
result = nil
6868
delegate?.documentUpdateContent(self)
6969

70-
let tempPath = URL(fileURLWithPath: NSTemporaryDirectory())
71-
coreWrapper.translate(fileURL.path, into: tempPath.path, with: password, editable: edit)
72-
70+
let cachePath = URL(fileURLWithPath: NSTemporaryDirectory())
71+
let outputPath = URL(fileURLWithPath: NSTemporaryDirectory())
72+
coreWrapper.translate(fileURL.path, cache: cachePath.path, into: outputPath.path, with: password, editable: edit)
73+
7374
let errorCode = coreWrapper.errorCode != nil ? coreWrapper.errorCode.intValue : 0
7475
if (errorCode == -2) {
7576
self.delegate?.documentEncrypted(self)

OpenDocumentReaderTests/OpenDocumentReaderTests.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,26 @@ import XCTest
1111
@testable import OpenDocumentReader
1212

1313
class OpenDocumentReaderTests: XCTestCase {
14-
1514
// ONLINE fails on GitHub Actions for some reason
1615
private let ONLINE = false
17-
16+
1817
private var saveURL: URL?
1918

2019
override func setUpWithError() throws {
2120
var fileURL: URL?
22-
21+
2322
let documentsURL = try
2423
FileManager.default.url(for: .documentDirectory,
2524
in: .userDomainMask,
2625
appropriateFor: nil,
2726
create: false)
28-
27+
2928
saveURL = documentsURL.appendingPathComponent("test.odt")
30-
29+
3130
if (FileManager.default.fileExists(atPath: saveURL!.path)) {
3231
return
3332
}
34-
33+
3534
if (ONLINE) {
3635
let url = URL(string: "https://api.libreoffice.org/examples/cpp/DocumentLoader/test.odt")
3736

@@ -45,25 +44,26 @@ class OpenDocumentReaderTests: XCTestCase {
4544
let filePath = Bundle(for: type(of: self)).path(forResource: "test", ofType: "odt")
4645
fileURL = URL(fileURLWithPath: filePath!)
4746
}
48-
47+
4948
try FileManager.default.moveItem(at: fileURL!, to: self.saveURL!)
5049
}
5150

5251
func testExample() throws {
5352
measure {
5453
let coreWrapper = CoreWrapper()
55-
56-
var translatePath = URL(fileURLWithPath: NSTemporaryDirectory())
57-
translatePath.appendPathComponent("translate.html")
58-
59-
coreWrapper.translate(saveURL?.path, into: translatePath.path, with: nil, editable: true)
54+
55+
var cachePath = URL(fileURLWithPath: NSTemporaryDirectory())
56+
var outputPath = URL(fileURLWithPath: NSTemporaryDirectory())
57+
outputPath.appendPathComponent("translate.html")
58+
59+
coreWrapper.translate(saveURL?.path, cache: cachePath.path, into: outputPath.path, with: nil, editable: true)
6060
XCTAssertNil(coreWrapper.errorCode)
61-
61+
6262
var backTranslatePath = URL(fileURLWithPath: NSTemporaryDirectory())
6363
backTranslatePath.appendPathComponent("backtranslate.html")
64-
64+
6565
let diff = "{\"modifiedText\":{\"/child:3/child:0\":\"This is a simple test document to demonstrate the DocumentLoaderwwww example!\"}}"
66-
66+
6767
coreWrapper.backTranslate(diff, into: backTranslatePath.path)
6868
XCTAssertNil(coreWrapper.errorCode)
6969
}

0 commit comments

Comments
 (0)