Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
true rootless paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandra authored and Alexandra committed Aug 16, 2023
1 parent c694b3b commit 1b2559d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
1 change: 1 addition & 0 deletions Manager/PasteboardManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Alexandra (@Traurige)
//

#import <rootless.h>
#import <UIKit/UIKit.h>
#import "PasteboardItem.h"
#import "../Utils/CommonUtil.h"
Expand Down
23 changes: 12 additions & 11 deletions Manager/PasteboardManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ - (void)pullPasteboardChanges {
// save as png if an alpha channel is present though
if ([ImageUtil imageHasAlpha:image]) {
imageName = [imageName stringByAppendingString:@".png"];
NSString* filePath = [kHistoryImagesPath stringByAppendingString:imageName];
NSString* filePath = ROOT_PATH_NS_VAR([kHistoryImagesPath stringByAppendingString:imageName]);
[UIImagePNGRepresentation([ImageUtil rotatedImageFromImage:image]) writeToFile:filePath atomically:YES];
} else {
imageName = [imageName stringByAppendingString:@".jpg"];
NSString* filePath = [kHistoryImagesPath stringByAppendingString:imageName];
NSString* filePath = ROOT_PATH_NS_VAR([kHistoryImagesPath stringByAppendingString:imageName]);
[UIImageJPEGRepresentation(image, 1) writeToFile:filePath atomically:YES];
}

Expand Down Expand Up @@ -160,7 +160,7 @@ - (void)removePasteboardItem:(PasteboardItem *)item fromHistoryWithKey:(NSString
if ([[historyItem content] isEqualToString:[item content]]) {
[history removeObject:dictionary];
if ([item hasImage] && shouldRemoveImage) {
NSString* filePath = [kHistoryImagesPath stringByAppendingString:[item imageName]];
NSString* filePath = ROOT_PATH_NS_VAR([kHistoryImagesPath stringByAppendingString:[item imageName]]);
[_fileManager removeItemAtPath:filePath error:nil];
}
break;
Expand All @@ -177,7 +177,7 @@ - (void)updatePasteboardWithItem:(PasteboardItem *)item fromHistoryWithKey:(NSSt
[_pasteboard setString:@""];

if ([item hasImage] && ![item hasPlainText] && ![item hasLink] && ![item hasMusicLink] && ![item hasColor]) {
NSString* filePath = [kHistoryImagesPath stringByAppendingString:[item imageName]];
NSString* filePath = ROOT_PATH_NS_VAR([kHistoryImagesPath stringByAppendingString:[item imageName]]);
UIImage* image = [UIImage imageWithContentsOfFile:filePath];
[_pasteboard setImage:image];
} else {
Expand All @@ -204,35 +204,36 @@ - (PasteboardItem *)latestHistoryItem {
}

- (UIImage *)imageForItem:(PasteboardItem *)item {
NSData* imageData = [_fileManager contentsAtPath:[NSString stringWithFormat:@"%@%@", kHistoryImagesPath, [item imageName]]];
NSString* path = [NSString stringWithFormat:@"%@%@", kHistoryImagesPath, [item imageName]];
NSData* imageData = [_fileManager contentsAtPath:ROOT_PATH_NS_VAR(path)];
return [UIImage imageWithData:imageData];
}

- (NSMutableDictionary *)getJson {
[self ensureResourcesExist];

NSData* jsonData = [NSData dataWithContentsOfFile:kHistoryPath];
NSData* jsonData = [NSData dataWithContentsOfFile:ROOT_PATH_NS_VAR(kHistoryPath)];
NSMutableDictionary* json = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];

return json;
}

- (void)setJsonFromDictionary:(NSMutableDictionary *)dictionary {
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dictionary options:NSJSONWritingPrettyPrinted error:nil];
[jsonData writeToFile:kHistoryPath atomically:YES];
[jsonData writeToFile:ROOT_PATH_NS_VAR(kHistoryPath) atomically:YES];

CFNotificationCenterPostNotification(CFNotificationCenterGetDarwinNotifyCenter(), (CFStringRef)kNotificationKeyCoreReload, nil, nil, YES);
}

- (void)ensureResourcesExist {
BOOL isDirectory;
if (![_fileManager fileExistsAtPath:kHistoryImagesPath isDirectory:&isDirectory]) {
[_fileManager createDirectoryAtPath:kHistoryImagesPath withIntermediateDirectories:YES attributes:nil error:nil];
if (![_fileManager fileExistsAtPath:ROOT_PATH_NS_VAR(kHistoryImagesPath) isDirectory:&isDirectory]) {
[_fileManager createDirectoryAtPath:ROOT_PATH_NS_VAR(kHistoryImagesPath) withIntermediateDirectories:YES attributes:nil error:nil];
}

if (![_fileManager fileExistsAtPath:kHistoryPath]) {
if (![_fileManager fileExistsAtPath:ROOT_PATH_NS_VAR(kHistoryPath)]) {
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:[[NSMutableDictionary alloc] init] options:NSJSONWritingPrettyPrinted error:nil];
[jsonData writeToFile:kHistoryPath options:NSDataWritingAtomic error:nil];
[jsonData writeToFile:ROOT_PATH_NS_VAR(kHistoryPath) options:NSDataWritingAtomic error:nil];
}
}
@end
1 change: 1 addition & 0 deletions Tweak/Core/Views/KayokoView.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// Created by Alexandra (@Traurige)
//

#import <rootless.h>
#import <UIKit/UIKit.h>
#import "KayokoHistoryTableView.h"
#import "KayokoFavoritesTableView.h"
Expand Down
3 changes: 2 additions & 1 deletion Tweak/Core/Views/KayokoView.m
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ - (void)showPreviewWithItem:(PasteboardItem *)item {
[[[self previewView] webView] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[item content]]]];
[[[self previewView] webView] setHidden:NO];
} else if ([item hasImage]) {
NSData* imageData = [[NSFileManager defaultManager] contentsAtPath:[NSString stringWithFormat:@"%@%@", kHistoryImagesPath, [item imageName]]];
NSString* path = [NSString stringWithFormat:@"%@%@", kHistoryImagesPath, [item imageName]];
NSData* imageData = [[NSFileManager defaultManager] contentsAtPath:ROOT_PATH_NS_VAR(path)];
[[[self previewView] imageView] setImage:[UIImage imageWithData:imageData]];
[[[self previewView] imageView] setHidden:NO];
} else {
Expand Down
2 changes: 1 addition & 1 deletion control
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: dev.traurige.kayoko
Name: Kayoko
Depends: firmware (>= 13.0), mobilesubstrate, preferenceloader, com.opa334.libsandy
Version: 1.4
Version: 1.4.2
Architecture: iphoneos-arm
Description: Feature rich clipboard manager for iOS
Maintainer: Traurige <[email protected]>
Expand Down
2 changes: 2 additions & 0 deletions layout/DEBIAN/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

if [ -d /var/mobile/Documents/dev.traurige/ ]; then
chown -R mobile:mobile /var/mobile/Documents/dev.traurige/
elif [ -d /var/jb/var/mobile/Documents/dev.traurige/ ]; then
chown -R mobile:mobile /var/jb/var/mobile/Documents/dev.traurige/
fi

if [[ -e /Library/LaunchDaemons/dev.traurige.kayokod.plist ]]; then
Expand Down

0 comments on commit 1b2559d

Please sign in to comment.