Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // AppDelegate.m
- // Settings
- //
- //
- #import "AppDelegate.h"
- #pragma mark -
- #pragma mark MainViewController
- #pragma mark -
- @implementation MainViewController
- - (id) init {
- self = [ super initWithStyle: UITableViewStyleGrouped ];
- if (self != nil) {
- self.title = @"Cyfix";
- }
- return self;
- }
- - (void) loadView {
- [ super loadView ];
- }
- - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
- {
- return (interfaceOrientation == UIInterfaceOrientationPortrait);
- }
- - (void)didReceiveMemoryWarning {
- [ super didReceiveMemoryWarning ];
- }
- - (void)dealloc {
- [ super dealloc ];
- }
- @end
- #pragma mark -
- #pragma mark AppDelegate
- #pragma mark -
- @implementation AppDelegate
- @synthesize window;
- @synthesize viewController;
- - (void)applicationDidFinishLaunching:(UIApplication *)application
- {
- // If you want the status bar to be hidden at launch use this:
- // application.statusBarHidden = YES;
- //
- // To set the status bar as black, use the following:
- // application.statusBarStyle = UIStatusBarStyleBlackOpaque;
- // Create window
- window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- // this helps in debugging, so that you know "exactly" where your views are placed;
- // if you see "red", you are looking at the bare window, otherwise use black
- // window.backgroundColor = [UIColor redColor];
- viewController = [ [ MainViewController alloc ] init ];
- navigationController = [ [ UINavigationController alloc ] initWithRootViewController: viewController ];
- /* Anchor the view to the window */
- [window addSubview:[navigationController view]];
- /* Make the window key and visible */
- [window makeKeyAndVisible];
- //code here
- info = [[UILabel alloc] initWithFrame: CGRectMake(75, 50, 190, 25)];
- info.font = [UIFont boldSystemFontOfSize: 14];
- info.backgroundColor = [UIColor clearColor];
- info.textColor = [UIColor darkGrayColor];
- info.shadowColor = [UIColor whiteColor];
- info.shadowOffset = CGSizeMake(0, -1.0);
- info.text = @"enter the buggy repo's URL";
- [viewController.view addSubview: info];
- url = [ [ UITextField alloc ] initWithFrame: CGRectMake(80, 90, 170, 27) ];
- url.adjustsFontSizeToFitWidth = YES;
- url.textColor = [UIColor blackColor];
- url.font = [UIFont systemFontOfSize:17.0];
- url.placeholder = @"";
- url.backgroundColor = [UIColor clearColor];
- url.autocorrectionType = UITextAutocorrectionTypeNo;
- url.autocapitalizationType = UITextAutocapitalizationTypeNone;
- url.textAlignment = UITextAlignmentLeft;
- url.keyboardType = UIKeyboardTypeDefault;
- url.returnKeyType = UIReturnKeyDone;
- url.tag = 0;
- url.delegate = self;
- url.clearButtonMode = UITextFieldViewModeAlways;
- url.text = @"";
- url.borderStyle = UITextBorderStyleRoundedRect;
- [url setEnabled: YES];
- [viewController.view addSubview: url];
- buttonImage = [[UIImage alloc] initWithContentsOfFile: [[NSBundle mainBundle] pathForResource: @"button" ofType: @"png"]];
- fixMe = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
- fixMe.frame = CGRectMake(65, 150, 80, 25);
- [fixMe setTitle:@"fix me!" forState:UIControlStateNormal];
- [fixMe setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [fixMe setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
- [fixMe setTitle:@"Running..." forState:UIControlStateHighlighted];
- [fixMe setBackgroundImage:buttonImage forState:UIControlStateHighlighted];
- [fixMe setBackgroundImage:buttonImage forState:UIControlStateNormal];
- [fixMe addTarget:self action:@selector(fixButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
- [viewController.view addSubview: fixMe];
- showRepos = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
- showRepos.frame = CGRectMake(165, 150, 100, 25);
- [showRepos setTitle:@"show repos" forState:UIControlStateNormal];
- [showRepos setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- [showRepos setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
- [showRepos setTitle:@"Running..." forState:UIControlStateHighlighted];
- [showRepos setBackgroundImage:buttonImage forState:UIControlStateHighlighted];
- [showRepos setBackgroundImage:buttonImage forState:UIControlStateNormal];
- [showRepos addTarget:self action:@selector(repoButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
- [viewController.view addSubview: showRepos];
- //cmd code
- repoTask = [[NSTask alloc] init];
- [repoTask setLaunchPath:@"/bin/bash"];
- [repoTask setArguments:[NSArray arrayWithObjects: [[NSBundle mainBundle] pathForResource: @"repoList" ofType: @"sh"], nil]];
- NSPipe *pipe;
- pipe = [NSPipe pipe];
- [repoTask setStandardOutput: pipe];
- NSFileHandle *file;
- file = [pipe fileHandleForReading];
- [repoTask launch];
- [repoTask waitUntilExit];
- NSData *data;
- data = [file readDataToEndOfFile];
- cmdReturn = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
- //put repos into array
- repoArray = [cmdReturn componentsSeparatedByString:@"\n"];
- //end array code
- //end cmd code
- //end code here
- }
- - (void) repoButtonPressed:(id)sender{
- repoAlert = [[UIAlertView alloc] initWithTitle:@"installed repos" message: cmdReturn delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
- [repoAlert show];
- }
- - (void) fixButtonPressed:(id)sender{
- for (i=0;i< [repoArray count];i++)
- {
- if ([[repoArray objectAtIndex: i] isEqualToString: url.text]) {
- found = YES;
- break;
- } else {
- found = NO;
- }
- }
- if (found == YES){
- if ([url.text length] != 0){
- task = [[NSTask alloc] init];
- [task setLaunchPath:@"/bin/bash"];
- [task setArguments:[NSArray arrayWithObjects:[[NSBundle mainBundle]
- pathForResource:@"cyfix" ofType:@"sh"], nil]];
- inputPipe = [NSPipe pipe];
- [task setStandardInput: inputPipe];
- inputHandle = [inputPipe fileHandleForWriting];
- [task launch];
- userInput = url.text;
- input = [userInput stringByAppendingString:@"\n"];
- inputData = [input dataUsingEncoding:
- NSUTF8StringEncoding allowLossyConversion: YES];
- [inputHandle writeData: inputData];
- [task waitUntilExit];
- alert = [[UIAlertView alloc] initWithTitle:@"Output" message: @"Done!" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
- [alert show];
- [alert release];
- }else{
- alert = [[UIAlertView alloc] initWithTitle:@"error" message:@"please enter a repo URL" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
- [alert show];
- [alert release];
- }
- }else{
- UIAlertView *foundAlert = [[UIAlertView alloc] initWithTitle:@"error" message:@"repo not found" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
- [foundAlert show];
- [foundAlert release];
- }
- }
- - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
- {
- // low on memory: do whatever you can to reduce your memory foot print here
- }
- - (void)dealloc
- {
- [viewController release];
- [navigationController release];
- [buttonImage release];
- [fixMe release];
- [showRepos release];
- [info release];
- [url release];
- [inputPipe release];
- [inputHandle release];
- [userInput release];
- [inputData release];
- [super dealloc];
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement