mac 辅助接口
mac 辅助接口
1.打开文件所在目录并选中该文件
2.获取plist属性值
3.系统关机
4.打开系统网络设置
5.字符串包含比较
6.系统挂载数及挂载盘符信息
//====================================================
1.打开文件所在目录并选中该文件
<1>.cocoa NSWorkspace方式
void MacOpenLocateFileInWindow(const char *pChFilePath)
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *nsStrFilePath = [[NSString alloc] initWithUTF8String:pChFilePath];
NSURL *nsFileURL = [NSURL fileURLWithPath:nsStrFilePath];
NSWorkspace *nsWorkSpace = [NSWorkspace sharedWorkspace];
[nsWorkSpace selectFile:[nsFileURL path] inFileViewerRootedAtPath:nil]; [pool drain];
return;
}
接口测试:
char *chStrPath;
MacOpenLocateFileInWindow(chStrPath);
<2>.Qt QProcess方式
QString strFilePath;
QStringList scriptArgs;
scriptArgs << QLatin1String("-e")
<< QString::fromLatin1("tell application \"Finder\" to reveal POSIX file \"%1\"").arg(strFilePath);
QProcess::execute(QLatin1String("/usr/bin/osascript"), scriptArgs);
scriptArgs.clear();
scriptArgs << QLatin1String("-e")
<< QLatin1String("tell application \"Finder\" to activate");
QProcess::execute("/usr/bin/osascript", scriptArgs);
2.获取plist属性值
int MacGetInfoAttribute(char *pChAttribute, const char *pChKey)
{
int iRet = -;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *nsStrAttribute = nil;
NSString *nsStrKey = [[NSString alloc] initWithUTF8String:pChKey];
nsStrAttribute = [[NSBundle mainBundle] objectForInfoDictionaryKey:nsStrKey]; if (nil != nsStrAttribute)
{
const char *pChAtt = [nsStrAttribute UTF8String];
int iLen = [nsStrAttribute length]; memset(pChAttribute, , );
memcpy(pChAttribute, pChAtt, iLen);
iRet = ;
} [nsStrKey release];
nsStrKey = nil; [pool drain];
return iRet;
}
接口测试:
char chVersion[];
memset(chVersion, , );
int iRet = GetInfoAttribute(chVersion, "CFBundleVersion");
3.系统关机
void MacShutDown()
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSDictionary *errorDict = nil;
NSAppleEventDescriptor *returnDescriptor = nil; NSAppleScript *scriptObject = [[NSAppleScript alloc] initWithSource:
@"tell application \"Finder\" to shut down"];
returnDescriptor = [scriptObject executeAndReturnError:&errorDict];
if (nil == returnDescriptor)
{
//no script result, handle error here
} [scriptObject release];
scriptObject = nil; [pool drain];
return;
}
4.打开系统网络设置
void MacActivateNetworkPreference()
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSDictionary *errorDict = nil;
NSAppleEventDescriptor *returnDescriptor = nil; NSAppleScript *scriptObject = [[[NSAppleScript alloc] initWithSource:
@"tell application \"System Preferences\"\n"
@"activate\n"
@"set current pane to pane \"com.apple.preference.network\"\n"
@"end tell\n"] autorelease]; returnDescriptor = [scriptObject executeAndReturnError:&errorDict];
if (nil == returnDescriptor)
{
//no script result, handle error here
} [pool drain];
return;
}
5.字符串包含比较
bool MacCaseStrContains(const char *pSourceStr, const char *pSearchStr)
{
bool bRet = false;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *nsSource = [[NSString alloc] initWithUTF8String:pSourceStr];
int iSourceLen = [nsSource length];
[nsSource release];
nsSource = nil; NSString *nsSearch = [[NSString alloc] initWithUTF8String:pSearchStr];
int iSearchLen = [nsSearch length];
[nsSearch release];
nsSearch = nil; if (iSourceLen<= || iSearchLen<= || iSearchLen>iSourceLen)
{
[pool drain];
return bRet;
} int iChSource, iChSearch;
do{
iChSource = tolower(*pSourceStr++);
iChSearch = tolower(*pSearchStr++);
}while ((--iSearchLen>) && iChSource==iChSearch && iChSource!=); if ( == iChSource-iChSearch)
{
bRet = true;
} [pool drain];
return bRet;
}
6.系统挂载数及挂载盘符信息
typedef struct {
char chDrivePath[];
char chDriveVolume[];
}STRUCT_DRIVE_INFO;
<1>.系统挂载数
int MacGetMountedPointNums()
{
int iMountPoint = ;
struct statfs *buf = NULL;
iMountPoint = getmntinfo(&buf, );
return iMountPoint;
}
<2>.挂载盘符信息
int MacGetMountedDriveInfo(STRUCT_DRIVE_INFO *structDriveInfo, int iMoundtedNums)
{
int iMountNum = ;
if (iMoundtedNums <= )
{
return iMountNum;
} NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; DASessionRef session = DASessionCreate(kCFAllocatorDefault);
if (session)
{
unsigned i, count = ;
struct statfs *buf = NULL; count = getmntinfo(&buf, );
for (i=; i<count; i++)
{
DADiskRef disk = DADiskCreateFromBSDName(kCFAllocatorDefault, session, buf[i].f_mntfromname);
if (disk)
{
CFDictionaryRef details = DADiskCopyDescription(disk);
if (details)
{
if (kCFBooleanTrue == CFDictionaryGetValue(details, kDADiskDescriptionMediaRemovableKey))
{
NSDictionary *dd = (NSDictionary*) DADiskCopyDescription(disk);
if (dd)
{
if (==memcmp(buf[i].f_fstypename, "udf", ) && iMountNum<iMoundtedNums)
{
NSString *nsStrVolumeName = [dd objectForKey:(NSString*)kDADiskDescriptionVolumeNameKey];
int iLen = [nsStrVolumeName length];
memset(structDriveInfo[iMountNum].chDriveVolume, , );
memcpy(structDriveInfo[iMountNum].chDriveVolume, [nsStrVolumeName UTF8String], iLen); NSString *nsStrDrivePath = [NSString stringWithUTF8String:buf[i].f_mntonname];
iLen = [nsStrDrivePath length];
memset(structDriveInfo[iMountNum].chDrivePath, , );
memcpy(structDriveInfo[iMountNum].chDrivePath, [nsStrDrivePath UTF8String], iLen);
iMountNum++;
} [dd release];
dd = nil;
}
}
CFRelease(details);
}
CFRelease(disk);
}
}
CFRelease(session);
} [pool drain];
return iMountNum;
}
接口测试:
int iMountPoint = MacGetMountedPointNums();
if (iMountPoint > )
{
STRUCT_DRIVE_INFO stDriveInfo[iMountPoint];
int iNums = MacGetMountedDriveInfo(stDriveInfo, iMountPoint);
}
mac 辅助接口的更多相关文章
- 抽象类 VS 接口
引言 接口和抽象类是面向对象编程(OOP, Object Oriented programming)中两个绕不开的概念,二者相似而又有所不同.接下来,我们来了解二者的概念并比较它们的异同. 什么是抽象 ...
- C#知识点:抽象类和接口浅谈
首先介绍什么是抽象类? 抽象类用关键字abstract修饰的类就是叫抽象类,抽象类天生的作用就是被继承的,所以不能实例化,只能被继承.而且 abstract 关键字不能和sealed一起使用,因为se ...
- 0026 Java学习笔记-面向对象-抽象类、接口
抽象方法与抽象类 抽象方法用abstract修饰,没有方法体部分,连花括号都不能有: 抽象方法和抽象类都用abstract修饰 包含抽象方法的类一定是抽象类:但不包含抽象方法的类也可以是抽象类 不能创 ...
- 【RL-TCPnet网络教程】第5章 PHY芯片和STM32的MAC基础知识
第5章 PHY芯片和STM32的MAC基础知识 本章节为大家讲解STM32自带的MAC和PHY芯片的基础知识,为下一章底层驱动的讲解做一个铺垫. 5.1 初学者重要提示 5.2 ...
- C#_接口与抽象类
.Net提供了接口,这个不同于Class或者Struct的类型定义.接口有些情况,看似和抽象类一样,因此有些人认为在.Net可以完全用接口来替换抽象类.其实不然,接口和抽象类各有长处和缺陷,因此往往在 ...
- windows平台下获取网卡MAC地址、硬盘序列号、主板序列号、CPU ID、BIOS序列号
转自http://blog.csdn.net/jhqin/article/details/5548656,如有侵权,请联系本人删除,谢谢!! 头文件:WMI_DeviceQuery.h /* ---- ...
- mac与phy怎样实现网络自适应
这两天改动网卡驱动以实现10/100/1000M自适应,因此研究了下phy芯片和emac驱动怎样兼容10/100/1000M网络环境,记录在此. 网络中设备端数据链路层由mac芯片和phy芯片组成.p ...
- Mac OS 网络设置教程 wifi设置与宽带设置详解
虽然所有设备连接无线网络的步骤都相差无几,但是Mac与windows系统还是不相同的,那么,苹果Mac怎么连接无线网络呢?针对此问题,本文就为大家介绍Mac网络的设置教程,有兴趣的朋友们可以了解下.如 ...
- SSD接口详解,再也不会买错固态硬盘了
http://stor.51cto.com/art/201808/582349.htm 硬盘知识科普中,我们提到了SSD的发展史虽短,但是种类和协议比HDD不知道多到哪里去了.因此,本期小编就通过接口 ...
随机推荐
- cygwin安装gcc/g++
安装cygwin如果按照默认的方式一直点下去的话,安装完了会发现没有安装gcc/g++. 这个时候可以在安装文件的目录打开命令行,并输入: setup-x86_64.exe -q -P wget -P ...
- vijos1196题解
Matrix67和Shadow正在做一个小游戏. 桌子上放着两堆糖果,Matrix67和Shadow轮流对这些糖果进行操作.在每一次操作中,操作者需要吃掉其中一堆糖果,并且把另一堆糖果分成两堆(可以不 ...
- Jenkins的安装配置
Jenkins的安装配置 一.Jenkins简介 Jenkins 是一个可扩展的持续集成引擎.Jenkins可以帮我们将代码进行统一的编译打包.还可以放到tomcat容器中进行发布.简单来说就是我们通 ...
- RabbitMQ系列教程之七:RabbitMQ的 C# 客户端 API 的简介
今天这篇博文是我翻译的RabbitMQ的最后一篇文章了,介绍一下RabbitMQ的C#开发的接口.好了,言归正传吧. Net/C# 客户端 API简介1.主要的命名空间,接口和类 定义核心的API的 ...
- 使用iframe父页面调用子页面和子页面调用父页面的元素与方法
在实际的项目开发中,iframe框架经常使用,主要用于引入其他的页面.下面主要介绍一下使用iframe引入其他页面后,父页面如何调用子页面的方法和元素以及子页面如何调用父页面的方法和元素. 1.父页面 ...
- tensorflow max_pool(最大池化)应用
1.最大池化 max pooling是CNN当中的最大值池化操作,其实用法和卷积很类似. tf.nn.max_pool(value, ksize, strides, padding, name=Non ...
- (转)java反射机制及简单工厂模式
第一步,定义一个接口类 package factory.face; /** * 接口,为了保证返回的对象可以统一用 Product接受 * @author Administrator */ publi ...
- 初学Python(九)——函数
初学Python(九)--函数 初学Python,主要整理一些学习到的知识点,这次是函数. 函数定义: # -*- coding:utf-8 -*- #函数的定义 def my_function(x) ...
- vc++MFC开发上位机程序
用vc++MFC开发过不少跟单片机通讯的上位机程序了.搞懂了MFC架构,开发还是很快的,与底层单片机程序通讯,可以用串口.usb.网络.短信形式.串口现在用的越来越少了,一般电脑跟单片机在一块,使用串 ...
- Tomcat和Java Virtual Machine的性能调优总结
就算生不逢时,也该理解理解了.已经在Java界快混迹3年了,对于一些性能调优的话题我是一直插不上嘴,只是针对昨晚看到的一篇性能调优的文章,我忍不住了. Tomcat性能调优: 找到Tomcat根目录下 ...