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. C# 定时器传值问题详解

    //传参数定时器 private static System.Timers.Timer aTimer;  Main(ApprovalID); public static void Main(int A ...

  2. (转载)DBCP、C3P0、Proxool 、 BoneCP开源连接池的比较

    原文链接: http://blog.csdn.net/miclung/article/details/7231553    简介   使用评价  项目主页  DBCP DBCP是一个依赖Jakarta ...

  3. Ajax获取数据的几种格式和解析方式

    一.什么是ajax  AJAX的全称是Asynchronous JavaScript and XML(是异步的 javascript 和 XML).  ajax不是新的编程语言,而是一种使用现有标准的 ...

  4. QQ空间魔力日志大全SduSRZ

    大家好~最近,在QQ空间里出现了一种神奇的日志,谁看显示谁的信息,在个人中心显示的是一张图片,在日志里显示的又是另一张图片.这就是传说中的魔力日志.魔力日志从今年的9月份开始盛行,因为具有谁看就针对谁 ...

  5. 基于Node.js的微信JS-SDK后端接口实现

    做了一个网站,放到线上,用微信打开,点击分享,可是分享后发给朋友的链接卡片是微信默认自带的,如下: 这标题,描述以及图片是默认自带的,丑不说,分享给别人还以为是盗号网站呢,而接入微信的JSSDK后,分 ...

  6. .net 爬虫框架技术选型

    个人认为爬虫框架分抓取框架和分析框架 1)抓取框架 .net 市面上好的似乎不多,选择要素分两种:1.轻量型,2.重量型. 1. 轻量型是可以定制一些特殊的功能或者插件开关形式.总体性能高,速度快. ...

  7. The first day,I get a blogs!!

    我拥有了自己的博客,很happy! 今天学习了kvm,虽然命令行界面比较枯燥,还好不算太难,在大家的热心帮助下我创建了一个虚拟机!!

  8. 二叉树 - 建立与遍历使用Java

    二叉树的遍历(traversing binary tree)是指从根节点出发,按照某种次序依次访问二叉树中所有节点,使得每个节点仅被访问一次 前序遍历:若二叉树为空,则空操作返回null.否则先访问根 ...

  9. HashSet TreeSet 源码

    1 HashSet 1.1 父类 java.lang.Object 继承者 java.util.AbstractCollection<E> 继承者 java.util.AbstractSe ...

  10. POJ 2566 尺取法(进阶题)

    Bound Found Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 4297   Accepted: 1351   Spe ...