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. MyBatis源码解析【1】准备工作

    终于迎来了这一天,我觉得现在的我在经历了长时间的学习和开发之后有了一定的经验,所以准备开始学习源码. 今天我将做好充足的准备,在接下来的一个月中,努力的爬过这座大山.(可能不用一个月,但是我觉得需要仔 ...

  2. Java基础语法<三> 输入输出

    1. 读取输入 Scanner in = new Scanner(System.in);   输入一行(包含空格) String str = in.nextLine()   读取一个单词(以空白符作为 ...

  3. Unreal Engine 4(虚幻UE4)GameplayAbilities 插件入门教程(四)技能屏蔽和简单的Buff等

    本节内容继续上一节教程的内容(如果没有看过前面的教程,请前往学习),不会讲太难的新东西,而是继续探究技能标签(Abiilty Tags)的内容.先来一道开胃菜. 第1.1步: 将上一次的召唤冰龙中的C ...

  4. 快手 Android 工程师面经

    看着我把简历投完之后弹出的"完成"字样,我就十分的激动了,我是一名应届毕业生,老老实实的那种,学过的知识我都一步一个脚印的复习的完了,Lintcode上该刷的题,也妥妥的完成了,但 ...

  5. PC-lint集成于SourceInsight 范例以及简单分析;提高代码的健壮性;

    写代码之际突然想起了pc-lint这个"古董级"的代码静态分析工具;   下午机房的服务器歇菜了,没法调试游戏,刚好抽出时间来研究一下pc-lint集成在SourceInsight ...

  6. Android Bitmap 常见的几个操作:缩放,裁剪,旋转,偏移

    Android Bitmap 相关操作 常见的几个操作:缩放,裁剪,旋转,偏移      很多操作需要 Matrix 来支持:Matrix 通过矩阵来处理位图,计算出各个像素点的位置,从而把bitma ...

  7. xdu_1077:循环节长度

    题意很简单,就是给出p,q,求p/q的循环节长度. 由循环小数的循环部分的值等于等比数列求和的值S,列公式得到最简分数分母的值.最终得10^x%q==1(其中q为经过modify之后的值).搞清这些之 ...

  8. hdu_5964:平行四边形

    打重现赛时,一点思路也没有,然后又看到这题AC数那么少,就直接放弃了.今天重新看了看,借鉴了下别人的,发现此题应该算是一道可解题. 看上去,这题的ans是同时有两个点作为自变量的函数(然而n^2复杂度 ...

  9. ubuntu下使用 chkconfig 是一种习惯

    ubuntu下使用 chkconfig 是一种习惯 习惯了chkconfig命令, 闲来写了个脚本模拟下, 步骤很简单. 如下: 第一步, 安装sysv-rc-conf sudo apt instal ...

  10. 将域名转移到 Google Domains

    之前存放域名用过 Godaddy.Dynadot.Namesilo 也有阿里云(万网)和腾讯云(新网),这回就用 Google Domains 啦! 话说 Google Domains 早已是 201 ...