diff --git a/1.gif b/1.gif new file mode 100644 index 0000000..84bb5c3 Binary files /dev/null and b/1.gif differ diff --git a/ed2kTools.xcodeproj/project.pbxproj b/ed2kTools.xcodeproj/project.pbxproj index 32ab9d7..ad626a0 100755 --- a/ed2kTools.xcodeproj/project.pbxproj +++ b/ed2kTools.xcodeproj/project.pbxproj @@ -20,8 +20,8 @@ 045C52481BCD04E100DBC0D2 /* XPathQuery.m in Sources */ = {isa = PBXBuildFile; fileRef = 045C52451BCD04E100DBC0D2 /* XPathQuery.m */; }; 045C524A1BCD060A00DBC0D2 /* libxml2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 045C52491BCD060A00DBC0D2 /* libxml2.dylib */; }; 045C524C1BCD063900DBC0D2 /* libxml2.2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 045C524B1BCD063900DBC0D2 /* libxml2.2.dylib */; }; - 046509D11BD0BE5D006BE2DB /* ed2kClass.m in Sources */ = {isa = PBXBuildFile; fileRef = 046509D01BD0BE5D006BE2DB /* ed2kClass.m */; settings = {ASSET_TAGS = (); }; }; - 046509D31BD0D00B006BE2DB /* weibo.png in Resources */ = {isa = PBXBuildFile; fileRef = 046509D21BD0D00B006BE2DB /* weibo.png */; settings = {ASSET_TAGS = (); }; }; + 046509D11BD0BE5D006BE2DB /* ed2kClass.m in Sources */ = {isa = PBXBuildFile; fileRef = 046509D01BD0BE5D006BE2DB /* ed2kClass.m */; }; + 046509D31BD0D00B006BE2DB /* weibo.png in Resources */ = {isa = PBXBuildFile; fileRef = 046509D21BD0D00B006BE2DB /* weibo.png */; }; 04D563131BCD130700CFD69D /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 04D563121BCD130700CFD69D /* Foundation.framework */; }; 04D563151BCD130E00CFD69D /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 04D563141BCD130E00CFD69D /* AppKit.framework */; }; 04D563171BCD131500CFD69D /* CoreData.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 04D563161BCD131500CFD69D /* CoreData.framework */; }; @@ -29,6 +29,7 @@ 04F793671BD8E4CD00A68CFA /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 04F793661BD8E4CD00A68CFA /* CoreServices.framework */; }; 04F793691BD8E4D700A68CFA /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 04F793681BD8E4D700A68CFA /* Security.framework */; }; 04F7936B1BD8E4DF00A68CFA /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 04F7936A1BD8E4DF00A68CFA /* SystemConfiguration.framework */; }; + AA5792111DE808B600720919 /* WindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = AA5792101DE808B600720919 /* WindowController.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -74,6 +75,8 @@ 04F793661BD8E4CD00A68CFA /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = System/Library/Frameworks/CoreServices.framework; sourceTree = SDKROOT; }; 04F793681BD8E4D700A68CFA /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; 04F7936A1BD8E4DF00A68CFA /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; + AA57920F1DE808B600720919 /* WindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WindowController.h; sourceTree = ""; }; + AA5792101DE808B600720919 /* WindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WindowController.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -129,6 +132,8 @@ 045C523F1BCD04E100DBC0D2 /* Classes */, 045C521E1BCD040C00DBC0D2 /* AppDelegate.h */, 045C521F1BCD040C00DBC0D2 /* AppDelegate.m */, + AA57920F1DE808B600720919 /* WindowController.h */, + AA5792101DE808B600720919 /* WindowController.m */, 046509D21BD0D00B006BE2DB /* weibo.png */, 045C52231BCD040C00DBC0D2 /* ViewController.h */, 045C52241BCD040C00DBC0D2 /* ViewController.m */, @@ -292,6 +297,7 @@ buildActionMask = 2147483647; files = ( 045C52251BCD040C00DBC0D2 /* ViewController.m in Sources */, + AA5792111DE808B600720919 /* WindowController.m in Sources */, 045C52221BCD040C00DBC0D2 /* main.m in Sources */, 045C52201BCD040C00DBC0D2 /* AppDelegate.m in Sources */, 045C52461BCD04E100DBC0D2 /* TFHpple.m in Sources */, diff --git a/ed2kTools/AppDelegate.h b/ed2kTools/AppDelegate.h index fd7d31f..6963527 100755 --- a/ed2kTools/AppDelegate.h +++ b/ed2kTools/AppDelegate.h @@ -10,6 +10,6 @@ @interface AppDelegate : NSObject - +@property (nonatomic,strong) NSWindow*RootWindow; @end diff --git a/ed2kTools/AppDelegate.m b/ed2kTools/AppDelegate.m index 4b519b3..2b749dd 100755 --- a/ed2kTools/AppDelegate.m +++ b/ed2kTools/AppDelegate.m @@ -8,9 +8,6 @@ #import "AppDelegate.h" -@interface AppDelegate () - -@end @implementation AppDelegate @@ -21,5 +18,17 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { - (void)applicationWillTerminate:(NSNotification *)aNotification { // Insert code here to tear down your application } - +- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication + hasVisibleWindows:(BOOL)flag{ + // if (!flag){//是否有可见窗口 + //主窗口显示 + // [NSApp activateIgnoringOtherApps:NO]; + [self.RootWindow makeKeyAndOrderFront:self]; + + + // } + + + return YES; +} @end diff --git a/ed2kTools/Base.lproj/Main.storyboard b/ed2kTools/Base.lproj/Main.storyboard index 6ab5dc9..62802ea 100755 --- a/ed2kTools/Base.lproj/Main.storyboard +++ b/ed2kTools/Base.lproj/Main.storyboard @@ -1,8 +1,9 @@ - - + + - + + @@ -645,16 +646,15 @@ - + - + - - + @@ -670,38 +670,36 @@ - + - + - - + - + - + - + - - - + + @@ -715,9 +713,8 @@ - + - - + - @@ -836,12 +822,11 @@ - - - - - - - - - + + - - - - - - - - + - - - + diff --git a/ed2kTools/Info.plist b/ed2kTools/Info.plist index 2f0b180..ab1bf82 100755 --- a/ed2kTools/Info.plist +++ b/ed2kTools/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.0 + 1.1125 CFBundleSignature ???? CFBundleVersion diff --git a/ed2kTools/ViewController.m b/ed2kTools/ViewController.m index eca262b..806cefd 100755 --- a/ed2kTools/ViewController.m +++ b/ed2kTools/ViewController.m @@ -95,16 +95,10 @@ - (void)openURL:(NSString *)url inBackground:(BOOL)background } } - (IBAction)pushWibo:(id)sender { -// if (/* DISABLES CODE */ (YES)) -// { + NSArray* urls = [NSArray arrayWithObject:[NSURL URLWithString:@"http://weibo.com/u/2689574923"]]; [[NSWorkspace sharedWorkspace] openURLs:urls withAppBundleIdentifier:nil options:NSWorkspaceLaunchWithoutActivation additionalEventParamDescriptor:nil launchIdentifiers:nil]; -// } -// else -// { -// [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://weibo.com/u/2689574923"]]; -// } -// [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:@"http://weibo.com/u/2689574923"]]; + } - (IBAction)copyAllEd2k:(id)sender { NSString*str=[[NSString alloc]init]; @@ -162,8 +156,9 @@ - (IBAction)GoAction:(id)sender { if (self.getURLField.stringValue.length>5) { [ed2kArray removeAllObjects]; - [ed2kArray addObjectsFromArray:[self getEd2kSetUrl:[self FiltrationURL:self.getURLField.stringValue]]]; - [EtableView reloadData]; +// [ed2kArray addObjectsFromArray:[self getEd2kSetUrl:[self FiltrationURL:self.getURLField.stringValue]]]; + [self getEd2kSetUrl:self.getURLField.stringValue]; + }else if (self.getSearchField.stringValue.length>5){ // [ed2kArray removeAllObjects]; // [EtableView reloadData]; @@ -180,68 +175,78 @@ - (IBAction)GoAction:(id)sender { } } --(NSMutableArray*)getEd2kSetUrl:(NSString*)url{ - NSMutableArray*ListArray=[[NSMutableArray alloc]init]; - NSData*htmlData=[[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:url]]; - if (htmlData.length<100) { - - return [[NSMutableArray alloc]init]; - } - // TFHpple *xpathparser = [[TFHpple alloc]initWithHTMLData:htmlData]; - [xpathparser setValue:htmlData forKey:@"data"]; - NSString*ed2k; - NSArray*liS=[xpathparser searchWithXPathQuery:@"//a[@href]"]; - NSString* strClear; -// NSString *user; - NSRange range; - BOOL isAdd = NO; - for (TFHppleElement*tf in liS) { - if (tf.raw.length>200) { - - if ([[tf.raw componentsSeparatedByString:@"ed2k://"] count]>=2) { -// 查找ed2k链接 -// user = @"ed2k://.*.\\|\\/"; -// range = [tf.raw rangeOfString:user options:NSRegularExpressionSearch]; -// strClear=[NSString stringWithFormat:@"%@",[tf.raw substringWithRange:range]]; - strClear = [self TextrangeOfString:tf.raw setRegularExpressions:@"ed2k://.*.\\|\\/"]; - NSArray*strClearArray=[strClear componentsSeparatedByString:@"|/"]; - if (strClearArray.count<2) { - ed2k=[tf.raw substringWithRange:range]; - }else{ - ed2k=[NSString stringWithFormat:@"%@|/",strClearArray[0]]; +-(void)getEd2kSetUrl:(NSString*)url{ + + NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; + NSURLSession * session = [NSURLSession sharedSession]; + NSURLSessionDataTask * dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { + dispatch_async(dispatch_queue_create("download html queue", nil), ^{ + if (data.length<100) { + + } + + [xpathparser setValue:data forKey:@"data"]; + NSString*ed2k; + NSArray*liS=[xpathparser searchWithXPathQuery:@"//a[@href]"]; + NSString* strClear; + NSRange range; + BOOL isAdd = NO; + for (TFHppleElement*tf in liS) { + if (tf.raw.length>200) { + + if ([[tf.raw componentsSeparatedByString:@"ed2k://"] count]>=2) { + // 查找ed2k链接 + // user = @"ed2k://.*.\\|\\/"; + // range = [tf.raw rangeOfString:user options:NSRegularExpressionSearch]; + // strClear=[NSString stringWithFormat:@"%@",[tf.raw substringWithRange:range]]; + strClear = [self TextrangeOfString:tf.raw setRegularExpressions:@"ed2k://.*.\\|\\/"]; + NSArray*strClearArray=[strClear componentsSeparatedByString:@"|/"]; + if (strClearArray.count<2) { + ed2k=[tf.raw substringWithRange:range]; + }else{ + ed2k=[NSString stringWithFormat:@"%@|/",strClearArray[0]]; + } + isAdd = YES; + + }else if ([[tf.raw componentsSeparatedByString:@"magnet:?"] count]>=2){ + // 查找磁力链接 + // user = @"magnet:?[^\"]+"; + // range = [tf.raw rangeOfString:user options:NSRegularExpressionSearch]; + // strClear = [NSString stringWithFormat:@"%@",[tf.raw substringWithRange:range]]; + // ed2k = strClear; + ed2k = [self TextrangeOfString:tf.raw setRegularExpressions:@"magnet:?[^\"]+"]; + isAdd = YES; + } + + + if (range.location != NSNotFound && isAdd) { + // 排除空数据 + ed2kClass*e=[[ed2kClass alloc]init]; + e.ed2k=ed2k; + e.Name=[self searchEd2kName:ed2k]; + + [ed2kArray addObject:e]; + } + isAdd = NO; + } } - isAdd = YES; - }else if ([[tf.raw componentsSeparatedByString:@"magnet:?"] count]>=2){ -// 查找磁力链接 -// user = @"magnet:?[^\"]+"; -// range = [tf.raw rangeOfString:user options:NSRegularExpressionSearch]; -// strClear = [NSString stringWithFormat:@"%@",[tf.raw substringWithRange:range]]; -// ed2k = strClear; - ed2k = [self TextrangeOfString:tf.raw setRegularExpressions:@"magnet:?[^\"]+"]; - isAdd = YES; - } - - - if (range.location != NSNotFound && isAdd) { -// 排除空数据 - ed2kClass*e=[[ed2kClass alloc]init]; - e.ed2k=ed2k; - e.Name=[self searchEd2kName:ed2k]; - [ListArray addObject:e]; - } - isAdd = NO; - } - } - - - if (ListArray.count<=0) { -// 查找非标签内的ed2k - [ListArray addObjectsFromArray:[self getNotLabeWeb:[xpathparser searchWithXPathQuery:@"/*"]]]; - } + if (ed2kArray.count<=0) { + // 查找非标签内的ed2k + [ed2kArray addObjectsFromArray:[self getNotLabeWeb:[xpathparser searchWithXPathQuery:@"/*"]]]; + } + dispatch_async(dispatch_get_main_queue(), ^{ + // 更新界面 + + [EtableView reloadData]; + }); + }); + }]; + [dataTask resume]; + - return ListArray; +// return ListArray; } -(NSMutableArray*)getNotLabeWeb:(NSArray*)array{ diff --git a/ed2kTools/WindowController.h b/ed2kTools/WindowController.h new file mode 100644 index 0000000..696473e --- /dev/null +++ b/ed2kTools/WindowController.h @@ -0,0 +1,13 @@ +// +// WindowController.h +// ed2kTools +// +// Created by phlx-mac1 on 2016/11/25. +// Copyright © 2016年 Mac. All rights reserved. +// + +#import + +@interface WindowController : NSWindowController + +@end diff --git a/ed2kTools/WindowController.m b/ed2kTools/WindowController.m new file mode 100644 index 0000000..cb5a682 --- /dev/null +++ b/ed2kTools/WindowController.m @@ -0,0 +1,72 @@ +// +// WindowController.m +// ed2kTools +// +// Created by phlx-mac1 on 2016/11/25. +// Copyright © 2016年 Mac. All rights reserved. +// + +#import "WindowController.h" +#import "AppDelegate.h" + +@interface WindowController () +@property BOOL mouseDownInTopToolBar; +@property (assign) NSPoint initialLocation; + +@end + +@implementation WindowController + +- (void)windowDidLoad { + [super windowDidLoad]; + AppDelegate* app =(AppDelegate*)[NSApplication sharedApplication].delegate; + app.RootWindow = self.window; + + // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file. +} +- (void)mouseDown:(NSEvent *)theEvent +{ + self.initialLocation = [theEvent locationInWindow]; + NSRect windowFrame = [self.window frame]; + CGFloat heightOfTitleBarAndTopToolBar = 65; + NSRect titleFrame = NSMakeRect(0, windowFrame.size.height-heightOfTitleBarAndTopToolBar, windowFrame.size.width, heightOfTitleBarAndTopToolBar); + + if(NSPointInRect(self.initialLocation, titleFrame)) + { + self.mouseDownInTopToolBar = YES; + NSLog(@"Mouse IN"); + } +} + +-(void)mouseUp:(NSEvent *)theEvent +{ + self.mouseDownInTopToolBar = NO; + NSLog(@"Mouse UP"); +} + +- (void)mouseDragged:(NSEvent *)theEvent +{ + if( self.mouseDownInTopToolBar ) + { + NSRect screenVisibleFrame = [[NSScreen mainScreen] visibleFrame]; + NSRect windowFrame = [self.window frame]; + + NSPoint newOrigin = windowFrame.origin; + NSPoint currentLocation = [theEvent locationInWindow]; + + + + // Update the origin with the difference between the new mouse location and the old mouse location. + newOrigin.x += (currentLocation.x - self.initialLocation.x); + newOrigin.y += (currentLocation.y - self.initialLocation.y); + + // Don't let window get dragged up under the menu bar + if ((newOrigin.y + windowFrame.size.height) > (screenVisibleFrame.origin.y + screenVisibleFrame.size.height)) { + newOrigin.y = screenVisibleFrame.origin.y + (screenVisibleFrame.size.height - windowFrame.size.height); + } + + [self.window setFrameOrigin:newOrigin]; + } +} + +@end