firemail

标题: sysinfo [打印本页]

作者: Qter    时间: 2020-9-9 17:59
标题: sysinfo
本帖最后由 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)





作者: Qter    时间: 2020-9-10 14: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.




作者: Qter    时间: 2020-9-10 18:24
// Setup the command line arguments to sign the MAR.
https://searchfox.org/comm-central/source/mozilla/modules/libmar/tests/unit/test_sign_verify.js#22

作者: Qter    时间: 2020-9-10 18:28
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






欢迎光临 firemail (http://firemail.wang:8088/) Powered by Discuz! X3