Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 18th, 2012  |  syntax: None  |  size: 8.49 KB  |  views: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. //  AppDelegate.m
  3. //  Settings
  4. //
  5. //
  6.  
  7.  
  8. #import "AppDelegate.h"
  9.  
  10. #pragma mark -
  11. #pragma mark MainViewController
  12. #pragma mark -
  13.  
  14. @implementation MainViewController
  15.  
  16. - (id) init {
  17.     self = [ super initWithStyle: UITableViewStyleGrouped ];
  18.  
  19.     if (self != nil) {
  20.         self.title = @"Cyfix";
  21.     }
  22.     return self;
  23. }
  24.  
  25. - (void) loadView {
  26.     [ super loadView ];
  27. }
  28.  
  29. - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
  30. {
  31.     return (interfaceOrientation == UIInterfaceOrientationPortrait);
  32. }
  33.  
  34. - (void)didReceiveMemoryWarning {
  35.     [ super didReceiveMemoryWarning ];
  36. }
  37.  
  38. - (void)dealloc {
  39.     [ super dealloc ];
  40. }
  41.  
  42.  
  43. @end
  44.  
  45. #pragma mark -
  46. #pragma mark AppDelegate
  47. #pragma mark -
  48.  
  49. @implementation AppDelegate
  50.  
  51. @synthesize window;
  52. @synthesize viewController;
  53.  
  54. - (void)applicationDidFinishLaunching:(UIApplication *)application 
  55. {    
  56.  
  57.     // If you want the status bar to be hidden at launch use this:
  58.     //  application.statusBarHidden = YES;
  59.     //
  60.     // To set the status bar as black, use the following:
  61.     // application.statusBarStyle = UIStatusBarStyleBlackOpaque;
  62.  
  63.  
  64.     // Create window
  65.     window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  66.     
  67.     // this helps in debugging, so that you know "exactly" where your views are placed;
  68.     // if you see "red", you are looking at the bare window, otherwise use black
  69.     // window.backgroundColor = [UIColor redColor];
  70.  
  71.     viewController = [ [ MainViewController alloc ] init ];
  72.  
  73.     navigationController = [ [ UINavigationController alloc ] initWithRootViewController: viewController ];
  74.  
  75.     /* Anchor the view to the window */
  76.     [window addSubview:[navigationController view]];
  77.  
  78.     /* Make the window key and visible */
  79.     [window makeKeyAndVisible];
  80.  
  81. //code here
  82.  
  83.  
  84. info = [[UILabel alloc] initWithFrame: CGRectMake(75, 50, 190, 25)];
  85.  
  86. info.font = [UIFont boldSystemFontOfSize: 14];
  87.  
  88. info.backgroundColor = [UIColor clearColor];
  89.  
  90. info.textColor = [UIColor darkGrayColor];
  91.  
  92. info.shadowColor = [UIColor whiteColor];
  93.  
  94. info.shadowOffset = CGSizeMake(0, -1.0);
  95.  
  96. info.text = @"enter the buggy repo's URL";
  97.  
  98. [viewController.view addSubview: info];
  99.  
  100. url = [ [ UITextField alloc ] initWithFrame: CGRectMake(80, 90, 170, 27) ];
  101.        url.adjustsFontSizeToFitWidth = YES;
  102.        url.textColor = [UIColor blackColor];
  103.        url.font = [UIFont systemFontOfSize:17.0];
  104.        url.placeholder = @"";
  105.        url.backgroundColor = [UIColor clearColor];
  106.        url.autocorrectionType = UITextAutocorrectionTypeNo;
  107.        url.autocapitalizationType = UITextAutocapitalizationTypeNone;
  108.        url.textAlignment = UITextAlignmentLeft;
  109.        url.keyboardType = UIKeyboardTypeDefault;
  110.        url.returnKeyType = UIReturnKeyDone;
  111.        url.tag = 0;
  112.        url.delegate = self;
  113.        
  114.        url.clearButtonMode = UITextFieldViewModeAlways;
  115.        url.text = @"";
  116.        url.borderStyle = UITextBorderStyleRoundedRect;
  117.        [url setEnabled: YES];
  118.  
  119.     [viewController.view addSubview: url];
  120.  
  121.  
  122. buttonImage = [[UIImage alloc] initWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @"button" ofType: @"png"]];
  123.  
  124. fixMe = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
  125.      fixMe.frame = CGRectMake(65, 150, 80, 25);
  126.      [fixMe setTitle:@"fix me!" forState:UIControlStateNormal];
  127.      [fixMe setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  128.      [fixMe setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
  129.      [fixMe setTitle:@"Running..." forState:UIControlStateHighlighted];
  130.      [fixMe setBackgroundImage:buttonImage forState:UIControlStateHighlighted];
  131.      [fixMe setBackgroundImage:buttonImage forState:UIControlStateNormal];
  132.      [fixMe addTarget:self action:@selector(fixButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
  133.  
  134.      [viewController.view addSubview: fixMe];
  135.  
  136.  
  137. showRepos = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
  138.      showRepos.frame = CGRectMake(165, 150, 100, 25);
  139.      [showRepos setTitle:@"show repos" forState:UIControlStateNormal];
  140.      [showRepos setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  141.      [showRepos setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
  142.      [showRepos setTitle:@"Running..." forState:UIControlStateHighlighted];
  143.      [showRepos setBackgroundImage:buttonImage forState:UIControlStateHighlighted];
  144.      [showRepos setBackgroundImage:buttonImage forState:UIControlStateNormal];
  145.      [showRepos addTarget:self action:@selector(repoButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
  146.  
  147.      [viewController.view addSubview: showRepos];
  148.  
  149.  
  150.  
  151. //cmd code
  152.  
  153.  
  154. repoTask = [[NSTask alloc] init];
  155. [repoTask setLaunchPath:@"/bin/bash"];
  156. [repoTask setArguments:[NSArray arrayWithObjects: [[NSBundle mainBundle] pathForResource: @"repoList" ofType: @"sh"], nil]];
  157.  
  158.     NSPipe *pipe;
  159.     pipe = [NSPipe pipe];
  160.     [repoTask setStandardOutput: pipe];
  161.  
  162.     NSFileHandle *file;
  163.     file = [pipe fileHandleForReading];
  164.  
  165.     [repoTask launch];
  166.     [repoTask waitUntilExit];
  167.  
  168.     NSData *data;
  169.     data = [file readDataToEndOfFile];
  170.  
  171.     cmdReturn = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
  172.  
  173. //put repos into array
  174. repoArray = [cmdReturn componentsSeparatedByString:@"\n"];
  175. //end array code
  176.  
  177. //end cmd code
  178.  
  179.  
  180.  
  181. //end code here
  182.  
  183. }
  184.  
  185.  
  186.  
  187.  
  188. - (void) repoButtonPressed:(id)sender{
  189.  
  190.  
  191. repoAlert = [[UIAlertView alloc] initWithTitle:@"installed repos" message: cmdReturn delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
  192.  
  193. [repoAlert show];
  194.  
  195.  
  196. }
  197.  
  198.  
  199. - (void) fixButtonPressed:(id)sender{
  200.  
  201.  
  202. for (i=0;i< [repoArray count];i++)
  203. {
  204.     if ([[repoArray objectAtIndex: i]  isEqualToString: url.text]) {
  205.         found = YES;
  206.         break;
  207.     } else {
  208.         found = NO;
  209.     }
  210. }
  211.  
  212. if (found == YES){
  213.  
  214. if ([url.text length] != 0){
  215. task = [[NSTask alloc] init];
  216. [task setLaunchPath:@"/bin/bash"];
  217. [task setArguments:[NSArray arrayWithObjects:[[NSBundle mainBundle]
  218. pathForResource:@"cyfix" ofType:@"sh"], nil]];
  219.  
  220.     inputPipe = [NSPipe pipe];
  221.     [task setStandardInput: inputPipe];
  222.  
  223.     inputHandle = [inputPipe fileHandleForWriting];
  224.  
  225.     [task launch];
  226.  
  227. userInput = url.text;
  228.  
  229.  
  230. input = [userInput stringByAppendingString:@"\n"];
  231.  
  232. inputData = [input dataUsingEncoding:
  233. NSUTF8StringEncoding allowLossyConversion: YES];
  234.  
  235. [inputHandle writeData: inputData];
  236.  
  237. [task waitUntilExit];
  238.  
  239. alert = [[UIAlertView alloc] initWithTitle:@"Output" message: @"Done!" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
  240. [alert show];
  241. [alert release];
  242.  
  243. }else{
  244.  
  245. alert = [[UIAlertView alloc] initWithTitle:@"error" message:@"please enter a repo URL" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
  246. [alert show];
  247. [alert release];
  248.  
  249. }
  250.  
  251. }else{
  252.  
  253. UIAlertView *foundAlert = [[UIAlertView alloc] initWithTitle:@"error" message:@"repo not found" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
  254. [foundAlert show];
  255. [foundAlert release];
  256.  
  257. }
  258. }
  259.  
  260.  
  261. - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
  262. {
  263.  // low on memory: do whatever you can to reduce your memory foot print here
  264. }
  265.  
  266.  
  267. - (void)dealloc
  268. {
  269.     [viewController release];
  270.     [navigationController release];
  271.  
  272.     [buttonImage release];
  273.     [fixMe release];
  274.     [showRepos release];
  275.     [info release];
  276.     [url release];
  277.  
  278.     [inputPipe release];
  279.     [inputHandle release];
  280.     [userInput release];
  281.     [inputData release];
  282.  
  283.     [super dealloc];
  284. }
  285.  
  286. @end