在本文中,我们将详细介绍Git扩展:Win32错误487:无法为cygwin的堆预留空间,Win32错误0的各个方面,并为您提供关于无法为tomclancy执行启动程序的相关解答,同时,我们也将为您带
在本文中,我们将详细介绍Git 扩展:Win32 错误 487:无法为 cygwin 的堆预留空间,Win32 错误 0的各个方面,并为您提供关于无法为tom clancy执行启动程序的相关解答,同时,我们也将为您带来关于Cocos 在win32 平台上显示中文(仅实现win32)、Cocos2d-x项目移植(Win32至IOS,Win32至Android)、com.intellij.openapi.util.io.win32.IdeaWin32的实例源码、com.sun.jna.platform.win32.Win32Exception的实例源码的有用知识。
本文目录一览:- Git 扩展:Win32 错误 487:无法为 cygwin 的堆预留空间,Win32 错误 0(无法为tom clancy执行启动程序)
- Cocos 在win32 平台上显示中文(仅实现win32)
- Cocos2d-x项目移植(Win32至IOS,Win32至Android)
- com.intellij.openapi.util.io.win32.IdeaWin32的实例源码
- com.sun.jna.platform.win32.Win32Exception的实例源码
Git 扩展:Win32 错误 487:无法为 cygwin 的堆预留空间,Win32 错误 0(无法为tom clancy执行启动程序)
Git 扩展: 直到昨天一切正常。
但是当我尝试使用拉一些存储库时突然出现此错误git extensions
C:\Program Files\Git\bin\git.exe pull --progress "origin" Done 0 [main] us 0 init_cheap: VirtualAlloc pointer is null, Win32 error 487AllocationBase 0x0, BaseAddress 0x68560000, RegionSize 0x390000, State 0x10000C:\Program Files\Git\bin\sh.exe: *** Couldn''t reserve space for cygwin''s heap, Win32 error 0
我克隆的所有存储库都在发生这种情况。但是,我的 git bash 工作正常。我不知道发生了什么。知道为什么会这样吗?
答案1
小编典典Cygwin 使用持久共享内存部分,这些部分有时会损坏。其症状是某些 Cygwin
程序开始失败,但其他应用程序不受影响。由于这些共享内存部分是持久的,因此通常需要 重新启动系统 以清除它们,然后才能解决问题。
Cocos 在win32 平台上显示中文(仅实现win32)
测试显示 中文或者 其它平台已经判断显示的 可以借用这偷懒的方法
在cocos-x 3.2,vs2012 环境中运行的
在所使用的.h文件中私有添加
inline std::string WideByte2UTF8(const wstring& text) { int asciisize = ::WideCharToMultiByte(CP_UTF8,text.c_str(),text.size(),NULL,NULL); if (asciisize == ERROR_NO_UNICODE_TRANSLATION || asciisize == 0) { return string(); } char* resultstring = new char[asciisize]; int convresult = ::WideCharToMultiByte(CP_UTF8,resultstring,asciisize,NULL); if (convresult != asciisize) { return string(); } std::string buffer(resultstring,convresult); delete[] resultstring; return buffer; }
在cpp中调用
std::string str = ""; str = WideByte2UTF8(L"你好世界"); Label* label = Label::createWithSystemFont(str.c_str(),"Arial",20); label->setColor(Color3B::RED); label->setPosition(200,200); this->addChild(label);
Cocos2d-x项目移植(Win32至IOS,Win32至Android)
1、前面的三个Cocos2d-x小游戏都是在VS中编写的,但是这些游戏实际上应该运行在手机或是平板等手持设备上。这就涉及到一个移植的问题。因为Cocos2d-x是由C++编写的,而IOS和Android又都有C++的编程接口,所以Cocos2d-x具备了跨平台的可移植性。2、相对来说,将项目移植IOS环境比较简单,如果电脑装有MAC系统只需要转一个XCode,以及一个Cocos2d-x的插件即可,然后利用插件向导新建一个项目,将待移植的工程中的.cpp和.h以及资源文件文件复制进去编译即可。
另注:main.h、main.cpp、Resource.h等文件不用复制。
3、如果没有苹果电脑,那么可以考虑虚拟机,问题往往出在安装虚拟机以及在虚拟机上安装MAC系统上。但是相对来说,在虚拟机上安装MAC系统比直接在机器上安装MAC容易的多。本人亲测,在i3,8G内存笔记本上用虚拟机安装OSXMavericks10.9(GM).iso,运行流畅,并且编译移植的cocos2d-x项目成功。(稍后如果有时间,会做一个教程)
4、以上是移植到IOS环境,下面介绍移植到Android环境,安卓因为涉及到Java的SDK以及NDK等内容,所以实现起来比较复杂。并且由于Cocos2d-x的版本比较多,各个版本之间的改动也比较到,所以教程不好写,最多针对某一特定版本的Cocos2d-x。
5、就我这两天的尝试可知,Cocos2d-x2.0.4和Cocos2d-x2.2.1库文件改动不大,在Win32下前者编写的工程可以无需修改在后者直接编译,但是移植到Android中时完全不同。前者需使用cyWin,而后者可以利用Python。就本人感觉而言,利用Python比较简单。
6、下面就来介绍如何将Win32下的Cocos2d-x项目移植到Android中,首先是用到的工具以及软件:
链接:http://pan.baidu.com/s/1hq5lY2w密码:ydxq
7、打开上述链接,显示如下:
8、首先,搭建Java环境:
(1)安装JDK(jdk-7u45-windows-x64.exe)
注1:根据自己的电脑选择32位或是64位版
注2:安装JDK的时候会同时安装对应的JRE
(2)配置环境变量:
系统变量→新建JAVA_HOME变量。变量值填写JDK的安装目录(默认是C:\ProgramFiles\Java\jdk1.7.0_45)
系统变量→寻找Path变量→编辑在变量值最后输入%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;(如果原值后面无分号,请添加一个分号)
完成后确定,打开CMD,键入java-version查看设置是否成功(显示如下表示环境变量设置成功):
9、其次,安装Python(python-2.7.5.msi):
因为我原先装过,所以界面如下,直接点下一步即可:
设置Python的环境变量:
默认安装在C盘:
系统变量→寻找Path变量→编辑在变量值最后输入C:\Python27(如果原值后面无分号,请添加一个分号)
10、解压缩adt-bundle-windows-x86_64-20131030.zip
(1)解压后的根目录:
(2)进入eclipse目录:
(3)双击运行eclipse.exe文件:(注:这一步需先装JDK并配置环境变量)
(4)新建一个Android项目,用于检测AndroidEclipse开发环境:
右键项目Test,Runas->AndroidApplication:
(5)如果没有创建Android虚拟机或者连接Android手机,会弹出如下提示:
(6)选择Yes后弹出如下界面:
(7)如果有Android手机,可以打开调试模式,用数据线连接到电脑(需要安装驱动,装个手机助手)。如果成功连接大豆电脑,会在ChoosingarunningAndroiddevice下显示,选择它点击OK就行了。
(8)如果不想连接Android手机,那么可以创建一个虚拟机,选中LaunchaNewAndroidDevice:
单击Manager...
(9)弹出如下窗口,选择NEW:
(10)弹出新建虚拟设备窗口,添加设备名,勾选UseHostGpu:
(11)OK后虚拟设备创建完成,如下:
(12)关闭上面的窗口,在下图窗口点击Refresh:
(13)选中刚创建的设备MyAndroid,点击OK:
(14)如果前面操作没问题的话,虚拟机就会运行,效果如下:
12、至此,Android的Eclipse环境搭建好了。
13、下面解压cocos2d-x-2.2.1.zip,解压后根目录(../cocos2d-x-2.2.1)文件如下:
14、将python.bat这个批处理程序复制到tools目录下的project-creator文件夹中:
15、右键以管理员身份运行python.bat:
根据提示创建一个项目:
16、现在进入Cocos2d-x的projects文件夹,会出现一个刚才创建的项目:
17、打开Eclipse,导入刚刚创建的项目cocos2dx_fighting:
导入刚刚创建的项目cocos2dx_fighting:
点击Finish后,文件列表:
18、我们看到刚才导入的项目还有错误,接下去继续设置。
19、
(1)将
...\cocos2d-x-2.2.1\cocos2dx\platform\android\java\src
下的org文件夹整个复制到
...\cocos2d-x-2.2.1\projects\cocos2dx_fighting\proj.android\src
目录中
(2)将
...\cocos2d-x-2.2.1\projects\cocos2dx_fighting\Resources
目录下的所有文件复制到
...\cocos2d-x-2.2.1\projects\cocos2dx_fighting\proj.android\assets
文件夹中
20、下面再在Eclipse中配置几个项目相关的路径,预先解压NDK(android-ndk-r9c-windows-x86_64.zip):
(1)右键cocos2dx_fighting项目,点击Properties:
选择C/C++Build,修改Buildcommand:为NDK的ndk-build.cmd文件的路径:
(2)切换到Resource,选择LinkedResources,添加一个COCOS2DX的路径:
21、上面几项每新建一个项目都需要重新设置,接下来设置3个不需重复设置的变量:
Window->Preferences
22、添加3个值:NDK_ROOT、NDK_MODULE_PATH、COCOS2DX
23、至此,所有配置完成,右键项目Refresh,Buildproject:
24、build的时间会有点长,我的电脑大概要5分钟,编译完成:
25、接下来,右键工程,Runas,AndroidApplication:
26、接下去导入Win32下编写的Cocosd-x格斗游戏至Android环境:
27、将待移植项目的.h和.cpp文件复制到cocos2dx_fighting工程下的Classes文件夹下(覆盖):
28、将待移植项目Resources目录下的所有内容复制到
目录下:
29、打开Eclipse右键工程cocos2dx_fighting->Refresh,Project->BuildProject。此时,可以尝试Runas->AndroidApplication:
你会发现,还是HelloWorld那个程序的界面,因为你导入的文件根本没有编译:
30、打开Android.mk文件:
31、添加cpp文件:
32、Project->BuildProject:
错误信息如下:
33、显然是ui64不识别,修改如下(最好不要在Eclipse中打开修改,而是用EditPlus或是直接yongVS打开修改):
GameDefines.h中
34、修改后保存,Eclipse中Refresh,然后BuildProject:
35、Build成功(警告可以不管),运行Runas->AndroidApplication:
36、OK,在工程的\cocos2d-x-2.2.1\projects\cocos2dx_fighting\proj.android\bin下回生成一个cocos2dx_fighting.apk,复制到手机安装运行。(虚拟机实在启动的太慢了,另外有时会卡壳重启,就不贴图了):
37、上面几张图是我手机上运行的截图。
38、至此,移植成功。另外:cocos2dx_fighting.apk
原文来自:http://www.58player.com/blog-2388-102251.html
com.intellij.openapi.util.io.win32.IdeaWin32的实例源码
public static void loadplatformlibrary(@NotNull String libName) { String libFileName = mapLibraryName(libName); String libPath = PathManager.getBinPath() + "/" + libFileName; if (!new File(libPath).exists()) { String platform = getPlatformName(); if (!new File(libPath = PathManager.getHomePath() + "/community/bin/" + platform + libFileName).exists()) { if (!new File(libPath = PathManager.getHomePath() + "/bin/" + platform + libFileName).exists()) { if (!new File(libPath = PathManager.getHomePathFor(IdeaWin32.class) + "/bin/" + libFileName).exists()) { File libDir = new File(PathManager.getBinPath()); throw new UnsatisfiedLinkError("'" + libFileName + "' not found in '" + libDir + "' among " + Arrays.toString(libDir.list())); } } } } System.load(libPath); }
@NotNull private static FileAttributes getAttributes(@NotNull final File file,final boolean checkList) { final FileAttributes attributes = FileSystemUtil.getAttributes(file); assertNotNull(attributes); if (SystemInfo.isWindows && checkList) { final String parent = file.getParent(); if (parent != null) { final FileInfo[] infos = IdeaWin32.getInstance().listChildren(parent); assertNotNull(infos); for (FileInfo info : infos) { if (file.getName().equals(info.getName())) { assertEquals(attributes,info.toFileAttributes()); return attributes; } } fail(file + " not listed"); } } return attributes; }
@NotNull private static FileAttributes getAttributes(@NotNull final File file,info.toFileAttributes()); return attributes; } } fail(file + " not listed"); } } return attributes; }
@Nonnull private static FileAttributes getAttributes(@Nonnull final File file,final boolean checkList) { final FileAttributes attributes = FileSystemUtil.getAttributes(file); assertNotNull(attributes); System.out.println(attributes + ": " + file); if (SystemInfo.isWindows && checkList) { final String parent = file.getParent(); if (parent != null) { final FileInfo[] infos = IdeaWin32.getInstance().listChildren(parent); assertNotNull(infos); for (FileInfo info : infos) { if (file.getName().equals(info.getName())) { assertEquals(attributes,info.toFileAttributes()); return attributes; } } fail(file + " not listed"); } } return attributes; }
private static void assertDirectoriesEqual(@NotNull final File dir) { final String[] list1 = dir.list(); assertNotNull(list1); final FileInfo[] list2 = IdeaWin32.getInstance().listChildren(dir.getPath()); assertNotNull(list2); if (list1.length + 2 != list2.length) { assertEquals(Arrays.toString(list1),Arrays.toString(list2)); } }
private static void assertDirectoriesEqual(@NotNull final File dir) { final String[] list1 = dir.list(); assertNotNull(list1); final FileInfo[] list2 = IdeaWin32.getInstance().listChildren(dir.getPath()); assertNotNull(list2); if (list1.length + 2 != list2.length) { assertEquals(Arrays.toString(list1),Arrays.toString(list2)); } }
private static void assertDirectoriesEqual(@Nonnull final File dir) { final String[] list1 = dir.list(); assertNotNull(list1); final FileInfo[] list2 = IdeaWin32.getInstance().listChildren(dir.getPath()); assertNotNull(list2); if (list1.length + 2 != list2.length) { assertEquals(Arrays.toString(list1),Arrays.toString(list2)); } }
public static boolean isAvailable() { return IdeaWin32.isAvailable(); }
@Before public void setUp() { assumeTrue(SystemInfo.isWindows); myDriver = IdeaWin32.getInstance(); myIdeaTotal = myJavaTotal = 0; }
public static boolean isAvailable() { return IdeaWin32.isAvailable(); }
@Before public void setUp() throws Exception { assumeTrue(SystemInfo.isWindows); myDriver = IdeaWin32.getInstance(); myIdeaTotal = myJavaTotal = 0; }
@Before public void setUp() throws Exception { assumeTrue(SystemInfo.isWindows); myDriver = IdeaWin32.getInstance(); myIdeaTotal = myJavaTotal = 0; }
public static boolean isAvailable() { return IdeaWin32.isAvailable(); }
com.sun.jna.platform.win32.Win32Exception的实例源码
public static String[] getAvailablebrowsers() throws DebuggableException { try { String[] keys = Advapi32Util.registryGetKeys(WinReg.HKEY_LOCAL_MACHINE,WIN_REG_CLIENTS_PATH); List<String> filteredList = new ArrayList<String>(50); for (int i = 0; i < keys.length; i++) { if (!keys[i].equals(WIN_REG_INTERNET_CLIENT_KEY)) { filteredList.add(keys[i]); } } String[] out = new String[filteredList.size()]; for (int i = 0; i < out.length; i++) { out[i] = filteredList.get(i); } return out; } catch (Win32Exception e) { throw new DebuggableException(null,"(Try&catch try)","Throw debuggable exception","(End of function)","Error reading registry",false,e); } }
private void checkKeyExists( String rootKey,String keyPath,String keyName ) { try { WinReg.HKEY rootHKey = getHKey(rootKey); if (!Advapi32Util.registryValueExists(rootHKey,keyPath,keyName)) { throw new RegistryOperationsException("Registry key does not exist. " + getDescription(rootKey,keyName)); } } catch (Win32Exception e) { throw new RegistryOperationsException("Registry key path does not exist. " + getDescription(rootKey,keyName),e); } }
/** * Captures the window. * * @param hwnd The window to capture. * @param filename Name to save the output into. * @throws AWTException Robot exception. * @throws IOException IO Exception. */ public static void capture(final WinDef.HWND hwnd,final String filename) throws AWTException,IOException,Win32Exception { ensureWinApiInstances(); WinDef.RECT rect = new WinDef.RECT(); if (!user32.GetwindowRect(hwnd,rect)) { throw new Win32Exception(kernel32.GetLastError()); } Rectangle rectangle = new Rectangle(rect.left,rect.top,rect.right -rect.left,rect.bottom -rect.top); BufferedImage image = new Robot().createScreenCapture(rectangle); ImageIO.write(image,"png",new File(filename)); }
@Test(expected= Win32Exception.class) public void test_setTransparency_Throws_Exception_When_Win32_Calls_Throw_Error() throws Exception { doAnswer(invocation -> { Object[] args = invocation.getArguments(); Object reference = (Object)args[0]; reference = 1245; return 1234; }).when(element).getPropertyValue(anyInt()); iuiAutomation mocked_automation = Mockito.mock(iuiAutomation.class); UIAutomation instance = new UIAutomation(mocked_automation); AutomationWindow wndw = new AutomationWindow( new ElementBuilder(element).window(window).itemContainer(container).automation(instance)); wndw.setTransparency(100); verify(element,atLeastOnce()).getPropertyValue(anyInt()); }
/** * Authenticates the user using Windows logonUser API */ @CheckForNull public WindowsPrincipal logonUser(String userName,String password) { checkArgument(isNotEmpty(userName),"userName is null or empty."); checkArgument(isNotEmpty(password),"password is null or empty."); LOG.debug("Authenticating user: {}",userName); WindowsPrincipal windowsPrincipal = null; IWindowsIdentity windowsIdentity = null; try { windowsIdentity = windowsAuthProvider.logonUser(userName,password); if (windowsIdentity != null) { windowsPrincipal = new WindowsPrincipal(windowsIdentity); } } catch (Win32Exception win32Exception) { LOG.debug("User {} is not authenticated : {}",userName,win32Exception.getMessage()); } finally { if (windowsIdentity != null) { windowsIdentity.dispose(); } } return windowsPrincipal; }
private void runlogonUserTest(String userName,String password,boolean islogonUserSuccessful) { IWindowsIdentity windowsIdentity = null; Win32Exception win32Exception = mock(Win32Exception.class); if (islogonUserSuccessful) { windowsIdentity = mock(IWindowsIdentity.class); Mockito.when(windowsIdentity.getFqn()).thenReturn(userName); Mockito.when(windowsIdentity.getGroups()).thenReturn(new IWindowsAccount[0]); Mockito.when(windowsAuthProvider.logonUser(userName,password)).thenReturn(windowsIdentity); } else { Mockito.when(windowsAuthProvider.logonUser(userName,password)).thenThrow(win32Exception); } WindowsPrincipal windowsPrincipal = authenticationHelper.logonUser(userName,password); if (islogonUserSuccessful) { assertthat(windowsPrincipal.getName()).isEqualTo(windowsIdentity.getFqn()); Mockito.verify(windowsIdentity,Mockito.times(1)).dispose(); Mockito.verify(win32Exception,Mockito.times(0)).getMessage(); } else { assertthat(windowsPrincipal).isNull(); Mockito.verify(win32Exception,Mockito.times(1)).getMessage(); } Mockito.verify(windowsAuthProvider,Mockito.times(1)).logonUser(userName,password); }
protected void getVLCRegistryInfo() { String key = "SOFTWARE\\VideoLAN\\VLC"; try { if (!Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE,key)) { key = "SOFTWARE\\Wow6432Node\\VideoLAN\\VLC"; if (!Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE,key)) { return; } } vlcPath = Paths.get(Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE,key,"")); vlcVersion = new Version(Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE,"Version")); } catch (Win32Exception e) { LOGGER.debug("Could not get VLC information from Windows registry: {}",e.getMessage()); LOGGER.trace("",e); } }
protected String getavisynthPluginsFolder() { String key = "SOFTWARE\\avisynth"; try { if (!Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE,key)) { key = "SOFTWARE\\Wow6432Node\\avisynth"; if (!Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE,key)) { return null; } } return Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE,"plugindir2_5"); } catch (Win32Exception e) { LOGGER.debug("Could not get avisynth information from Windows registry: {}",e); } return null; }
protected String getKLiteFiltersFolder() { String key = "SOFTWARE\\Wow6432Node\\KLCodecPack"; try { if (!Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE,key)) { key = "SOFTWARE\\KLCodecPack"; if (!Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE,"installdir"); } catch (Win32Exception e) { LOGGER.debug("Could not get K-Lite Codec Pack information from Windows registry: {}",e); } return null; }
/** * Retrieves the id of the process that belongs to the given exe-file name. * * @param szExeFile * Name of the exe-File. * @return The id of the process that belongs to the given exe-file name or * <tt>0</tt> (zero) if not found. */ public static int getProcessIdBySzExeFile(final String szExeFile) { try { final Iterator<Process> processes = Kernel32Util.getProcessList().iterator(); while (processes.hasNext()) { final Process process = processes.next(); if (process.getSzExeFile().equalsIgnoreCase(szExeFile)) { return process.getPid(); } } } catch (final Win32Exception e) { // Just catch the exception and return an error code } return 0; }
public static String getbrowserValue() { if (SETTINGS.getProperty(KEY_broWSER) == null || SETTINGS.getProperty(KEY_broWSER).isEmpty()) { try { String value = Advapi32Util.registryGetStringValue(APP_ROOT_HKEY,REGISTRY_APP_PATH,KEY_broWSER); return value; } catch (Win32Exception e) { return ApplicationConstants.broWSER_DEFAULT_VALUE; } } else { if (!SETTINGS.getProperty(KEY_broWSER).equals(ApplicationConstants.broWSER_DEFAULT_VALUE)) { return SETTINGS.getProperty(KEY_broWSER); } else { return ApplicationConstants.broWSER_DEFAULT_VALUE; } } }
public static String getInstallLocationValue() throws RegistryCanNotReadInfoException { if (SETTINGS.getProperty(KEY_INSTALL_LOCATION) == null || SETTINGS.getProperty(KEY_INSTALL_LOCATION).isEmpty()) { try { String value = Advapi32Util.registryGetStringValue(APP_ROOT_HKEY,KEY_INSTALL_LOCATION); if (!value.endsWith(File.separator)) { value = value + File.separator; } SETTINGS.setProperty(KEY_INSTALL_LOCATION,value); return value; } catch (Win32Exception e) { throw new RegistryCanNotReadInfoException("Can not read Installed Location value : " + "HKCU\\" + REGISTRY_APP_PATH + "" + KEY_INSTALL_LOCATION,e); } } else return SETTINGS.getProperty(KEY_INSTALL_LOCATION); }
@SuppressWarnings("UnusedReturnValue") public static String getAppNameValue() throws RegistryCanNotReadInfoException { if (SETTINGS.getProperty(KEY_APP_NAME) == null || SETTINGS.getProperty(KEY_APP_NAME).isEmpty()) { try { String value = Advapi32Util.registryGetStringValue(APP_ROOT_HKEY,KEY_APP_NAME); SETTINGS.setProperty(KEY_APP_NAME,value); return value; } catch (Win32Exception e) { throw new RegistryCanNotReadInfoException("Can not read Installed Location value : " + "HKLM\\" + REGISTRY_APP_PATH + "" + KEY_APP_NAME,e); } } else return SETTINGS.getProperty(KEY_APP_NAME); }
@SuppressWarnings("UnusedReturnValue") public static String getURLUpdateValue() throws RegistryCanNotReadInfoException { if (SETTINGS.getProperty(KEY_URL_UPDATE_LINK) == null || SETTINGS.getProperty(KEY_URL_UPDATE_LINK).isEmpty()) { try { String value = Advapi32Util.registryGetStringValue(APP_ROOT_HKEY,KEY_URL_UPDATE_LINK); SETTINGS.setProperty(KEY_URL_UPDATE_LINK,value); return value; } catch (Win32Exception e) { throw new RegistryCanNotReadInfoException( "Can not read Installed Location value : " + "HKLM\\" + REGISTRY_APP_PATH + "" + KEY_URL_UPDATE_LINK,e); } } else return SETTINGS.getProperty(KEY_URL_UPDATE_LINK); }
/** * Check if registry keys exist and if the cmd file the key contains matches the latest cmd file * * @param newCmd * @return if keys exists or not */ protected static boolean doesKeyNeedUpdated(final File newCmd) throws IOException { try { final String existingKey = Advapi32Util.registryGetStringValue(WinReg.HKEY_CURRENT_USER,VSOI_KEY,StringUtils.EMPTY); final File existingCmd = new File(existingKey.replace("\"%1\"","").trim()); if (!existingCmd.exists()) { logger.debug("The registry key needs updated because the old key cmd file doesn't exist."); return true; } if (existingCmd.getPath().equalsIgnoreCase(newCmd.getPath()) || FileUtils.contentEquals(existingCmd,newCmd)) { logger.debug("The registry key does not need updated because {}",existingCmd.getPath().equalsIgnoreCase(newCmd.getPath()) ? "the file paths are the same" : "the contents of the files are the same."); return false; } // use the newest cmd file so update if existing cmd file is older // Todo: version cmd file if we continually iterate on it so we chose the correct file more reliably logger.debug("The existing cmd file is {} old and the the cmd file is {} old",existingCmd.lastModified(),newCmd.lastModified()); return existingCmd.lastModified() < newCmd.lastModified() ? true : false; } catch (Win32Exception e) { // Error occurred reading the registry (possible key doesn't exist or is empty) so update just to be safe logger.debug("There was an issue reading the registry so updating the key to be safe."); return true; } }
/** * Fetches the full backup path from the registry. * * @return Filepath from registry to full backup path. If none exists,this * returns null. */ public static String GetFullBackupPath(boolean returnEvenIfInvalid) { String backupPath = null; try { backupPath = Advapi32Util.registryGetStringValue(HKEY_CURRENT_USER,VanillaUserRegistryKey,VanillaUserRegistryValue); File backupDir = new File(backupPath); if (verifyVanillaBackup(backupDir)) { ModManager.debugLogger.writeMessage("Found valid vanilla copy location in registry: " + backupPath); } else { ModManager.debugLogger.writeError("Found vanilla copy location in registry,but it doesn't seem to be valid,at least one of the validation checks Failed"); } } catch (Win32Exception e) { ModManager.debugLogger.writeErrorWithException("Win32Exception reading registry - assuming no backup exists yet (this is not really an error... mostly).",e); } if (backupPath != null) { if (new File(backupPath).exists() && new File(backupPath).isDirectory()) { return backupPath; } else if (returnEvenIfInvalid) { ModManager.debugLogger.writeError("returnEvenIfInvalid - returning path anyways."); return backupPath; } } return null; }
/** * Returns the osu! installation directory. * @return the directory,or null if not found */ private static File getosuInstallationDirectory() { if (!System.getProperty("os.name").startsWith("Win")) return null; // only works on Windows // registry location final WinReg.HKEY rootKey = WinReg.HKEY_CLASSES_ROOT; final String regKey = "osu\\DefaultIcon"; final String regValue = null; // default value final String regPathPattern = "\"(.+)\\\\[^\\/]+\\.exe\""; String value; try { value = Advapi32Util.registryGetStringValue(rootKey,regKey,regValue); } catch (Win32Exception e) { return null; // key/value not found } Pattern pattern = Pattern.compile(regPathPattern); Matcher m = pattern.matcher(value); if (!m.find()) return null; File dir = new File(m.group(1)); return (dir.isDirectory()) ? dir : null; }
public static boolean isAddedToContextMenu() { if (!Platform.isWindows()) { return false; } final WinReg.HKEY REG_CLASSES_HKEY = WinReg.HKEY_LOCAL_MACHINE; final String REG_CLASSES_PATH = "Software\\Classes\\"; try { if (!Advapi32Util.registryKeyExists(REG_CLASSES_HKEY,REG_CLASSES_PATH + ".swf")) { return false; } String clsName = Advapi32Util.registryGetStringValue(REG_CLASSES_HKEY,REG_CLASSES_PATH + ".swf",""); if (clsName == null) { return false; } return Advapi32Util.registryKeyExists(REG_CLASSES_HKEY,REG_CLASSES_PATH + clsName + "\\shell\\ffdec"); } catch (Win32Exception ex) { return false; } }
public static String getbrowserExePath(String browserName) { String value = null; try { value = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE,WIN_REG_CLIENTS_PATH + "\\" + browserName + "\\shell\\open\\command",""); } catch (Win32Exception e) { return null; } return value; }
/** * Sets transparency of the window. * @param alpha 0..255 alpha attribute. * @throws Win32Exception WIN32 call has Failed. * @throws AutomationException Something is wrong in automation. */ public void setTransparency(int alpha) throws Win32Exception,AutomationException { WinDef.HWND hwnd = this.getNativeWindowHandle(); if (user32.SetwindowLong(hwnd,User32.GWL_EXSTYLE,User32.WS_EX_layered) == 0) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } if (!user32.SetlayeredWindowAttributes(hwnd,(byte)alpha,User32.LWA_ALPHA)) { throw new Win32Exception(Kernel32.INSTANCE.GetLastError()); } }
private File loadOsuInstallationDirectory() { if (!System.getProperty("os.name").startsWith("Win")) { return null; } final WinReg.HKEY rootKey = WinReg.HKEY_CLASSES_ROOT; final String regKey = "osu\\DefaultIcon"; final String regValue = null; // default value final String regPathPattern = "\"(.+)\\\\[^\\/]+\\.exe\""; String value; try { value = Advapi32Util.registryGetStringValue(rootKey,regValue); } catch (Win32Exception ignored) { return null; } Pattern pattern = Pattern.compile(regPathPattern); Matcher m = pattern.matcher(value); if (!m.find()) { return null; } File dir = new File(m.group(1)); if (dir.isDirectory()) { return dir; } return null; }
@CheckForNull private IWindowsAccount getwindowsAccount(String userName) { IWindowsAccount windowsAccount = null; try { windowsAccount = windowsAuthProvider.lookupAccount(userName); } catch (Win32Exception win32Exception) { LOG.debug("User {} is not found: {}",win32Exception.getMessage()); } return windowsAccount; }
@Test public void getUserDetailsFromUserNameWindowsAccountNulltest() { String userName = "User"; String domainName = "Domain"; String userNameWithDomain = getAccountNameWithDomain(domainName,"\\",userName); Win32Exception win32Exception = mock(Win32Exception.class); IWindowsAccount windowsAccount = getIWindowsAccount(domainName,userName); assertthat(authenticationHelper.getUserDetails(userNameWithDomain)).isNull(); Mockito.when(windowsAuthProvider.lookupAccount(userNameWithDomain)).thenThrow(win32Exception); assertthat(authenticationHelper.getUserDetails(userNameWithDomain)).isNull(); Mockito.verify(win32Exception,Mockito.times(1)).getMessage(); }
protected boolean isKerioInstalled() { try { String key = "SOFTWARE\\Kerio"; if (!Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE,key)) { key = "SOFTWARE\\Wow6432Node\\Kerio"; return Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE,key); } return true; } catch (Win32Exception e) { LOGGER.debug("Could not get Kerio information from Windows registry: {}",e); return false; } }
@Override public MemoryBuffer read(Pointer address,int size,MemoryBuffer buffer) { if (Kernel32.ReadProcessMemory(pointer(),address,buffer,size,0) == 0) { throw new Win32Exception(Native.getLastError()); } return buffer; }
@Override public Process write(Pointer address,MemoryBuffer buffer) { if (Kernel32.WriteProcessMemory(pointer(),buffer.size(),0) == 0) { throw new Win32Exception(Native.getLastError()); } return this; }
/** * Gets a list of currently active processes by creating a snapshot. * * @return List of currently active processes * @throws Win32Exception * If the operation was not successful */ public static ProcessList getProcessList() throws Win32Exception { final ProcessList plist = new ProcessList(); final List<PROCESSENTRY32> list = new LinkedList<>(); final HANDLE hProcessSnap = Kernel32.INSTANCE.Createtoolhelp32Snapshot(Tlhelp32.TH32CS_SNAPPROCESS,new DWORD(0)); PROCESSENTRY32 pe32 = new PROCESSENTRY32(); if (!Kernel32.INSTANCE.Process32First(hProcessSnap,pe32)) { throw new Win32Exception(Native.getLastError()); } do { if (pe32.th32ProcessID.intValue() != 0) { list.add(pe32); } pe32 = new PROCESSENTRY32(); } while (Kernel32.INSTANCE.Process32Next(hProcessSnap,pe32)); for (final PROCESSENTRY32 pe : list) { plist.add(new Process(pe)); } Kernel32.INSTANCE.CloseHandle(hProcessSnap); final List<DesktopWindow> windows = WindowUtils.getAllWindows(false); final IntByReference lpdwProcessId = new IntByReference(); int pid = 0; for (final DesktopWindow window : windows) { User32.INSTANCE.GetwindowThreadProcessId(window.getHWND(),lpdwProcessId); pid = lpdwProcessId.getValue(); plist.add(pid,window.getHWND()); } return plist; }
/** * Whether the given process is a 64-bit application or not. A 32-bit * application that runs in the WoW64 environment is not considered as * 64-bit application,since they are restricted to the 32-bit memory space. * * @param hProcess * Handle to the process in question * @return <tt>True</tt> if the given process is a 64-bit application,* <tt>false</tt> otherwise. * @throws Win32Exception * If the operation was not successful */ public static boolean is64Bit(final HANDLE hProcess) throws Win32Exception { if (System.getenv(SystemProperties.PRC_ARCH) == Masks.PRC_ARCH_32BIT) { return false; } final IntByReference isWow64 = new IntByReference(); final boolean success = Kernel32.INSTANCE.IsWow64Process(hProcess,isWow64); if (!success) { throw new Win32Exception(Native.getLastError()); } return isWow64.getValue() == 0; }
public static String getAppVersionValue() throws RegistryCanNotReadInfoException { if (SETTINGS.getProperty(KEY_CURRENT_VERSION) == null || SETTINGS.getProperty(KEY_CURRENT_VERSION).isEmpty()) { try { String result = Advapi32Util.registryGetStringValue(APP_ROOT_HKEY,KEY_CURRENT_VERSION); SETTINGS.setProperty(KEY_CURRENT_VERSION,result); return result; } catch (Win32Exception e) { throw new RegistryCanNotReadInfoException("Can not get app version value",e); } } else return SETTINGS.getProperty(KEY_CURRENT_VERSION); }
public static boolean isAutoUpdateActive() throws RegistryCanNotReadInfoException { if (SETTINGS.getProperty(KEY_AUTO_UPDATE) == null || SETTINGS.getProperty(KEY_AUTO_UPDATE).isEmpty()) { try { String value = Advapi32Util.registryGetStringValue(APP_ROOT_HKEY,KEY_AUTO_UPDATE); boolean result = Boolean.parseBoolean(value); //prevents SETTINGS.setProperty(KEY_AUTO_UPDATE,Boolean.toString(result)); return result; } catch (Win32Exception e) { throw new RegistryCanNotReadInfoException("Can not read " + RegistryManager.KEY_AUTO_UPDATE + " value",e); } } else return Boolean.parseBoolean(SETTINGS.getProperty(KEY_AUTO_UPDATE)); }
public static void createRegistryEntry(String path,String valueName,String value) throws RegistryCanNotWriteInfoException { try { SETTINGS.setProperty(valueName,value); Advapi32Util.registrySetStringValue(APP_ROOT_HKEY,path,valueName,value); } catch (Win32Exception e) { throw new RegistryCanNotWriteInfoException("Can not create entry at: " + APP_ROOT_HKEY + "\\" + path + valueName + " With value [" + value + "]",e); } }
public static void createRootRegistryFolder(String path) throws RegistryCanNotWriteInfoException { if (!Advapi32Util.registryKeyExists(APP_ROOT_HKEY,path)) { try { Advapi32Util.registryCreateKey(APP_ROOT_HKEY,path); } catch (Win32Exception e) { throw new RegistryCanNotWriteInfoException("Can not create root folder on registry.",e); } } }
String getToken( final CtxtHandle continueCtx,final SecBufferDesc continuetoken,final String targetName) { final IntByReference attr = new IntByReference(); final SecBufferDesc token = new SecBufferDesc( sspi.SECBUFFER_TOKEN,sspi.MAX_TOKEN_SIZE); sspiContext = new CtxtHandle(); final int rc = Secur32.INSTANCE.InitializeSecurityContext(clientCred,continueCtx,targetName,sspi.ISC_REQ_DELEGATE | sspi.ISC_REQ_MUTUAL_AUTH,sspi.Security_NATIVE_DREP,continuetoken,sspiContext,token,attr,null); switch (rc) { case WinError.SEC_I_CONTINUE_NEEDED: continueNeeded = true; break; case WinError.SEC_E_OK: dispose(); // Don't keep the context continueNeeded = false; break; default: dispose(); throw new Win32Exception(rc); } return Base64.encodeBase64String(token.getBytes()); }
@Override String getToken(final CtxtHandle continueCtx,final String targetName) { dispose(); /* We will rather throw SEC_E_TARGET_UNKNowN because SEC_E_DOWNGRADE_DETECTED is not * available on Windows XP and this unit test always fails. */ throw new Win32Exception(WinError.SEC_E_TARGET_UNKNowN); }
@Override public int getBrightness() throws Win32Exception { DWORDByReference minBrightness = new DWORDByReference(); DWORDByReference curBrightness = new DWORDByReference(); DWORDByReference maxBrightness = new DWORDByReference(); check(Dxva2.INSTANCE.GetMonitorBrightness(handle,minBrightness,curBrightness,maxBrightness)); // return curBright; return curBrightness.getValue().intValue(); }
private void check(BOOL retVal) { if (!retVal.booleanValue()) { int err = Kernel32.INSTANCE.GetLastError(); if (err != 0) throw new Win32Exception(err); } }
private CredHandle acquireCredentialsHandle() { CredHandle handle = new CredHandle(); int rc = Secur32.INSTANCE.AcquireCredentialsHandle(null,"NTLM",SECPKG_CRED_OUTBOUND,null,handle,new TimeStamp()); if (SEC_E_OK != rc) { throw new Win32Exception(rc); } return handle; }
@Test(expected = Win32Exception.class) public void test_setTransparency_Throws_Exception_When_SetwindowLong_Returns_Error() throws Exception { doAnswer(invocation -> 0).when(user32).SetwindowLong(any(),anyInt(),anyInt()); doAnswer(invocation -> true).when(user32).SetlayeredWindowAttributes(any(),anyByte(),anyInt()); doAnswer(invocation -> { Object[] args = invocation.getArguments(); Object reference = (Object)args[0]; reference = 1245; return 1234; }).when(element).getPropertyValue(anyInt()); AutomationWindow wndw = new AutomationWindow( new ElementBuilder(element).window(window).itemContainer(container).user32(user32)); wndw.setTransparency(100); verify(element,atLeastOnce()).getPropertyValue(anyInt()); }
今天关于Git 扩展:Win32 错误 487:无法为 cygwin 的堆预留空间,Win32 错误 0和无法为tom clancy执行启动程序的分享就到这里,希望大家有所收获,若想了解更多关于Cocos 在win32 平台上显示中文(仅实现win32)、Cocos2d-x项目移植(Win32至IOS,Win32至Android)、com.intellij.openapi.util.io.win32.IdeaWin32的实例源码、com.sun.jna.platform.win32.Win32Exception的实例源码等相关知识,可以在本站进行查询。
本文标签: