Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1567|回复: 3
打印 上一主题 下一主题

sysinfo

[复制链接]

1228

主题

1997

帖子

7578

积分

认证用户组

Rank: 5Rank: 5

积分
7578
跳转到指定楼层
楼主
发表于 2020-9-9 17:59:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 Qter 于 2020-9-9 18:45 编辑

var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");


Services.sysinfo.getProperty("name")
  1.   XPCOMUtils.defineLazyGetter(this, "OSVersion", function UFS_OSVersion() {
  2.     let OSVersion = "default";
  3.     let sysInfo = Cc["@mozilla.org/system-info;1"].getService(
  4.       Ci.nsIPropertyBag2
  5.     );
  6.     try {
  7.       OSVersion =
  8.         sysInfo.getProperty("name") + " " + sysInfo.getProperty("version");
  9.       OSVersion += " (" + sysInfo.getProperty("secondaryLibrary") + ")";
  10.     } catch (e) {}

  11.     return encodeURIComponent(OSVersion);
  12.   });
复制代码
https://searchfox.org/comm-central/source/mozilla/xpcom/build/components.conf#191
  1. {
  2.         'js_name': 'sysinfo',
  3.         'cid': '{d962398a-99e5-49b2-857a-c159049c7f6c}',
  4.         'contract_ids': ['@mozilla.org/system-info;1'],
  5.         'interfaces': ['nsIPropertyBag2', 'nsISystemInfo'],
  6.         'type': 'nsSystemInfo',
  7.         'headers': ['nsSystemInfo.h'],
  8.         'init_method': 'Init',
  9.         'overridable': True,
  10.     },
复制代码
https://searchfox.org/comm-central/source/mozilla/xpcom/base/nsSystemInfo.h
https://searchfox.org/comm-central/source/mozilla/xpcom/base/nsSystemInfo.cpp

PR_SI_RELEASE_BUILD
https://searchfox.org/comm-central/source/mozilla/nsprpub/pr/src/misc/prsystem.c#155
https://searchfox.org/comm-central/source/mozilla/nsprpub/pr/include/prsystem.h#48


_PR_MD_GETSYSINFO -> _MD_GETSYSINFO -> _MD_WindowsGetSysInfo
https://searchfox.org/comm-centr ... indows/ntmisc.c#811
PRStatus _MD_WindowsGetSysInfo(PRSysInfo cmd, char *name, PRUint32 namelen)




回复

使用道具 举报

1228

主题

1997

帖子

7578

积分

认证用户组

Rank: 5Rank: 5

积分
7578
沙发
 楼主| 发表于 2020-9-10 14:31:31 | 只看该作者
本帖最后由 Qter 于 2020-9-10 14:33 编辑

Resolving Redefinition Errors Betwen ws2def.h and winsock.h
https://www.zachburlingame.com/2011/05/resolving-redefinition-errors-betwen-ws2def-h-and-winsock-h/
The Solution
You basically have three options to fix this:
Option 1: WIN32_LEAN_AND_MEAN
Defining WIN32_LEAN_AND_MEAN will reduce the size of the Windows headers by excluding several APIs, including Windows Sockets.
  1. #define WIN32_LEAN_AND_MEAN
  2. #include <Windows.h>
  3. #include <WinSock2.h>

  4. int main( int argc, char* argv[] )
  5. {
  6.   return 0;
  7. }
复制代码
Option 2: Explicitly include WinSock2.h before Windows.h
By explicitly including WinSock2.h before every place that you Windows.h, you prevent the collision. However, this can be quite cumbersome at times.
UPDATE 2011-11-12:This method can cause issues with struct packing and alignment if WIN32 isn’t defined before including WinSock2.h (see Oren’s comment below). To resolve this issue, either define WIN32 as a preprocessor flag in your project or explicitly define #WIN32 prior to the WinSock2.h include as I’ve done below.

  1. #ifndef WIN32
  2.   #define WIN32
  3. #endif
  4. #include <WinSock2.h>
  5. #include <Windows.h>

  6. int main( int argc, char* argv[] )
  7. {
  8.   return 0;
  9. }
复制代码

Option 3: Create a WinSock Wrapper Header
This option creates a header file that prevents the collision in the first place and then you include this at (or nearest as possible) to the top of every file that needs WinSock2.h.
The following is based on code from this stackoverflowanswer.

  1. #ifndef _WINSOCK_WRAPPER_H_
  2. #define _WINSOCK_WRAPPER_H_

  3. #if _MSC_VER > 1000
  4. #pragma once
  5. #endif

  6. #ifndef _WINDOWS_
  7. #define WIN32_LEAN_AND_MEAN
  8. #include <windows.h>
  9. #undef WIN32_LEAN_AND_MEAN
  10. #endif

  11. #include <winsock2.h>

  12. #pragma comment(lib, "ws2_32.lib")

  13. #endif
复制代码

If the #pragma option above is unfamiliar to you, the compiler passes it along to the linker telling it to include the lib rather than having to set it in the project settings. Theres more on #pragma comment options over on MSDN.



回复 支持 反对

使用道具 举报

1228

主题

1997

帖子

7578

积分

认证用户组

Rank: 5Rank: 5

积分
7578
板凳
 楼主| 发表于 2020-9-10 18:24:55 | 只看该作者
回复 支持 反对

使用道具 举报

1228

主题

1997

帖子

7578

积分

认证用户组

Rank: 5Rank: 5

积分
7578
地板
 楼主| 发表于 2020-9-10 18:28:22 | 只看该作者
this._hddData = await Services.sysinfo.diskInfo;
let osData = await Services.sysinfo.osInfo;
https://searchfox.org/comm-central/source/mozilla/toolkit/components/telemetry/app/TelemetryEnvironment.jsm#1086

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|firemail ( 粤ICP备15085507号-1 )

GMT+8, 2024-4-29 08:51 , Processed in 0.059311 second(s), 18 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表