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不知道多到哪里去了.因此,本期小编就通过接口 ...
随机推荐
- SDP
SDP语法 一个SDP描述含有会话级信息和媒体级信息.会话级信息应用于整个会话.例如:它能成为会话始发者或者会话的名字.媒体级信息作用于特殊的媒体流.例如:它能作为一个编码器给音频流编码或者是给视频流 ...
- 结巴(jieba)中文分词及其应用实践
中文文本分类不像英文文本分类一样只需要将单词一个个分开就可以了,中文文本分类需要将文字组成的词语分出来构成一个个向量.所以,需要分词. 这里使用网上流行的开源分词工具结巴分词(jieba),它可以有效 ...
- java操作DBF的使用
1.引入javadbf.4.1.jar 2. import com.linuxense.javadbf.DBFField; import com.linuxense.javadbf.DBFRead ...
- jdk和jre有什么区别?
简单的说JDK是面向开发人员使用的SDK,它提供了Java的开发环境和运行环境.SDK是Software Development Kit 一般指软件开发包,可以包括函数库.编译程序等. JDK就是Ja ...
- CJOJ 1494 【网络流24题】 搭配飞行员(二分图最大匹配)
CJOJ 1494 [网络流24题] 搭配飞行员(二分图最大匹配) Description 飞行大队有若干个来自各地的驾驶员,专门驾驶一种型号的飞机,这种飞机每架有两个驾驶员,需一个正驾驶员和一个副驾 ...
- 1、微信小程序----弹幕的实现(无后台)
小程序刚刚出来,现在网上的demo是多,但是要找到一个自己需要的却不容易.今天跟大家分享自己写的一个弹幕功能. 先来一张效果图: 我的思路是这样的,先用<switch>标签确定是否打开弹幕 ...
- JavaWeb开发技术基础概念回顾篇
JavaWeb开发技术基础概念回顾篇 第一章 动态网页开发技术概述 1.JSP技术:JSP是Java Server Page的缩写,指的是基于Java服务器端动态网页. 2.JSP的运行原理:当用户第 ...
- Selenium对浏览器支持的版本
最新的selenium与几种常用浏览器的版本兼容情况: selenium 3.4.0 : Mozilla GeckoDriver 0.18 -- Firefox 53 - 56 Google Ch ...
- (转)java之runnable jar与普通jar
背景:项目中有时候需要导出相关的jar包,可是总是不能分清楚. 1 导出包 导出普通jar包(可作为第三方库,类似dll,so等) 在eclipse中右键选择except->java->j ...
- (转)流量加速插件 FinalSpeed介绍及一键安装教程
原文章连接:https://blog.kuoruan.com/82.html 1 介绍 官方介绍:FinalSpeed是高速双边加速软件,可加速所有基于tcp协议的网络服务,在高丢包和高延迟环境下,仍 ...