Tweak to pull updates, and bypass the 24 hour limit.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

130 lines
4.4KB

  1. /* Imports */
  2. #import <CoreData/CoreData.h>
  3. #import <UIKit/UIKit.h>
  4. #include <substrate.h>
  5. /* Definitions (Macros) */
  6. #define Bundle_Path @"/Library/MobileSubstrate/DynamicLibraries/MovieBoxBundle.bundle"
  7. #define Queued_Update @"Update has been queued and will commence soon."
  8. #define AlertTitle @"Movie Box Updater"
  9. #define AlertDownload @"Download Working"
  10. #define AlertDismiss @"Dismiss"
  11. #define AlertOK @"OK"
  12. #define UpdateCheck_URL @"http://gh0stbyte.ga/iOS/moviebox.json"
  13. #define UpdateCheck_Local @"3.6.4"
  14. #define UpdateCheck_Alert @"There is an update available for this tweak."
  15. /* Fake interface to allow calling of the update function, along with new sharedInstance */
  16. @interface UpdatesManager : NSObject
  17. /* Fool the compiler into thinking that we have the method */
  18. - (void)requestUpdatedDataBaseWithFileURL:(NSString*)url;
  19. /* Create sharedInstance method */
  20. + (id)sharedInstance;
  21. @end
  22. /* Variables */
  23. static UIView *header;
  24. static UpdatesManager *sharedInstance = nil;
  25. NSString *updateURL;
  26. %hook MenuViewController
  27. /* When it sets up the headerView */
  28. -(UIView*)headerView {
  29. /* set the headerview to itself */
  30. header = %orig;
  31. /* Give it a second to create the header before adding to it */
  32. [NSTimer scheduledTimerWithTimeInterval:1.0
  33. target:self
  34. selector:@selector(setupButton)
  35. userInfo:nil
  36. repeats:NO];
  37. /* return the header variable which is itself */
  38. return header;
  39. }
  40. %new
  41. /* New function called 1 second after headerView called allowing time for it to be created */
  42. -(void)setupButton {
  43. // Update Available Check
  44. NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:UpdateCheck_URL]];
  45. [NSURLConnection sendAsynchronousRequest:request
  46. queue:[NSOperationQueue mainQueue]
  47. completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
  48. NSDictionary *myjson = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL];
  49. updateURL = @"http://sbfunapi.cc/data/data_en.zip";
  50. NSString *current_version = [myjson objectForKey:@"current_version"];
  51. if(![current_version isEqualToString:UpdateCheck_Local]) {
  52. UIAlertView *a = [[UIAlertView alloc] initWithTitle:AlertTitle message:UpdateCheck_Alert delegate:self cancelButtonTitle:AlertOK otherButtonTitles:@"Update", nil];
  53. [a show];
  54. [a release];
  55. }
  56. }];
  57. CGFloat height = CGRectGetHeight(header.bounds);
  58. CGFloat width = CGRectGetWidth(header.bounds);
  59. // Create a new button that will trigger database updates.
  60. UIButton *updateButton = [[UIButton alloc] initWithFrame:CGRectMake((width - 63), ((height/2) +3.333333), 20.0, 20.0)];
  61. // When button pressed, updateDB function will be called
  62. [updateButton addTarget:self
  63. action:@selector(updateDB)
  64. forControlEvents:UIControlEventTouchUpInside];
  65. // Set the image of the button
  66. [updateButton setImage:[UIImage imageWithContentsOfFile:[[[NSBundle alloc] initWithPath:Bundle_Path] pathForResource:@"refresh" ofType:@"png"]] forState:UIControlStateNormal];
  67. // Add button to the header UIView (header)
  68. [header addSubview:updateButton];
  69. }
  70. %new
  71. /* Function to update the Database */
  72. -(void)updateDB {
  73. /* Let the user know that the update has been queued. Good for older phones that take a while to actually show the update process, and prevent the user
  74. from spamming the update button. */
  75. UIAlertView *a = [[UIAlertView alloc] initWithTitle:AlertTitle message:Queued_Update delegate:nil cancelButtonTitle:AlertOK otherButtonTitles:nil];
  76. [a show];
  77. [a release];
  78. /* Use the sharedInstance function (returns the current instance) to call the requestUpdateBlah function with our updateURL grabbed from the server */
  79. [[%c(UpdatesManager) sharedInstance] requestUpdatedDataBaseWithFileURL:updateURL];
  80. }
  81. %new
  82. // When the user presses a button
  83. - (void)alertView :(UIAlertView*)alertView clickedButtonAtIndex: (NSInteger)buttonIndex {
  84. if([[alertView buttonTitleAtIndex:buttonIndex] isEqualToString: @"Update"]) {
  85. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://cydia.dtathemes.com/"]];
  86. }
  87. }
  88. %end
  89. %hook UpdatesManager
  90. /* When an UpdatesManager instance is created */
  91. - (id)init
  92. {
  93. /* we set our sharedInstance to be the current instance of the UpdatesManager */
  94. sharedInstance = %orig;
  95. /* Then we return the sharedInstance which is itself */
  96. return sharedInstance;
  97. }
  98. /* Create new sharedInstance */
  99. %new
  100. + (id)sharedInstance
  101. {
  102. /* It returns the current instance of the UpdatesManger */
  103. return sharedInstance;
  104. }
  105. %end