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 辅助接口的更多相关文章

  1. 抽象类 VS 接口

    引言 接口和抽象类是面向对象编程(OOP, Object Oriented programming)中两个绕不开的概念,二者相似而又有所不同.接下来,我们来了解二者的概念并比较它们的异同. 什么是抽象 ...

  2. C#知识点:抽象类和接口浅谈

    首先介绍什么是抽象类? 抽象类用关键字abstract修饰的类就是叫抽象类,抽象类天生的作用就是被继承的,所以不能实例化,只能被继承.而且 abstract 关键字不能和sealed一起使用,因为se ...

  3. 0026 Java学习笔记-面向对象-抽象类、接口

    抽象方法与抽象类 抽象方法用abstract修饰,没有方法体部分,连花括号都不能有: 抽象方法和抽象类都用abstract修饰 包含抽象方法的类一定是抽象类:但不包含抽象方法的类也可以是抽象类 不能创 ...

  4. 【RL-TCPnet网络教程】第5章 PHY芯片和STM32的MAC基础知识

    第5章        PHY芯片和STM32的MAC基础知识 本章节为大家讲解STM32自带的MAC和PHY芯片的基础知识,为下一章底层驱动的讲解做一个铺垫. 5.1   初学者重要提示 5.2    ...

  5. C#_接口与抽象类

    .Net提供了接口,这个不同于Class或者Struct的类型定义.接口有些情况,看似和抽象类一样,因此有些人认为在.Net可以完全用接口来替换抽象类.其实不然,接口和抽象类各有长处和缺陷,因此往往在 ...

  6. windows平台下获取网卡MAC地址、硬盘序列号、主板序列号、CPU ID、BIOS序列号

    转自http://blog.csdn.net/jhqin/article/details/5548656,如有侵权,请联系本人删除,谢谢!! 头文件:WMI_DeviceQuery.h /* ---- ...

  7. mac与phy怎样实现网络自适应

    这两天改动网卡驱动以实现10/100/1000M自适应,因此研究了下phy芯片和emac驱动怎样兼容10/100/1000M网络环境,记录在此. 网络中设备端数据链路层由mac芯片和phy芯片组成.p ...

  8. Mac OS 网络设置教程 wifi设置与宽带设置详解

    虽然所有设备连接无线网络的步骤都相差无几,但是Mac与windows系统还是不相同的,那么,苹果Mac怎么连接无线网络呢?针对此问题,本文就为大家介绍Mac网络的设置教程,有兴趣的朋友们可以了解下.如 ...

  9. SSD接口详解,再也不会买错固态硬盘了

    http://stor.51cto.com/art/201808/582349.htm 硬盘知识科普中,我们提到了SSD的发展史虽短,但是种类和协议比HDD不知道多到哪里去了.因此,本期小编就通过接口 ...

随机推荐

  1. Linux下进行硬盘挂载、分区、删除分区,格式化,卸载方法

    本文简单介绍了下文件系统及其操作(df命令),磁盘分区.格式化,还有最主要是挂载操作. 在这里对"挂载"做个说明,我们都知道文件系统是创建在磁盘上面的,每个文件系统都有独立的ino ...

  2. CCS学习(三)

    边框样式  边框线 dorder-style (top 上: bottom 下:  left 左: right 右)  样式:none | hidden | dotted | dashed | sol ...

  3. spring 框架的xml文件如何读取properties文件数据

    spring 框架的xml文件如何读取properties文件数据 第一步:在spring配置文件中 注意:value可以多配置几个properties文件 <bean id="pro ...

  4. CSS3-loading动画(四)

    图片看的效果真是不行,还是戳下面网址看吧 在线示例:http://liyunpei.xyz/loading.html 十七.效果十七 三个小球,纵向居中,间距撑开,依次改变小球的translateY的 ...

  5. 常见MD5加密解密值及免费解密网站

    常用的MD5解密 MD5(admin,16)    = 7a57a5a743  MD5(admin,16)    = 7a57a5a743894a0e  MD5(admin888,16) = 469e ...

  6. ubuntu(linux)新装系统恢复备份后无法进入系统问题的解决

    1. 引子: 可以跳过直接看3.~5. 我们可能会遇到这样的状况,从ubuntu转到别的系统,兜兜转转又回到了ubuntu. 比如说: Fedora升级后一大堆BUG,与java有关的软件渲染都糟糕的 ...

  7. css3变换,过度,动画实现梦幻网页

    html和css3一出,整个互联网设计发生了颠覆性的改变,各大IT企业也推出了很多新颖的设计,比如百度浏览器的下载首页,fullpage设计风格加css动画让网页看起来很流畅舒服. css3的变换有3 ...

  8. 51nod_1298:圆与三角形(计算几何)

    题目链接 判断圆和三角形是否相交   可以转化为   判断三条线段是否和圆相交 #include<iostream> #include<cstdio> #include< ...

  9. jenkins - MultiJob使用

    我们如果使用jenkins需要由串行,并行,传递参数和等待执行的功能的话,那我们会用到jenkins里面的两个东西:MultiJob和pipeline 这里我介绍下MultiJob的使用 实例任务的拓 ...

  10. 【Django】中间件

    Middleware 这个地方把所有Request 拦截住,用我们自己的方式完成处理以后直接返回 Response.因此了解中间件的构成是非常必要的. Initializer: __init__(se ...