-
Notifications
You must be signed in to change notification settings - Fork 2
/
Tweak.xm
105 lines (82 loc) · 3.26 KB
/
Tweak.xm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//
// ToneEnabler.xm
//
// Created by eni9889 on 12-24-2013.
// Copyright 2013 UnlimApps Inc. All rights reserved.
//
%group IOS7
%hook TKToneTableController
- (id)loadRingtonesFromPlist
{
NSDictionary *original = %orig;
NSMutableDictionary *allRingtones = [NSMutableDictionary dictionary];
NSMutableArray *classicRingtones = [NSMutableArray arrayWithArray:[original objectForKey:@"classic"]];
NSMutableArray *modernRingtones = [NSMutableArray arrayWithArray:[original objectForKey:@"modern"]];
NSString *tonesDirectory = @"/Library/Ringtones";
NSFileManager *localFileManager = [[NSFileManager alloc] init];
NSDirectoryEnumerator *dirEnum = [localFileManager enumeratorAtPath:tonesDirectory];
NSString *file;
while ((file = [dirEnum nextObject]))
{
if ([[file pathExtension] isEqualToString: @"m4r"])
{
NSString *properToneIdentifier = [NSString stringWithFormat:@"system:%@",[file stringByDeletingPathExtension]];
BOOL isClassicTone = [classicRingtones containsObject:properToneIdentifier];
BOOL isModernTone = [modernRingtones containsObject:properToneIdentifier];
if(!isClassicTone && !isModernTone)
{
[modernRingtones addObject:properToneIdentifier];
}
}
}
[allRingtones setObject:classicRingtones forKey:@"classic"];
[allRingtones setObject:modernRingtones forKey:@"modern"];
return allRingtones;
}
%end
%end
%group IOS8
%hook TKTonePickerController
- (id)_loadTonesFromPlistNamed:(id)arg1 {
%log;
if ([arg1 isEqualToString:@"TKRingtones"]) {
NSDictionary *original = %orig;
NSMutableDictionary *allRingtones = [NSMutableDictionary dictionary];
NSMutableArray *classicRingtones = [NSMutableArray arrayWithArray:[original objectForKey:@"classic"]];
NSMutableArray *modernRingtones = [NSMutableArray arrayWithArray:[original objectForKey:@"modern"]];
NSString *tonesDirectory = @"/Library/Ringtones";
NSFileManager *localFileManager = [[NSFileManager alloc] init];
NSDirectoryEnumerator *dirEnum = [localFileManager enumeratorAtPath:tonesDirectory];
NSString *file;
while ((file = [dirEnum nextObject]))
{
if ([[file pathExtension] isEqualToString: @"m4r"])
{
NSString *properToneIdentifier = [NSString stringWithFormat:@"system:%@",[file stringByDeletingPathExtension]];
BOOL isClassicTone = [classicRingtones containsObject:properToneIdentifier];
BOOL isModernTone = [modernRingtones containsObject:properToneIdentifier];
if(!isClassicTone && !isModernTone)
{
[modernRingtones addObject:properToneIdentifier];
}
}
}
[allRingtones setObject:classicRingtones forKey:@"classic"];
[allRingtones setObject:modernRingtones forKey:@"modern"];
return allRingtones;
} else {
return %orig;
}
}
%end
%end
%ctor {
Class klass = NSClassFromString(@"TKTonePickerController");
if (klass) {
NSLog(@"ToneEnabler iOS 8");
%init(IOS8);
} else {
NSLog(@"ToneEnabler iOS 7");
%init(IOS7);
}
}