Comparar commits
803 Commits
| Autor | SHA1 | Data | |
|---|---|---|---|
| 4268e3a1d2 | |||
| 860b9a266a | |||
| c39d752ccb | |||
| 15db1cf385 | |||
| 38d684d1e6 | |||
| ccb1bc514b | |||
| 27c46a2c8e | |||
| ff2f1d237a | |||
| 402f4c162c | |||
| 81013a98b4 | |||
| 971dd622c7 | |||
| 0045d31e2d | |||
| caef8f4ebc | |||
| 6116c1ae71 | |||
| 03ecf2b0bb | |||
| d4a5005273 | |||
| 7522f29f0a | |||
| 09f0a2e4a6 | |||
| aa846929f3 | |||
| b378af7cb1 | |||
| 8b549a487f | |||
| 005f659eaa | |||
| a5aad94f24 | |||
| 52a6926da3 | |||
| b3c0f003bb | |||
| 3d2360bc56 | |||
| 1267f51d8c | |||
| e7328001a4 | |||
| fc7b53e809 | |||
| 50637cb3c2 | |||
| 11b4203874 | |||
| 60beb432eb | |||
| 64331c9cf0 | |||
| 00088d4093 | |||
| 472f3660e0 | |||
| 3c13cc8c4d | |||
| 0792ac8eee | |||
| 4952af4ffe | |||
| 3fcca7ef56 | |||
| e93244fef2 | |||
| acf75ce7fe | |||
| 7560b6e53d | |||
| f5346bbec2 | |||
| 41958889fb | |||
| d439a7811d | |||
| 4951c00d23 | |||
| 202cd0d45e | |||
| 1502db6095 | |||
| e8eea9e68e | |||
| 396eb9f283 | |||
| 378f400226 | |||
| 37e02dfbd5 | |||
| dce66ec8ec | |||
| 2fef67a08d | |||
| 50a17583c7 | |||
| bfe2c7df83 | |||
| b3186dde12 | |||
| 628a33eb76 | |||
| 4373e66b1e | |||
| 2e67b0ad9f | |||
| a4cbe0635f | |||
| 8563419280 | |||
| 0974bd4a90 | |||
| e1d47adc99 | |||
| e5e171d913 | |||
| 1e313227b8 | |||
| 8d45a9e0cd | |||
| 95568d76d3 | |||
| d4a3442468 | |||
| e262de22ea | |||
| 49243f1891 | |||
| 1a099ba549 | |||
| 2367133b4f | |||
| c648a1933d | |||
| 598acf08da | |||
| 208a8dee90 | |||
| e9fb299565 | |||
| 17a514ecd0 | |||
| 38ac62cedd | |||
| ce280731af | |||
| 751fb57f71 | |||
| be7d90abbf | |||
| d59585dd4f | |||
| 7a695707a2 | |||
| 4e590c9450 | |||
| b069d1c9e9 | |||
| 9fa1f7b981 | |||
| 4a68e4cd9d | |||
| 8320b6fd7c | |||
| e40cf0a1c4 | |||
| 19106985d7 | |||
| 3d817c54da | |||
| ca31877107 | |||
| f5f9afefb0 | |||
| d42863603e | |||
| 2c19cf3e31 | |||
| e7dc918c6a | |||
| 64c9e8212a | |||
| 499c39f13d | |||
| bccdae735b | |||
| 58120730a5 | |||
| 5b8db8a680 | |||
| 0acfd583c8 | |||
| 402b7ef67e | |||
| 6944871c42 | |||
| b60da35689 | |||
| 5204feddb1 | |||
| 68156df66b | |||
| a9e8b27285 | |||
| b8f470ddbd | |||
| 9d075dd1d1 | |||
| 4b802c6f60 | |||
| 8ce9344dd0 | |||
| cb2b386791 | |||
| 7ee4681c10 | |||
| 82c0ea9df2 | |||
| 9070d80880 | |||
| 45c53caf94 | |||
| c4947618c1 | |||
| 941ed59c37 | |||
| d76bbec1ab | |||
| f5a1d98cf9 | |||
| b0e6d837f0 | |||
| b1cfb1b733 | |||
| 26a1212546 | |||
| 03b05aaae9 | |||
| f41c87d7c9 | |||
| b74deb5e35 | |||
| 240e2db637 | |||
| 441947b6a4 | |||
| 194bdaffcd | |||
| db6e9ff4c6 | |||
| 57261a1164 | |||
| 0b116bb409 | |||
| a5ad2e5de2 | |||
| b6928ff6c0 | |||
| 4b03dd321c | |||
| f7eefbd3d7 | |||
| b23f7f9b27 | |||
| b95bc7e4c4 | |||
| 1593c0c347 | |||
| c154663455 | |||
| 13bc1901dc | |||
| 4f28322ac2 | |||
| 756e2ced8b | |||
| 1dc78b5209 | |||
| 3464093273 | |||
| 4487214494 | |||
| 6d7e222946 | |||
| d12a6a3178 | |||
| ed9d609c35 | |||
| b86f359d93 | |||
| 02080dfcf8 | |||
| 2768d25884 | |||
| 7bdf9896d2 | |||
| 3b4f84ded8 | |||
| 69abc52731 | |||
| 1671b1fb8b | |||
| 8735f4ef5c | |||
| 86967b5786 | |||
| ca8ceeb130 | |||
| 41d6f8eeea | |||
| 27b7805608 | |||
| fef39f7013 | |||
| b414b54c6b | |||
| ccdbb20ad0 | |||
| eb7e47bf29 | |||
| 53988c7184 | |||
| 9092b2bdc5 | |||
| 068353aa5b | |||
| 95a17ddbf0 | |||
| 6c8c455f5b | |||
| 282032e178 | |||
| af63e6a80d | |||
| a46ba0da29 | |||
| f7738bf65b | |||
| bb11d1fe37 | |||
| d02a2deb52 | |||
| 46105d849d | |||
| f16b6c3482 | |||
| a9cb497045 | |||
| d529a34ecb | |||
| 5394029dc5 | |||
| 28247737ca | |||
| 6448c2d8fb | |||
| 4460ccc8ec | |||
| 2b02a3c533 | |||
| 6705513b86 | |||
| 4bd8d12481 | |||
| ccaf3c283b | |||
| ce4276a0cb | |||
| 709e316e56 | |||
| e46635d6ab | |||
| 0af8677ba4 | |||
| 9ab13daf09 | |||
| 17977fbabc | |||
| 83854047b7 | |||
| 28e56fd587 | |||
| 29fc6308b8 | |||
| 14a7df128d | |||
| dd4ef89d0a | |||
| 830ec91cbf | |||
| aee2d55fab | |||
| 89ed7982e7 | |||
| 9f702c89ab | |||
| 2f76efd0f6 | |||
| fae18c72c3 | |||
| 1586f6ee2b | |||
| 4ce6214526 | |||
| e370e4b65e | |||
| 944de2d3f5 | |||
| f32146368d | |||
| 8d45e9b016 | |||
| 70227861ff | |||
| 20e542516b | |||
| 73ad21df73 | |||
| a67fe7e43d | |||
| a15ddd9f88 | |||
| b27f9bf930 | |||
| d5c28f98f1 | |||
| 16b283ed00 | |||
| 97b43889a1 | |||
| 05efa12411 | |||
| 3e60495232 | |||
| 45522b0710 | |||
| d67d25eb7b | |||
| 2538690fb4 | |||
| 4c23b2518e | |||
| 9daade9816 | |||
| 5f925f0070 | |||
| 38b0cd7780 | |||
| e46391042b | |||
| 553a03b05f | |||
| 24c1cc4efe | |||
| f6eabe7b58 | |||
| de2de1fdc7 | |||
| 8184ac8843 | |||
| a57d82d4cd | |||
| a266ef7337 | |||
| b30ca23180 | |||
| db5c8f00fc | |||
| d1bbacb06e | |||
| bff4e3b0fd | |||
| 14248ddbd9 | |||
| 391f39d291 | |||
| b4354efa8b | |||
| 686588a6e5 | |||
| 294267a605 | |||
| 7b53b9108b | |||
| 15be9ab501 | |||
| 7cfcd2daef | |||
| 6070429eec | |||
| b5f41ef6c7 | |||
| 716588a8fb | |||
| 95bc92f005 | |||
| 23425abe9d | |||
| 3bab5e1e78 | |||
| 79ed7e81b1 | |||
| a59e58cc94 | |||
| 72bd12e394 | |||
| 2c667ca016 | |||
| 209c4d724f | |||
| 95cf641f50 | |||
| 85750fd065 | |||
| 402b5c7f81 | |||
| be6f52b796 | |||
| f4e6c6ad94 | |||
| 99fe59cee9 | |||
| 0e80ba8b91 | |||
| 8965efdce1 | |||
| 1393a94804 | |||
| 52e558d877 | |||
| d9948105f1 | |||
| 87c91c1c04 | |||
| f15e471371 | |||
| fc0a83933d | |||
| f1cf2fe218 | |||
| 7a5679cb65 | |||
| 571b4604db | |||
| 29e15a40db | |||
| 6fb2286fa4 | |||
| ab2f78c7b4 | |||
| f9b918a05b | |||
| a46cde174a | |||
| 6eee0f8741 | |||
| 28d31bb9f6 | |||
| 23128be17f | |||
| 130885fda7 | |||
| c4fc42f8f4 | |||
| 21e73c5fb9 | |||
| b635bf5591 | |||
| be594bb1f6 | |||
| 543e3fca98 | |||
| b385d76dc6 | |||
| 2adc88fec3 | |||
| 2a9e2ceb61 | |||
| 47fa804469 | |||
| f70c01eee7 | |||
| eb4ea07a2d | |||
| 55cd72baaa | |||
| 940076d101 | |||
| 93ebb9f7a9 | |||
| 1a17ea52d8 | |||
| 68bc0c0c7c | |||
| 0e7dd6b350 | |||
| b3b0bf3845 | |||
| ddc32f1e43 | |||
| c9de508a2c | |||
| fac68bca4e | |||
| eaf250c3c6 | |||
| 8b99772d29 | |||
| 862a32e97e | |||
| 6cfb84d6ee | |||
| 2fda7ca6f6 | |||
| f2aecb53bc | |||
| 05fdc2f17a | |||
| b9868b993c | |||
| 573d8eefd1 | |||
| 51d64f29e6 | |||
| a39ab60ae5 | |||
| ba9671fae5 | |||
| a9340f354d | |||
| f9d6b069f7 | |||
| c363d5790d | |||
| 15a50d2a26 | |||
| bffc188151 | |||
| e78205430c | |||
| 4ef76d4f85 | |||
| 967da46793 | |||
| 46899503bd | |||
| 2dcf0f774c | |||
| d669db0cab | |||
| f8aabcc50a | |||
| 4bb3ece8dc | |||
| 495a7765d2 | |||
| 225296f253 | |||
| 52e6900e7a | |||
| 557bff1465 | |||
| add32ac107 | |||
| f7699b98fb | |||
| 05a8ec1fec | |||
| 004e63c433 | |||
| 898f41b95a | |||
| 859a6a75aa | |||
| b90dae6448 | |||
| dc1ddf4cff | |||
| 46ef5d86c3 | |||
| ac63a6b125 | |||
| 72778c97df | |||
| b4b86081f9 | |||
| e4a47a4ca5 | |||
| 79c60f6d4e | |||
| 4c4d55e0dc | |||
| 9504416beb | |||
| 99586d9b3f | |||
| 65b19cbbd3 | |||
| 7b64f4443d | |||
| abb2e857be | |||
| df10745963 | |||
| 3d729595d1 | |||
| 96a38d1895 | |||
| b4c1390af8 | |||
| e9604ac212 | |||
| ea3a4b34ea | |||
| 79a0d92161 | |||
| b10c40260c | |||
| 9e056d2097 | |||
| 8a250c5994 | |||
| e311ac3269 | |||
| 28078a2d0c | |||
| 7def8c1bbf | |||
| 24ca11387e | |||
| bccc9583c1 | |||
| 9643747b17 | |||
| c695848092 | |||
| 5011613e4c | |||
| 6cc7f69a59 | |||
| db6678637b | |||
| 93892e12a2 | |||
| c196aab89d | |||
| 54a7718b88 | |||
| cec6e6175a | |||
| bc5036bd34 | |||
| 021826eb1b | |||
| facd071967 | |||
| 486e81ad77 | |||
| 872cd3d7c0 | |||
| ca9851b311 | |||
| 2fa0940d45 | |||
| 3485338386 | |||
| 786a821f3f | |||
| da1c9c5ea5 | |||
| 93d8cce7ac | |||
| 5086ba2a3b | |||
| 4cf8611dcd | |||
| 101e9d705a | |||
| 7d8bfa1b62 | |||
| 5dcf9e2f41 | |||
| cdf18b6c4d | |||
| 609ce3b6e0 | |||
| 3ba8be2e21 | |||
| 6b13a97ce4 | |||
| 130e40957e | |||
| a7b28317d7 | |||
| 29fcd0fdcf | |||
| 9d5f63e543 | |||
| 208c28ead2 | |||
| 447d5ee94b | |||
| bb443add17 | |||
| cb954773ed | |||
| 89749c7eb1 | |||
| 30146f8744 | |||
| a623f374b1 | |||
| b41584feb3 | |||
| 77d5bbb767 | |||
| 171d428d3a | |||
| 61254c6cc4 | |||
| 44b3a8952e | |||
| 0fc8c5e7e9 | |||
| 6d969eb92f | |||
| 26ea0f81ca | |||
| dc45e38f11 | |||
| 9d5db40d3f | |||
| 9e25d52679 | |||
| 1f98d4f6ff | |||
| b73883ce1d | |||
| 7af42da5d2 | |||
| cf75057b67 | |||
| e5b1841030 | |||
| 57325a22a5 | |||
| c640166cf8 | |||
| 4b4c362c03 | |||
| c71bfb1602 | |||
| 022e6349c1 | |||
| 917671ac9a | |||
| a108975d78 | |||
| 62d31c5902 | |||
| 5d28314ee3 | |||
| 1b22109f95 | |||
| e5c05bfd66 | |||
| 62e97858d7 | |||
| b9da9b977e | |||
| f121b6c039 | |||
| c48b13bc0a | |||
| 26abb9beb9 | |||
| 02cc7d53b7 | |||
| 67136b5986 | |||
| 58d5175fde | |||
| c511c4063e | |||
| 6429611b3c | |||
| 3cea53ddca | |||
| d661e58fc3 | |||
| e140b6e4e2 | |||
| e1025d9337 | |||
| f1acc483c3 | |||
| 0e25e979a2 | |||
| 0c129ff02e | |||
| 05234082a9 | |||
| bdc44962a1 | |||
| e96a59965e | |||
| 507f3fc74b | |||
| 22d997fcd9 | |||
| 89a98ca51b | |||
| 9834abe3ab | |||
| 54ffc2c138 | |||
| 4785c4f11e | |||
| 9d5b0deb61 | |||
| 9c0b540ddc | |||
| c124a9f2b8 | |||
| 8b0e08f9df | |||
| 9ee115d1a0 | |||
| a7ebf431a8 | |||
| d85330d54a | |||
| f8f93c7351 | |||
| ee1fd4944f | |||
| 5117fa06b8 | |||
| 2ac1552bf7 | |||
| 94c2647d25 | |||
| 6b2f067435 | |||
| 3e2471d0a0 | |||
| f0b1d33398 | |||
| bae955f7c5 | |||
| b747e71583 | |||
| 48160da4b7 | |||
| d17df6a9db | |||
| df7a9ec977 | |||
| f2157420f2 | |||
| ae9c56416f | |||
| 1dec6a541a | |||
| c75157ffd8 | |||
| fa77d03fea | |||
| 618f4c533c | |||
| 9b77631dd5 | |||
| 7aa22df1e2 | |||
| ee0ff79820 | |||
| ca772e8a9c | |||
| 8af05c14be | |||
| 20f230e910 | |||
| 8af51875b6 | |||
| a4ead757f6 | |||
| 0cc6bc9e2e | |||
| 00a551d2b1 | |||
| b6f1652aab | |||
| b304555389 | |||
| 456af457bb | |||
| e9cb67844d | |||
| ff12099078 | |||
| 4068c6da1a | |||
| 2f839a41c0 | |||
| d9c13aefe3 | |||
| 7bfa1c27bf | |||
| f6986352ee | |||
| 2eb51bbb13 | |||
| 77ef1e75c8 | |||
| ae11a9d77c | |||
| 30648be2ed | |||
| e5958a2a15 | |||
| 8d3b41ea4d | |||
| 2d7f82af75 | |||
| 9c93a94834 | |||
| 13a9861d18 | |||
| f7d1a91aad | |||
| 121b8e0a64 | |||
| 36ebf4a034 | |||
| 0a752616b7 | |||
| edd21a959b | |||
| dfe9779401 | |||
| d64bc68562 | |||
| f29a57ceb2 | |||
| 529c8e36f2 | |||
| 108abcdec4 | |||
| 1ae7d8373f | |||
| 8eb4860ec6 | |||
| 7ae188c42b | |||
| 125a65ee8a | |||
| 98c3353a07 | |||
| 683ba59fae | |||
| 38abd739d3 | |||
| df58c84b5a | |||
| 513bb215db | |||
| 77be329ed0 | |||
| 1f223fbe13 | |||
| c6a21ab661 | |||
| 6d59f0bd3f | |||
| 74972e267a | |||
| 6c2134ba0e | |||
| 7bf53b0588 | |||
| eaff635df5 | |||
| 88ad275b44 | |||
| fe6143ca49 | |||
| 724432aa02 | |||
| 9686a4b1bd | |||
| 7f8fab8ec0 | |||
| 5a985a143b | |||
| f9154f8c2e | |||
| 287879a7f5 | |||
| 3c82302545 | |||
| b331783c01 | |||
| 1882210db4 | |||
| 12bd185a9b | |||
| 3dbaa7984f | |||
| 40f00b1dcb | |||
| 98bb38cb03 | |||
| e1b4c8d616 | |||
| 5d7c015348 | |||
| a90e7c82b3 | |||
| 6c0c9e7d7c | |||
| 461b35f6ef | |||
| 81ca040918 | |||
| 5dc6bfb195 | |||
| b0d3657e56 | |||
| 822913c85f | |||
| ce0ac250e1 | |||
| 22e98986e5 | |||
| 3f7fc39362 | |||
| 024c845d06 | |||
| 4bb1e29cf3 | |||
| fa7bdc4fcd | |||
| ab0708340c | |||
| 34723a2e17 | |||
| d4c4d2bb13 | |||
| 80090df8e4 | |||
| 05dc68db7b | |||
| 1bcde2cbf2 | |||
| 9a5f5851ba | |||
| 8c7152bb9f | |||
| 5580e39447 | |||
| f29d58c0f0 | |||
| d69e62363e | |||
| 0e0af9dcaa | |||
| 85fee142b3 | |||
| a1b5a934f4 | |||
| 996b533634 | |||
| 11fab2e58e | |||
| 437df3b6d4 | |||
| 663c2fdbac | |||
| 4eb0e9f8aa | |||
| 00a17b60f8 | |||
| fb5f00db61 | |||
| 0105055c3e | |||
| efe147b731 | |||
| 9585302dc5 | |||
| 7432c0775b | |||
| 8666ac7b85 | |||
| 827cbfd03c | |||
| 64a5e8f236 | |||
| 6a60315011 | |||
| a234334f69 | |||
| d71acbd909 | |||
| 33e672d135 | |||
| a26a696e34 | |||
| c63827d5a0 | |||
| 998f9f6ad0 | |||
| 0e188d3bff | |||
| 4a0867c5f2 | |||
| 4fb1955303 | |||
| ef202cd8b8 | |||
| 3648b4539b | |||
| b78ac9355a | |||
| f023994074 | |||
| a47e77bdf9 | |||
| 13773c267d | |||
| deccbf6d9a | |||
| ec1f92c16a | |||
| 5436e605b0 | |||
| 949ae6a7aa | |||
| b957c563c6 | |||
| 36c73e1d64 | |||
| d8f0925466 | |||
| 77d1b2f648 | |||
| 7a82dd3baf | |||
| 7c5573199f | |||
| 55146b70bd | |||
| c2a26458e8 | |||
| 6be895f83c | |||
| fcae79eb9a | |||
| 9a342d979f | |||
| a48a7c321d | |||
| fd167bc19f | |||
| 11f794c9df | |||
| 30b353fabe | |||
| 61590a115c | |||
| 982dfbdd61 | |||
| 9a5605f5de | |||
| 5d62055838 | |||
| 3e886a8a5b | |||
| eb1d4736b0 | |||
| affcdf49f9 | |||
| 06a4a3f8af | |||
| eb58d23656 | |||
| ed2ee11af8 | |||
| 6ed833bf28 | |||
| 196e8af786 | |||
| 17aafbc595 | |||
| 1dcf8cf36c | |||
| 3fc6bc7e53 | |||
| fce337b823 | |||
| 6e3c4a856c | |||
| 05f44f3c62 | |||
| d609eed733 | |||
| 65c4e6ad94 | |||
| 6fc11568c0 | |||
| 494aa6e090 | |||
| abab91748c | |||
| f86ef41980 | |||
| a22191c1fb | |||
| db2a6b239e | |||
| 25726a3df9 | |||
| a95c4d673d | |||
| b6b53d7b83 | |||
| 573a5c6a53 | |||
| 7db8868043 | |||
| 7ee89a6e1d | |||
| 5e22b1cd27 | |||
| 2e5eee5092 | |||
| b341608130 | |||
| e6e8ffb1c3 | |||
| 60c851972e | |||
| dcfc552254 | |||
| 8bb92f5c19 | |||
| 0ca338ade0 | |||
| 272424d379 | |||
| 6d72f33da7 | |||
| c0fab06356 | |||
| 1423a7ce91 | |||
| 053a432804 | |||
| f50129baa3 | |||
| 9150e8f188 | |||
| b637ab3ceb | |||
| 32d38dd876 | |||
| a04f4bd4b2 | |||
| ad68219568 | |||
| af117d810d | |||
| 5d764abdc6 | |||
| a9e9c69265 | |||
| 461e86eb82 | |||
| 7e87ffa0fd | |||
| 7bfa698796 | |||
| 285f64ed62 | |||
| b13b1d7b70 | |||
| 212e0cd812 | |||
| 589a8e101d | |||
| b8b4169b1a | |||
| e8aac64083 | |||
| 8e3ae9bb85 | |||
| 14a549928f | |||
| 83e1fb715e | |||
| aeeac8e343 | |||
| 5fc6d50486 | |||
| edc7c111cb | |||
| 05a754bc92 | |||
| dff58c56fb | |||
| 58709a1d32 | |||
| 554567fa82 | |||
| 3ad51db9c2 | |||
| 007d74ee23 | |||
| cd15214d77 | |||
| 32eca24468 | |||
| a96e25ef5d | |||
| 5087fb1904 | |||
| 2c4af20cb0 | |||
| 78cdc63b76 | |||
| 6ef191563a | |||
| daf616be22 | |||
| 278dc84bb9 | |||
| 686a2931e6 | |||
| 5be5a0e417 | |||
| cd2d1dbb76 | |||
| 68a92623d0 | |||
| 81b3255577 | |||
| fc33a22f27 | |||
| 5267c76580 | |||
| 2908b993a3 | |||
| 1c172bf513 | |||
| aa037e4a0c | |||
| 10dd04e03c | |||
| 560f75c755 | |||
| f2ce65fb84 | |||
| eb1d463889 | |||
| 8d021cb29c | |||
| 70faac1b6a | |||
| abaf425a36 | |||
| 95a0333057 | |||
| a49bba636a | |||
| e252ef2cb2 | |||
| 4ca6be8892 | |||
| 29227a2c9e | |||
| be4326eb83 | |||
| 72cc002d5a | |||
| 0efce8e9b4 | |||
| 398b12f176 | |||
| 4ca2eaaeda | |||
| 8711ab4738 | |||
| d58faad8de | |||
| 8f44698c58 | |||
| 14b2f05881 | |||
| 663071fbb8 | |||
| 098e79c301 | |||
| 5f18808f7d | |||
| cb19b706d5 | |||
| e2ed1db1e1 | |||
| fc748c6a8b | |||
| 294f136297 | |||
| f3fc29497e | |||
| 6e01d29355 | |||
| 749725adba | |||
| 5538031da1 | |||
| dd0153f4e3 | |||
| 690cf60b8c | |||
| cce40a97f2 | |||
| ed0d95ae1f | |||
| 1e28ec4a6a | |||
| 6b4daa5f16 | |||
| 3075fd0cf5 | |||
| b7470fd09f | |||
| 4b8bf1149e | |||
| d9567609de | |||
| 9944e202c8 | |||
| 923b59e2a0 | |||
| bd7d13136f | |||
| a08aa84884 | |||
| 5be48aaae8 | |||
| 8530ec12b7 | |||
| d777506b74 | |||
| 6e9a57421e | |||
| c6d47a49cd | |||
| 13c48da980 | |||
| df0658406c | |||
| ea548c34cf | |||
| 28824d4b6f | |||
| 341a1e3810 | |||
| dcf4a926f6 | |||
| c12bdbb8a1 | |||
| 261706d808 | |||
| 904c3f4072 | |||
| 4a885ac56e | |||
| a51745868d | |||
| 9dd2d6c18c | |||
| 8aae405584 | |||
| 4a119e6012 | |||
| e3041177c7 | |||
| 607f83cf96 | |||
| 2c1fd46e24 |
@@ -1,21 +0,0 @@
|
||||
.libs
|
||||
.deps
|
||||
*.o
|
||||
*.lo
|
||||
.dirstamp
|
||||
*.la
|
||||
Makefile
|
||||
config.log
|
||||
config.status
|
||||
*~
|
||||
fficonfig.h
|
||||
include/ffi.h
|
||||
include/ffitarget.h
|
||||
libffi.pc
|
||||
libtool
|
||||
stamp-h1
|
||||
libffi*gz
|
||||
autom4te.cache
|
||||
libffi.xcodeproj/xcuserdata
|
||||
libffi.xcodeproj/project.xcworkspace
|
||||
ios/
|
||||
@@ -1,8 +0,0 @@
|
||||
language: c
|
||||
compiler:
|
||||
- gcc
|
||||
- clang
|
||||
|
||||
before_script: sudo apt-get install dejagnu
|
||||
|
||||
script: ./configure && make && make check
|
||||
-401
@@ -1,401 +0,0 @@
|
||||
Status
|
||||
======
|
||||
|
||||
libffi-3.0.13 was released on March 17, 2013. Check the libffi web
|
||||
page for updates: <URL:http://sourceware.org/libffi/>.
|
||||
|
||||
|
||||
What is libffi?
|
||||
===============
|
||||
|
||||
Compilers for high level languages generate code that follow certain
|
||||
conventions. These conventions are necessary, in part, for separate
|
||||
compilation to work. One such convention is the "calling
|
||||
convention". The "calling convention" is essentially a set of
|
||||
assumptions made by the compiler about where function arguments will
|
||||
be found on entry to a function. A "calling convention" also specifies
|
||||
where the return value for a function is found.
|
||||
|
||||
Some programs may not know at the time of compilation what arguments
|
||||
are to be passed to a function. For instance, an interpreter may be
|
||||
told at run-time about the number and types of arguments used to call
|
||||
a given function. Libffi can be used in such programs to provide a
|
||||
bridge from the interpreter program to compiled code.
|
||||
|
||||
The libffi library provides a portable, high level programming
|
||||
interface to various calling conventions. This allows a programmer to
|
||||
call any function specified by a call interface description at run
|
||||
time.
|
||||
|
||||
FFI stands for Foreign Function Interface. A foreign function
|
||||
interface is the popular name for the interface that allows code
|
||||
written in one language to call code written in another language. The
|
||||
libffi library really only provides the lowest, machine dependent
|
||||
layer of a fully featured foreign function interface. A layer must
|
||||
exist above libffi that handles type conversions for values passed
|
||||
between the two languages.
|
||||
|
||||
|
||||
Supported Platforms
|
||||
===================
|
||||
|
||||
Libffi has been ported to many different platforms.
|
||||
For specific configuration details and testing status, please
|
||||
refer to the wiki page here:
|
||||
|
||||
http://www.moxielogic.org/wiki/index.php?title=Libffi_3.0.13
|
||||
|
||||
At the time of release, the following basic configurations have been
|
||||
tested:
|
||||
|
||||
|-----------------+------------------+-------------------------|
|
||||
| Architecture | Operating System | Compiler |
|
||||
|-----------------+------------------+-------------------------|
|
||||
| AArch64 | Linux | GCC |
|
||||
| Alpha | Linux | GCC |
|
||||
| Alpha | Tru64 | GCC |
|
||||
| ARM | Linux | GCC |
|
||||
| ARM | iOS | GCC |
|
||||
| AVR32 | Linux | GCC |
|
||||
| Blackfin | uClinux | GCC |
|
||||
| HPPA | HPUX | GCC |
|
||||
| IA-64 | Linux | GCC |
|
||||
| M68K | FreeMiNT | GCC |
|
||||
| M68K | Linux | GCC |
|
||||
| M68K | RTEMS | GCC |
|
||||
| Meta | Linux | GCC |
|
||||
| MicroBlaze | Linux | GCC |
|
||||
| MIPS | IRIX | GCC |
|
||||
| MIPS | Linux | GCC |
|
||||
| MIPS | RTEMS | GCC |
|
||||
| MIPS64 | Linux | GCC |
|
||||
| Moxie | Bare metal | GCC
|
||||
| PowerPC 32-bit | AIX | IBM XL C |
|
||||
| PowerPC 64-bit | AIX | IBM XL C |
|
||||
| PowerPC | AMIGA | GCC |
|
||||
| PowerPC | Linux | GCC |
|
||||
| PowerPC | Mac OSX | GCC |
|
||||
| PowerPC | FreeBSD | GCC |
|
||||
| PowerPC 64-bit | FreeBSD | GCC |
|
||||
| PowerPC 64-bit | Linux | GCC |
|
||||
| S390 | Linux | GCC |
|
||||
| S390X | Linux | GCC |
|
||||
| SPARC | Linux | GCC |
|
||||
| SPARC | Solaris | GCC |
|
||||
| SPARC | Solaris | Oracle Solaris Studio C |
|
||||
| SPARC64 | Linux | GCC |
|
||||
| SPARC64 | FreeBSD | GCC |
|
||||
| SPARC64 | Solaris | Oracle Solaris Studio C |
|
||||
| TILE-Gx/TILEPro | Linux | GCC |
|
||||
| X86 | FreeBSD | GCC |
|
||||
| X86 | GNU HURD | GCC |
|
||||
| X86 | Interix | GCC |
|
||||
| X86 | kFreeBSD | GCC |
|
||||
| X86 | Linux | GCC |
|
||||
| X86 | Mac OSX | GCC |
|
||||
| X86 | OpenBSD | GCC |
|
||||
| X86 | OS/2 | GCC |
|
||||
| X86 | Solaris | GCC |
|
||||
| X86 | Solaris | Oracle Solaris Studio C |
|
||||
| X86 | Windows/Cygwin | GCC |
|
||||
| X86 | Windows/MingW | GCC |
|
||||
| X86-64 | FreeBSD | GCC |
|
||||
| X86-64 | Linux | GCC |
|
||||
| X86-64 | Linux/x32 | GCC |
|
||||
| X86-64 | OpenBSD | GCC |
|
||||
| X86-64 | Solaris | Oracle Solaris Studio C |
|
||||
| X86-64 | Windows/MingW | GCC |
|
||||
| Xtensa | Linux | GCC |
|
||||
|-----------------+------------------+-------------------------|
|
||||
|
||||
Please send additional platform test results to
|
||||
libffi-discuss@sourceware.org and feel free to update the wiki page
|
||||
above.
|
||||
|
||||
Installing libffi
|
||||
=================
|
||||
|
||||
First you must configure the distribution for your particular
|
||||
system. Go to the directory you wish to build libffi in and run the
|
||||
"configure" program found in the root directory of the libffi source
|
||||
distribution.
|
||||
|
||||
You may want to tell configure where to install the libffi library and
|
||||
header files. To do that, use the --prefix configure switch. Libffi
|
||||
will install under /usr/local by default.
|
||||
|
||||
If you want to enable extra run-time debugging checks use the the
|
||||
--enable-debug configure switch. This is useful when your program dies
|
||||
mysteriously while using libffi.
|
||||
|
||||
Another useful configure switch is --enable-purify-safety. Using this
|
||||
will add some extra code which will suppress certain warnings when you
|
||||
are using Purify with libffi. Only use this switch when using
|
||||
Purify, as it will slow down the library.
|
||||
|
||||
It's also possible to build libffi on Windows platforms with
|
||||
Microsoft's Visual C++ compiler. In this case, use the msvcc.sh
|
||||
wrapper script during configuration like so:
|
||||
|
||||
path/to/configure CC=path/to/msvcc.sh LD=link CPP=\"cl -nologo -EP\"
|
||||
|
||||
For 64-bit Windows builds, use CC="path/to/msvcc.sh -m64".
|
||||
You may also need to specify --build appropriately. When building with MSVC
|
||||
under a MingW environment, you may need to remove the line in configure
|
||||
that sets 'fix_srcfile_path' to a 'cygpath' command. ('cygpath' is not
|
||||
present in MingW, and is not required when using MingW-style paths.)
|
||||
|
||||
For iOS builds, the 'libffi.xcodeproj' Xcode project is available.
|
||||
|
||||
Configure has many other options. Use "configure --help" to see them all.
|
||||
|
||||
Once configure has finished, type "make". Note that you must be using
|
||||
GNU make. You can ftp GNU make from ftp.gnu.org:/pub/gnu/make .
|
||||
|
||||
To ensure that libffi is working as advertised, type "make check".
|
||||
This will require that you have DejaGNU installed.
|
||||
|
||||
To install the library and header files, type "make install".
|
||||
|
||||
|
||||
History
|
||||
=======
|
||||
|
||||
See the ChangeLog files for details.
|
||||
|
||||
3.0.13 Mar-17-13
|
||||
Add Meta support.
|
||||
Add missing Moxie bits.
|
||||
Fix stack alignment bug on 32-bit x86.
|
||||
Build fix for m68000 targets.
|
||||
Build fix for soft-float Power targets.
|
||||
Fix the install dir location for some platforms when building
|
||||
with GCC (OS X, Solaris).
|
||||
Fix Cygwin regression.
|
||||
|
||||
3.0.12 Feb-11-13
|
||||
Add Moxie support.
|
||||
Add AArch64 support.
|
||||
Add Blackfin support.
|
||||
Add TILE-Gx/TILEPro support.
|
||||
Add MicroBlaze support.
|
||||
Add Xtensa support.
|
||||
Add support for PaX enabled kernels with MPROTECT.
|
||||
Add support for native vendor compilers on
|
||||
Solaris and AIX.
|
||||
Work around LLVM/GCC interoperability issue on x86_64.
|
||||
|
||||
3.0.11 Apr-11-12
|
||||
Lots of build fixes.
|
||||
Add Amiga newer MacOS support.
|
||||
Add support for variadic functions (ffi_prep_cif_var).
|
||||
Add Linux/x32 support.
|
||||
Add thiscall, fastcall and MSVC cdecl support on Windows.
|
||||
Add Amiga and newer MacOS support.
|
||||
Add m68k FreeMiNT support.
|
||||
Integration with iOS' xcode build tools.
|
||||
Fix Octeon and MC68881 support.
|
||||
Fix code pessimizations.
|
||||
|
||||
3.0.10 Aug-23-11
|
||||
Add support for Apple's iOS.
|
||||
Add support for ARM VFP ABI.
|
||||
Add RTEMS support for MIPS and M68K.
|
||||
Fix instruction cache clearing problems on
|
||||
ARM and SPARC.
|
||||
Fix the N64 build on mips-sgi-irix6.5.
|
||||
Enable builds with Microsoft's compiler.
|
||||
Enable x86 builds with Oracle's Solaris compiler.
|
||||
Fix support for calling code compiled with Oracle's Sparc
|
||||
Solaris compiler.
|
||||
Testsuite fixes for Tru64 Unix.
|
||||
Additional platform support.
|
||||
|
||||
3.0.9 Dec-31-09
|
||||
Add AVR32 and win64 ports. Add ARM softfp support.
|
||||
Many fixes for AIX, Solaris, HP-UX, *BSD.
|
||||
Several PowerPC and x86-64 bug fixes.
|
||||
Build DLL for windows.
|
||||
|
||||
3.0.8 Dec-19-08
|
||||
Add *BSD, BeOS, and PA-Linux support.
|
||||
|
||||
3.0.7 Nov-11-08
|
||||
Fix for ppc FreeBSD.
|
||||
(thanks to Andreas Tobler)
|
||||
|
||||
3.0.6 Jul-17-08
|
||||
Fix for closures on sh.
|
||||
Mark the sh/sh64 stack as non-executable.
|
||||
(both thanks to Kaz Kojima)
|
||||
|
||||
3.0.5 Apr-3-08
|
||||
Fix libffi.pc file.
|
||||
Fix #define ARM for IcedTea users.
|
||||
Fix x86 closure bug.
|
||||
|
||||
3.0.4 Feb-24-08
|
||||
Fix x86 OpenBSD configury.
|
||||
|
||||
3.0.3 Feb-22-08
|
||||
Enable x86 OpenBSD thanks to Thomas Heller, and
|
||||
x86-64 FreeBSD thanks to Björn König and Andreas Tobler.
|
||||
Clean up test instruction in README.
|
||||
|
||||
3.0.2 Feb-21-08
|
||||
Improved x86 FreeBSD support.
|
||||
Thanks to Björn König.
|
||||
|
||||
3.0.1 Feb-15-08
|
||||
Fix instruction cache flushing bug on MIPS.
|
||||
Thanks to David Daney.
|
||||
|
||||
3.0.0 Feb-15-08
|
||||
Many changes, mostly thanks to the GCC project.
|
||||
Cygnus Solutions is now Red Hat.
|
||||
|
||||
[10 years go by...]
|
||||
|
||||
1.20 Oct-5-98
|
||||
Raffaele Sena produces ARM port.
|
||||
|
||||
1.19 Oct-5-98
|
||||
Fixed x86 long double and long long return support.
|
||||
m68k bug fixes from Andreas Schwab.
|
||||
Patch for DU assembler compatibility for the Alpha from Richard
|
||||
Henderson.
|
||||
|
||||
1.18 Apr-17-98
|
||||
Bug fixes and MIPS configuration changes.
|
||||
|
||||
1.17 Feb-24-98
|
||||
Bug fixes and m68k port from Andreas Schwab. PowerPC port from
|
||||
Geoffrey Keating. Various bug x86, Sparc and MIPS bug fixes.
|
||||
|
||||
1.16 Feb-11-98
|
||||
Richard Henderson produces Alpha port.
|
||||
|
||||
1.15 Dec-4-97
|
||||
Fixed an n32 ABI bug. New libtool, auto* support.
|
||||
|
||||
1.14 May-13-97
|
||||
libtool is now used to generate shared and static libraries.
|
||||
Fixed a minor portability problem reported by Russ McManus
|
||||
<mcmanr@eq.gs.com>.
|
||||
|
||||
1.13 Dec-2-96
|
||||
Added --enable-purify-safety to keep Purify from complaining
|
||||
about certain low level code.
|
||||
Sparc fix for calling functions with < 6 args.
|
||||
Linux x86 a.out fix.
|
||||
|
||||
1.12 Nov-22-96
|
||||
Added missing ffi_type_void, needed for supporting void return
|
||||
types. Fixed test case for non MIPS machines. Cygnus Support
|
||||
is now Cygnus Solutions.
|
||||
|
||||
1.11 Oct-30-96
|
||||
Added notes about GNU make.
|
||||
|
||||
1.10 Oct-29-96
|
||||
Added configuration fix for non GNU compilers.
|
||||
|
||||
1.09 Oct-29-96
|
||||
Added --enable-debug configure switch. Clean-ups based on LCLint
|
||||
feedback. ffi_mips.h is always installed. Many configuration
|
||||
fixes. Fixed ffitest.c for sparc builds.
|
||||
|
||||
1.08 Oct-15-96
|
||||
Fixed n32 problem. Many clean-ups.
|
||||
|
||||
1.07 Oct-14-96
|
||||
Gordon Irlam rewrites v8.S again. Bug fixes.
|
||||
|
||||
1.06 Oct-14-96
|
||||
Gordon Irlam improved the sparc port.
|
||||
|
||||
1.05 Oct-14-96
|
||||
Interface changes based on feedback.
|
||||
|
||||
1.04 Oct-11-96
|
||||
Sparc port complete (modulo struct passing bug).
|
||||
|
||||
1.03 Oct-10-96
|
||||
Passing struct args, and returning struct values works for
|
||||
all architectures/calling conventions. Expanded tests.
|
||||
|
||||
1.02 Oct-9-96
|
||||
Added SGI n32 support. Fixed bugs in both o32 and Linux support.
|
||||
Added "make test".
|
||||
|
||||
1.01 Oct-8-96
|
||||
Fixed float passing bug in mips version. Restructured some
|
||||
of the code. Builds cleanly with SGI tools.
|
||||
|
||||
1.00 Oct-7-96
|
||||
First release. No public announcement.
|
||||
|
||||
|
||||
Authors & Credits
|
||||
=================
|
||||
|
||||
libffi was originally written by Anthony Green <green@redhat.com>.
|
||||
|
||||
The developers of the GNU Compiler Collection project have made
|
||||
innumerable valuable contributions. See the ChangeLog file for
|
||||
details.
|
||||
|
||||
Some of the ideas behind libffi were inspired by Gianni Mariani's free
|
||||
gencall library for Silicon Graphics machines.
|
||||
|
||||
The closure mechanism was designed and implemented by Kresten Krab
|
||||
Thorup.
|
||||
|
||||
Major processor architecture ports were contributed by the following
|
||||
developers:
|
||||
|
||||
aarch64 Marcus Shawcroft, James Greenhalgh
|
||||
alpha Richard Henderson
|
||||
arm Raffaele Sena
|
||||
blackfin Alexandre Keunecke I. de Mendonca
|
||||
cris Simon Posnjak, Hans-Peter Nilsson
|
||||
frv Anthony Green
|
||||
ia64 Hans Boehm
|
||||
m32r Kazuhiro Inaoka
|
||||
m68k Andreas Schwab
|
||||
microblaze Nathan Rossi
|
||||
mips Anthony Green, Casey Marshall
|
||||
mips64 David Daney
|
||||
moxie Anthony Green
|
||||
pa Randolph Chung, Dave Anglin, Andreas Tobler
|
||||
powerpc Geoffrey Keating, Andreas Tobler,
|
||||
David Edelsohn, John Hornkvist
|
||||
powerpc64 Jakub Jelinek
|
||||
s390 Gerhard Tonn, Ulrich Weigand
|
||||
sh Kaz Kojima
|
||||
sh64 Kaz Kojima
|
||||
sparc Anthony Green, Gordon Irlam
|
||||
tile-gx/tilepro Walter Lee
|
||||
x86 Anthony Green, Jon Beniston
|
||||
x86-64 Bo Thorsen
|
||||
xtensa Chris Zankel
|
||||
|
||||
Jesper Skov and Andrew Haley both did more than their fair share of
|
||||
stepping through the code and tracking down bugs.
|
||||
|
||||
Thanks also to Tom Tromey for bug fixes, documentation and
|
||||
configuration help.
|
||||
|
||||
Thanks to Jim Blandy, who provided some useful feedback on the libffi
|
||||
interface.
|
||||
|
||||
Andreas Tobler has done a tremendous amount of work on the testsuite.
|
||||
|
||||
Alex Oliva solved the executable page problem for SElinux.
|
||||
|
||||
The list above is almost certainly incomplete and inaccurate. I'm
|
||||
happy to make corrections or additions upon request.
|
||||
|
||||
If you have a problem, or have found a bug, please send a note to the
|
||||
author at green@moxielogic.com, or the project mailing list at
|
||||
libffi-discuss@sourceware.org.
|
||||
externo
-1903
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -1,67 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
PLATFORM_IOS=/Developer/Platforms/iPhoneOS.platform/
|
||||
PLATFORM_IOS_SIM=/Developer/Platforms/iPhoneSimulator.platform/
|
||||
SDK_IOS_VERSION="4.2"
|
||||
MIN_IOS_VERSION="3.0"
|
||||
OUTPUT_DIR="universal-ios"
|
||||
|
||||
build_target () {
|
||||
local platform=$1
|
||||
local sdk=$2
|
||||
local arch=$3
|
||||
local triple=$4
|
||||
local builddir=$5
|
||||
|
||||
mkdir -p "${builddir}"
|
||||
pushd "${builddir}"
|
||||
export CC="${platform}"/Developer/usr/bin/gcc-4.2
|
||||
export CFLAGS="-arch ${arch} -isysroot ${sdk} -miphoneos-version-min=${MIN_IOS_VERSION}"
|
||||
../configure --host=${triple} && make
|
||||
popd
|
||||
}
|
||||
|
||||
# Build all targets
|
||||
build_target "${PLATFORM_IOS}" "${PLATFORM_IOS}/Developer/SDKs/iPhoneOS${SDK_IOS_VERSION}.sdk/" armv6 arm-apple-darwin10 armv6-ios
|
||||
build_target "${PLATFORM_IOS}" "${PLATFORM_IOS}/Developer/SDKs/iPhoneOS${SDK_IOS_VERSION}.sdk/" armv7 arm-apple-darwin10 armv7-ios
|
||||
build_target "${PLATFORM_IOS_SIM}" "${PLATFORM_IOS_SIM}/Developer/SDKs/iPhoneSimulator${SDK_IOS_VERSION}.sdk/" i386 i386-apple-darwin10 i386-ios-sim
|
||||
|
||||
# Create universal output directories
|
||||
mkdir -p "${OUTPUT_DIR}"
|
||||
mkdir -p "${OUTPUT_DIR}/include"
|
||||
mkdir -p "${OUTPUT_DIR}/include/armv6"
|
||||
mkdir -p "${OUTPUT_DIR}/include/armv7"
|
||||
mkdir -p "${OUTPUT_DIR}/include/i386"
|
||||
|
||||
# Create the universal binary
|
||||
lipo -create armv6-ios/.libs/libffi.a armv7-ios/.libs/libffi.a i386-ios-sim/.libs/libffi.a -output "${OUTPUT_DIR}/libffi.a"
|
||||
|
||||
# Copy in the headers
|
||||
copy_headers () {
|
||||
local src=$1
|
||||
local dest=$2
|
||||
|
||||
# Fix non-relative header reference
|
||||
sed 's/<ffitarget.h>/"ffitarget.h"/' < "${src}/include/ffi.h" > "${dest}/ffi.h"
|
||||
cp "${src}/include/ffitarget.h" "${dest}"
|
||||
}
|
||||
|
||||
copy_headers armv6-ios "${OUTPUT_DIR}/include/armv6"
|
||||
copy_headers armv7-ios "${OUTPUT_DIR}/include/armv7"
|
||||
copy_headers i386-ios-sim "${OUTPUT_DIR}/include/i386"
|
||||
|
||||
# Create top-level header
|
||||
(
|
||||
cat << EOF
|
||||
#ifdef __arm__
|
||||
#include <arm/arch.h>
|
||||
#ifdef _ARM_ARCH_6
|
||||
#include "include/armv6/ffi.h"
|
||||
#elif _ARM_ARCH_7
|
||||
#include "include/armv7/ffi.h"
|
||||
#endif
|
||||
#elif defined(__i386__)
|
||||
#include "include/i386/ffi.h"
|
||||
#endif
|
||||
EOF
|
||||
) > "${OUTPUT_DIR}/ffi.h"
|
||||
externo
-17586
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
-570
@@ -1,570 +0,0 @@
|
||||
dnl Process this with autoconf to create configure
|
||||
|
||||
AC_PREREQ(2.68)
|
||||
|
||||
AC_INIT([libffi], [3.0.13], [http://github.com/atgreen/libffi/issues])
|
||||
AC_CONFIG_HEADERS([fficonfig.h])
|
||||
|
||||
AC_CANONICAL_SYSTEM
|
||||
target_alias=${target_alias-$host_alias}
|
||||
|
||||
. ${srcdir}/configure.host
|
||||
|
||||
AX_ENABLE_BUILDDIR
|
||||
|
||||
AM_INIT_AUTOMAKE
|
||||
|
||||
# The same as in boehm-gc and libstdc++. Have to borrow it from there.
|
||||
# We must force CC to /not/ be precious variables; otherwise
|
||||
# the wrong, non-multilib-adjusted value will be used in multilibs.
|
||||
# As a side effect, we have to subst CFLAGS ourselves.
|
||||
# Also save and restore CFLAGS, since AC_PROG_CC will come up with
|
||||
# defaults of its own if none are provided.
|
||||
|
||||
m4_rename([_AC_ARG_VAR_PRECIOUS],[real_PRECIOUS])
|
||||
m4_define([_AC_ARG_VAR_PRECIOUS],[])
|
||||
save_CFLAGS=$CFLAGS
|
||||
AC_PROG_CC
|
||||
CFLAGS=$save_CFLAGS
|
||||
m4_undefine([_AC_ARG_VAR_PRECIOUS])
|
||||
m4_rename_force([real_PRECIOUS],[_AC_ARG_VAR_PRECIOUS])
|
||||
|
||||
AC_SUBST(CFLAGS)
|
||||
|
||||
AM_PROG_AS
|
||||
AM_PROG_CC_C_O
|
||||
AC_PROG_LIBTOOL
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
|
||||
# Test for 64-bit build.
|
||||
AC_CHECK_SIZEOF([size_t])
|
||||
|
||||
AX_COMPILER_VENDOR
|
||||
AX_CC_MAXOPT
|
||||
# The AX_CFLAGS_WARN_ALL macro doesn't currently work for sunpro
|
||||
# compiler.
|
||||
if test "$ax_cv_c_compiler_vendor" != "sun"; then
|
||||
AX_CFLAGS_WARN_ALL
|
||||
fi
|
||||
|
||||
if test "x$GCC" = "xyes"; then
|
||||
CFLAGS="$CFLAGS -fexceptions"
|
||||
touch local.exp
|
||||
else
|
||||
cat > local.exp <<EOF
|
||||
set CC_FOR_TARGET "$CC"
|
||||
EOF
|
||||
fi
|
||||
|
||||
AM_MAINTAINER_MODE
|
||||
|
||||
AC_CHECK_HEADERS(sys/mman.h)
|
||||
AC_CHECK_FUNCS(mmap)
|
||||
AC_FUNC_MMAP_BLACKLIST
|
||||
|
||||
dnl The -no-testsuite modules omit the test subdir.
|
||||
AM_CONDITIONAL(TESTSUBDIR, test -d $srcdir/testsuite)
|
||||
|
||||
TARGETDIR="unknown"
|
||||
case "$host" in
|
||||
aarch64*-*-*)
|
||||
TARGET=AARCH64; TARGETDIR=aarch64
|
||||
;;
|
||||
|
||||
alpha*-*-*)
|
||||
TARGET=ALPHA; TARGETDIR=alpha;
|
||||
# Support 128-bit long double, changeable via command-line switch.
|
||||
HAVE_LONG_DOUBLE='defined(__LONG_DOUBLE_128__)'
|
||||
;;
|
||||
|
||||
arm*-*-*)
|
||||
TARGET=ARM; TARGETDIR=arm
|
||||
;;
|
||||
|
||||
amd64-*-freebsd* | amd64-*-openbsd*)
|
||||
TARGET=X86_64; TARGETDIR=x86
|
||||
;;
|
||||
|
||||
amd64-*-freebsd*)
|
||||
TARGET=X86_64; TARGETDIR=x86
|
||||
;;
|
||||
|
||||
amd64-*-freebsd*)
|
||||
TARGET=X86_64; TARGETDIR=x86
|
||||
;;
|
||||
|
||||
avr32*-*-*)
|
||||
TARGET=AVR32; TARGETDIR=avr32
|
||||
;;
|
||||
|
||||
bfin*)
|
||||
TARGET=BFIN; TARGETDIR=bfin
|
||||
;;
|
||||
|
||||
cris-*-*)
|
||||
TARGET=LIBFFI_CRIS; TARGETDIR=cris
|
||||
;;
|
||||
|
||||
frv-*-*)
|
||||
TARGET=FRV; TARGETDIR=frv
|
||||
;;
|
||||
|
||||
hppa*-*-linux* | parisc*-*-linux* | hppa*-*-openbsd*)
|
||||
TARGET=PA_LINUX; TARGETDIR=pa
|
||||
;;
|
||||
hppa*64-*-hpux*)
|
||||
TARGET=PA64_HPUX; TARGETDIR=pa
|
||||
;;
|
||||
hppa*-*-hpux*)
|
||||
TARGET=PA_HPUX; TARGETDIR=pa
|
||||
;;
|
||||
|
||||
i?86-*-freebsd* | i?86-*-openbsd*)
|
||||
TARGET=X86_FREEBSD; TARGETDIR=x86
|
||||
;;
|
||||
i?86-win32* | i?86-*-cygwin* | i?86-*-mingw* | i?86-*-os2* | i?86-*-interix*)
|
||||
TARGET=X86_WIN32; TARGETDIR=x86
|
||||
# All mingw/cygwin/win32 builds require -no-undefined for sharedlib.
|
||||
# We must also check with_cross_host to decide if this is a native
|
||||
# or cross-build and select where to install dlls appropriately.
|
||||
if test -n "$with_cross_host" &&
|
||||
test x"$with_cross_host" != x"no"; then
|
||||
AM_LTLDFLAGS='-no-undefined -bindir "$(toolexeclibdir)"';
|
||||
else
|
||||
AM_LTLDFLAGS='-no-undefined -bindir "$(bindir)"';
|
||||
fi
|
||||
;;
|
||||
i?86-*-darwin*)
|
||||
TARGET=X86_DARWIN; TARGETDIR=x86
|
||||
;;
|
||||
i?86-*-solaris2.1[[0-9]]*)
|
||||
TARGETDIR=x86
|
||||
if test $ac_cv_sizeof_size_t = 4; then
|
||||
TARGET=X86;
|
||||
else
|
||||
TARGET=X86_64;
|
||||
fi
|
||||
;;
|
||||
|
||||
x86_64-*-darwin*)
|
||||
TARGET=X86_DARWIN; TARGETDIR=x86
|
||||
;;
|
||||
|
||||
x86_64-*-cygwin* | x86_64-*-mingw*)
|
||||
TARGET=X86_WIN64; TARGETDIR=x86
|
||||
# All mingw/cygwin/win32 builds require -no-undefined for sharedlib.
|
||||
# We must also check with_cross_host to decide if this is a native
|
||||
# or cross-build and select where to install dlls appropriately.
|
||||
if test -n "$with_cross_host" &&
|
||||
test x"$with_cross_host" != x"no"; then
|
||||
AM_LTLDFLAGS='-no-undefined -bindir "$(toolexeclibdir)"';
|
||||
else
|
||||
AM_LTLDFLAGS='-no-undefined -bindir "$(bindir)"';
|
||||
fi
|
||||
;;
|
||||
|
||||
i?86-*-* | x86_64-*-*)
|
||||
TARGETDIR=x86
|
||||
if test $ac_cv_sizeof_size_t = 4; then
|
||||
case "$host" in
|
||||
*-gnux32)
|
||||
TARGET=X86_64
|
||||
;;
|
||||
*)
|
||||
TARGET=X86
|
||||
;;
|
||||
esac
|
||||
else
|
||||
TARGET=X86_64;
|
||||
fi
|
||||
;;
|
||||
|
||||
ia64*-*-*)
|
||||
TARGET=IA64; TARGETDIR=ia64
|
||||
;;
|
||||
|
||||
m32r*-*-*)
|
||||
TARGET=M32R; TARGETDIR=m32r
|
||||
;;
|
||||
|
||||
m68k-*-*)
|
||||
TARGET=M68K; TARGETDIR=m68k
|
||||
;;
|
||||
|
||||
microblaze*-*-*)
|
||||
TARGET=MICROBLAZE; TARGETDIR=microblaze
|
||||
;;
|
||||
|
||||
moxie-*-*)
|
||||
TARGET=MOXIE; TARGETDIR=moxie
|
||||
;;
|
||||
|
||||
metag-*-*)
|
||||
TARGET=METAG; TARGETDIR=metag
|
||||
;;
|
||||
|
||||
mips-sgi-irix5.* | mips-sgi-irix6.* | mips*-*-rtems*)
|
||||
TARGET=MIPS; TARGETDIR=mips
|
||||
;;
|
||||
mips*-*-linux* | mips*-*-openbsd*)
|
||||
# Support 128-bit long double for NewABI.
|
||||
HAVE_LONG_DOUBLE='defined(__mips64)'
|
||||
TARGET=MIPS; TARGETDIR=mips
|
||||
;;
|
||||
|
||||
powerpc*-*-linux* | powerpc-*-sysv*)
|
||||
TARGET=POWERPC; TARGETDIR=powerpc
|
||||
;;
|
||||
powerpc-*-amigaos*)
|
||||
TARGET=POWERPC; TARGETDIR=powerpc
|
||||
;;
|
||||
powerpc-*-beos*)
|
||||
TARGET=POWERPC; TARGETDIR=powerpc
|
||||
;;
|
||||
powerpc-*-darwin* | powerpc64-*-darwin*)
|
||||
TARGET=POWERPC_DARWIN; TARGETDIR=powerpc
|
||||
;;
|
||||
powerpc-*-aix* | rs6000-*-aix*)
|
||||
TARGET=POWERPC_AIX; TARGETDIR=powerpc
|
||||
;;
|
||||
powerpc-*-freebsd* | powerpc-*-openbsd*)
|
||||
TARGET=POWERPC_FREEBSD; TARGETDIR=powerpc
|
||||
;;
|
||||
powerpc64-*-freebsd*)
|
||||
TARGET=POWERPC; TARGETDIR=powerpc
|
||||
;;
|
||||
powerpc*-*-rtems*)
|
||||
TARGET=POWERPC; TARGETDIR=powerpc
|
||||
;;
|
||||
|
||||
s390-*-* | s390x-*-*)
|
||||
TARGET=S390; TARGETDIR=s390
|
||||
;;
|
||||
|
||||
sh-*-* | sh[[34]]*-*-*)
|
||||
TARGET=SH; TARGETDIR=sh
|
||||
;;
|
||||
sh64-*-* | sh5*-*-*)
|
||||
TARGET=SH64; TARGETDIR=sh64
|
||||
;;
|
||||
|
||||
sparc*-*-*)
|
||||
TARGET=SPARC; TARGETDIR=sparc
|
||||
;;
|
||||
|
||||
tile*-*)
|
||||
TARGET=TILE; TARGETDIR=tile
|
||||
;;
|
||||
|
||||
xtensa*-*)
|
||||
TARGET=XTENSA; TARGETDIR=xtensa
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
AC_SUBST(AM_RUNTESTFLAGS)
|
||||
AC_SUBST(AM_LTLDFLAGS)
|
||||
|
||||
if test $TARGETDIR = unknown; then
|
||||
AC_MSG_ERROR(["libffi has not been ported to $host."])
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL(MIPS, test x$TARGET = xMIPS)
|
||||
AM_CONDITIONAL(BFIN, test x$TARGET = xBFIN)
|
||||
AM_CONDITIONAL(SPARC, test x$TARGET = xSPARC)
|
||||
AM_CONDITIONAL(X86, test x$TARGET = xX86)
|
||||
AM_CONDITIONAL(X86_FREEBSD, test x$TARGET = xX86_FREEBSD)
|
||||
AM_CONDITIONAL(X86_WIN32, test x$TARGET = xX86_WIN32)
|
||||
AM_CONDITIONAL(X86_WIN64, test x$TARGET = xX86_WIN64)
|
||||
AM_CONDITIONAL(X86_DARWIN, test x$TARGET = xX86_DARWIN)
|
||||
AM_CONDITIONAL(ALPHA, test x$TARGET = xALPHA)
|
||||
AM_CONDITIONAL(IA64, test x$TARGET = xIA64)
|
||||
AM_CONDITIONAL(M32R, test x$TARGET = xM32R)
|
||||
AM_CONDITIONAL(M68K, test x$TARGET = xM68K)
|
||||
AM_CONDITIONAL(MICROBLAZE, test x$TARGET = xMICROBLAZE)
|
||||
AM_CONDITIONAL(METAG, test x$TARGET = xMETAG)
|
||||
AM_CONDITIONAL(MOXIE, test x$TARGET = xMOXIE)
|
||||
AM_CONDITIONAL(POWERPC, test x$TARGET = xPOWERPC)
|
||||
AM_CONDITIONAL(POWERPC_AIX, test x$TARGET = xPOWERPC_AIX)
|
||||
AM_CONDITIONAL(POWERPC_DARWIN, test x$TARGET = xPOWERPC_DARWIN)
|
||||
AM_CONDITIONAL(POWERPC_FREEBSD, test x$TARGET = xPOWERPC_FREEBSD)
|
||||
AM_CONDITIONAL(AARCH64, test x$TARGET = xAARCH64)
|
||||
AM_CONDITIONAL(ARM, test x$TARGET = xARM)
|
||||
AM_CONDITIONAL(AVR32, test x$TARGET = xAVR32)
|
||||
AM_CONDITIONAL(LIBFFI_CRIS, test x$TARGET = xLIBFFI_CRIS)
|
||||
AM_CONDITIONAL(FRV, test x$TARGET = xFRV)
|
||||
AM_CONDITIONAL(S390, test x$TARGET = xS390)
|
||||
AM_CONDITIONAL(X86_64, test x$TARGET = xX86_64)
|
||||
AM_CONDITIONAL(SH, test x$TARGET = xSH)
|
||||
AM_CONDITIONAL(SH64, test x$TARGET = xSH64)
|
||||
AM_CONDITIONAL(PA_LINUX, test x$TARGET = xPA_LINUX)
|
||||
AM_CONDITIONAL(PA_HPUX, test x$TARGET = xPA_HPUX)
|
||||
AM_CONDITIONAL(PA64_HPUX, test x$TARGET = xPA64_HPUX)
|
||||
AM_CONDITIONAL(TILE, test x$TARGET = xTILE)
|
||||
AM_CONDITIONAL(XTENSA, test x$TARGET = xXTENSA)
|
||||
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_FUNCS(memcpy)
|
||||
AC_FUNC_ALLOCA
|
||||
|
||||
AC_CHECK_SIZEOF(double)
|
||||
AC_CHECK_SIZEOF(long double)
|
||||
|
||||
# Also AC_SUBST this variable for ffi.h.
|
||||
if test -z "$HAVE_LONG_DOUBLE"; then
|
||||
HAVE_LONG_DOUBLE=0
|
||||
if test $ac_cv_sizeof_double != $ac_cv_sizeof_long_double; then
|
||||
if test $ac_cv_sizeof_long_double != 0; then
|
||||
HAVE_LONG_DOUBLE=1
|
||||
AC_DEFINE(HAVE_LONG_DOUBLE, 1, [Define if you have the long double type and it is bigger than a double])
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
AC_SUBST(HAVE_LONG_DOUBLE)
|
||||
|
||||
AC_C_BIGENDIAN
|
||||
|
||||
GCC_AS_CFI_PSEUDO_OP
|
||||
|
||||
if test x$TARGET = xSPARC; then
|
||||
AC_CACHE_CHECK([assembler and linker support unaligned pc related relocs],
|
||||
libffi_cv_as_sparc_ua_pcrel, [
|
||||
save_CFLAGS="$CFLAGS"
|
||||
save_LDFLAGS="$LDFLAGS"
|
||||
CFLAGS="$CFLAGS -fpic"
|
||||
LDFLAGS="$LDFLAGS -shared"
|
||||
AC_TRY_LINK([asm (".text; foo: nop; .data; .align 4; .byte 0; .uaword %r_disp32(foo); .text");],,
|
||||
[libffi_cv_as_sparc_ua_pcrel=yes],
|
||||
[libffi_cv_as_sparc_ua_pcrel=no])
|
||||
CFLAGS="$save_CFLAGS"
|
||||
LDFLAGS="$save_LDFLAGS"])
|
||||
if test "x$libffi_cv_as_sparc_ua_pcrel" = xyes; then
|
||||
AC_DEFINE(HAVE_AS_SPARC_UA_PCREL, 1,
|
||||
[Define if your assembler and linker support unaligned PC relative relocs.])
|
||||
fi
|
||||
|
||||
AC_CACHE_CHECK([assembler .register pseudo-op support],
|
||||
libffi_cv_as_register_pseudo_op, [
|
||||
libffi_cv_as_register_pseudo_op=unknown
|
||||
# Check if we have .register
|
||||
AC_TRY_COMPILE(,[asm (".register %g2, #scratch");],
|
||||
[libffi_cv_as_register_pseudo_op=yes],
|
||||
[libffi_cv_as_register_pseudo_op=no])
|
||||
])
|
||||
if test "x$libffi_cv_as_register_pseudo_op" = xyes; then
|
||||
AC_DEFINE(HAVE_AS_REGISTER_PSEUDO_OP, 1,
|
||||
[Define if your assembler supports .register.])
|
||||
fi
|
||||
fi
|
||||
|
||||
if test x$TARGET = xX86 || test x$TARGET = xX86_WIN32 || test x$TARGET = xX86_64; then
|
||||
AC_CACHE_CHECK([assembler supports pc related relocs],
|
||||
libffi_cv_as_x86_pcrel, [
|
||||
libffi_cv_as_x86_pcrel=no
|
||||
echo '.text; foo: nop; .data; .long foo-.; .text' > conftest.s
|
||||
if $CC $CFLAGS -c conftest.s > /dev/null 2>&1; then
|
||||
libffi_cv_as_x86_pcrel=yes
|
||||
fi
|
||||
])
|
||||
if test "x$libffi_cv_as_x86_pcrel" = xyes; then
|
||||
AC_DEFINE(HAVE_AS_X86_PCREL, 1,
|
||||
[Define if your assembler supports PC relative relocs.])
|
||||
fi
|
||||
|
||||
AC_CACHE_CHECK([assembler .ascii pseudo-op support],
|
||||
libffi_cv_as_ascii_pseudo_op, [
|
||||
libffi_cv_as_ascii_pseudo_op=unknown
|
||||
# Check if we have .ascii
|
||||
AC_TRY_COMPILE(,[asm (".ascii \\"string\\"");],
|
||||
[libffi_cv_as_ascii_pseudo_op=yes],
|
||||
[libffi_cv_as_ascii_pseudo_op=no])
|
||||
])
|
||||
if test "x$libffi_cv_as_ascii_pseudo_op" = xyes; then
|
||||
AC_DEFINE(HAVE_AS_ASCII_PSEUDO_OP, 1,
|
||||
[Define if your assembler supports .ascii.])
|
||||
fi
|
||||
|
||||
AC_CACHE_CHECK([assembler .string pseudo-op support],
|
||||
libffi_cv_as_string_pseudo_op, [
|
||||
libffi_cv_as_string_pseudo_op=unknown
|
||||
# Check if we have .string
|
||||
AC_TRY_COMPILE(,[asm (".string \\"string\\"");],
|
||||
[libffi_cv_as_string_pseudo_op=yes],
|
||||
[libffi_cv_as_string_pseudo_op=no])
|
||||
])
|
||||
if test "x$libffi_cv_as_string_pseudo_op" = xyes; then
|
||||
AC_DEFINE(HAVE_AS_STRING_PSEUDO_OP, 1,
|
||||
[Define if your assembler supports .string.])
|
||||
fi
|
||||
fi
|
||||
|
||||
# On PaX enable kernels that have MPROTECT enable we can't use PROT_EXEC.
|
||||
AC_ARG_ENABLE(pax_emutramp,
|
||||
[ --enable-pax_emutramp enable pax emulated trampolines, for we can't use PROT_EXEC],
|
||||
if test "$enable_pax_emutramp" = "yes"; then
|
||||
AC_DEFINE(FFI_MMAP_EXEC_EMUTRAMP_PAX, 1,
|
||||
[Define this if you want to enable pax emulated trampolines])
|
||||
fi)
|
||||
|
||||
if test x$TARGET = xX86_WIN64; then
|
||||
LT_SYS_SYMBOL_USCORE
|
||||
if test "x$sys_symbol_underscore" = xyes; then
|
||||
AC_DEFINE(SYMBOL_UNDERSCORE, 1, [Define if symbols are underscored.])
|
||||
fi
|
||||
fi
|
||||
|
||||
FFI_EXEC_TRAMPOLINE_TABLE=0
|
||||
case "$target" in
|
||||
*arm*-apple-darwin*)
|
||||
FFI_EXEC_TRAMPOLINE_TABLE=1
|
||||
AC_DEFINE(FFI_EXEC_TRAMPOLINE_TABLE, 1,
|
||||
[Cannot use PROT_EXEC on this target, so, we revert to
|
||||
alternative means])
|
||||
;;
|
||||
*-apple-darwin1* | *-*-freebsd* | *-*-kfreebsd* | *-*-openbsd* | *-pc-solaris*)
|
||||
AC_DEFINE(FFI_MMAP_EXEC_WRIT, 1,
|
||||
[Cannot use malloc on this target, so, we revert to
|
||||
alternative means])
|
||||
;;
|
||||
esac
|
||||
AM_CONDITIONAL(FFI_EXEC_TRAMPOLINE_TABLE, test x$FFI_EXEC_TRAMPOLINE_TABLE = x1)
|
||||
AC_SUBST(FFI_EXEC_TRAMPOLINE_TABLE)
|
||||
|
||||
if test x$TARGET = xX86_64; then
|
||||
AC_CACHE_CHECK([assembler supports unwind section type],
|
||||
libffi_cv_as_x86_64_unwind_section_type, [
|
||||
libffi_cv_as_x86_64_unwind_section_type=yes
|
||||
echo '.section .eh_frame,"a",@unwind' > conftest.s
|
||||
if $CC $CFLAGS -c conftest.s 2>&1 | grep -i warning > /dev/null; then
|
||||
libffi_cv_as_x86_64_unwind_section_type=no
|
||||
fi
|
||||
])
|
||||
if test "x$libffi_cv_as_x86_64_unwind_section_type" = xyes; then
|
||||
AC_DEFINE(HAVE_AS_X86_64_UNWIND_SECTION_TYPE, 1,
|
||||
[Define if your assembler supports unwind section type.])
|
||||
fi
|
||||
fi
|
||||
|
||||
if test "x$GCC" = "xyes"; then
|
||||
AC_CACHE_CHECK([whether .eh_frame section should be read-only],
|
||||
libffi_cv_ro_eh_frame, [
|
||||
libffi_cv_ro_eh_frame=no
|
||||
echo 'extern void foo (void); void bar (void) { foo (); foo (); }' > conftest.c
|
||||
if $CC $CFLAGS -c -fpic -fexceptions -o conftest.o conftest.c > /dev/null 2>&1; then
|
||||
objdump -h conftest.o > conftest.dump 2>&1
|
||||
libffi_eh_frame_line=`grep -n eh_frame conftest.dump | cut -d: -f 1`
|
||||
libffi_test_line=`expr $libffi_eh_frame_line + 1`p
|
||||
sed -n $libffi_test_line conftest.dump > conftest.line
|
||||
if grep READONLY conftest.line > /dev/null; then
|
||||
libffi_cv_ro_eh_frame=yes
|
||||
fi
|
||||
fi
|
||||
rm -f conftest.*
|
||||
])
|
||||
if test "x$libffi_cv_ro_eh_frame" = xyes; then
|
||||
AC_DEFINE(HAVE_RO_EH_FRAME, 1,
|
||||
[Define if .eh_frame sections should be read-only.])
|
||||
AC_DEFINE(EH_FRAME_FLAGS, "a",
|
||||
[Define to the flags needed for the .section .eh_frame directive. ])
|
||||
else
|
||||
AC_DEFINE(EH_FRAME_FLAGS, "aw",
|
||||
[Define to the flags needed for the .section .eh_frame directive. ])
|
||||
fi
|
||||
|
||||
AC_CACHE_CHECK([for __attribute__((visibility("hidden")))],
|
||||
libffi_cv_hidden_visibility_attribute, [
|
||||
echo 'int __attribute__ ((visibility ("hidden"))) foo (void) { return 1 ; }' > conftest.c
|
||||
libffi_cv_hidden_visibility_attribute=no
|
||||
if AC_TRY_COMMAND(${CC-cc} -Werror -S conftest.c -o conftest.s 1>&AS_MESSAGE_LOG_FD); then
|
||||
if grep '\.hidden.*foo' conftest.s >/dev/null; then
|
||||
libffi_cv_hidden_visibility_attribute=yes
|
||||
fi
|
||||
fi
|
||||
rm -f conftest.*
|
||||
])
|
||||
if test $libffi_cv_hidden_visibility_attribute = yes; then
|
||||
AC_DEFINE(HAVE_HIDDEN_VISIBILITY_ATTRIBUTE, 1,
|
||||
[Define if __attribute__((visibility("hidden"))) is supported.])
|
||||
fi
|
||||
fi
|
||||
|
||||
AH_BOTTOM([
|
||||
#ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE
|
||||
#ifdef LIBFFI_ASM
|
||||
#define FFI_HIDDEN(name) .hidden name
|
||||
#else
|
||||
#define FFI_HIDDEN __attribute__ ((visibility ("hidden")))
|
||||
#endif
|
||||
#else
|
||||
#ifdef LIBFFI_ASM
|
||||
#define FFI_HIDDEN(name)
|
||||
#else
|
||||
#define FFI_HIDDEN
|
||||
#endif
|
||||
#endif
|
||||
])
|
||||
|
||||
AC_SUBST(TARGET)
|
||||
AC_SUBST(TARGETDIR)
|
||||
|
||||
AC_SUBST(SHELL)
|
||||
|
||||
AC_ARG_ENABLE(debug,
|
||||
[ --enable-debug debugging mode],
|
||||
if test "$enable_debug" = "yes"; then
|
||||
AC_DEFINE(FFI_DEBUG, 1, [Define this if you want extra debugging.])
|
||||
fi)
|
||||
AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
|
||||
|
||||
AC_ARG_ENABLE(structs,
|
||||
[ --disable-structs omit code for struct support],
|
||||
if test "$enable_structs" = "no"; then
|
||||
AC_DEFINE(FFI_NO_STRUCTS, 1, [Define this is you do not want support for aggregate types.])
|
||||
fi)
|
||||
AM_CONDITIONAL(FFI_DEBUG, test "$enable_debug" = "yes")
|
||||
|
||||
AC_ARG_ENABLE(raw-api,
|
||||
[ --disable-raw-api make the raw api unavailable],
|
||||
if test "$enable_raw_api" = "no"; then
|
||||
AC_DEFINE(FFI_NO_RAW_API, 1, [Define this is you do not want support for the raw API.])
|
||||
fi)
|
||||
|
||||
AC_ARG_ENABLE(purify-safety,
|
||||
[ --enable-purify-safety purify-safe mode],
|
||||
if test "$enable_purify_safety" = "yes"; then
|
||||
AC_DEFINE(USING_PURIFY, 1, [Define this if you are using Purify and want to suppress spurious messages.])
|
||||
fi)
|
||||
|
||||
# These variables are only ever used when we cross-build to X86_WIN32.
|
||||
# And we only support this with GCC, so...
|
||||
if test "x$GCC" = "xyes"; then
|
||||
if test -n "$with_cross_host" &&
|
||||
test x"$with_cross_host" != x"no"; then
|
||||
toolexecdir='$(exec_prefix)/$(target_alias)'
|
||||
toolexeclibdir='$(toolexecdir)/lib'
|
||||
else
|
||||
toolexecdir='$(libdir)/gcc-lib/$(target_alias)'
|
||||
toolexeclibdir='$(libdir)'
|
||||
fi
|
||||
multi_os_directory=`$CC -print-multi-os-directory`
|
||||
case $multi_os_directory in
|
||||
.) ;; # Avoid trailing /.
|
||||
../*) toolexeclibdir=$toolexeclibdir/$multi_os_directory ;;
|
||||
esac
|
||||
AC_SUBST(toolexecdir)
|
||||
else
|
||||
toolexeclibdir='$(libdir)'
|
||||
fi
|
||||
AC_SUBST(toolexeclibdir)
|
||||
|
||||
AC_CONFIG_COMMANDS(include, [test -d include || mkdir include])
|
||||
AC_CONFIG_COMMANDS(src, [
|
||||
test -d src || mkdir src
|
||||
test -d src/$TARGETDIR || mkdir src/$TARGETDIR
|
||||
], [TARGETDIR="$TARGETDIR"])
|
||||
|
||||
AC_CONFIG_LINKS(include/ffitarget.h:src/$TARGETDIR/ffitarget.h)
|
||||
|
||||
AC_CONFIG_FILES(include/Makefile include/ffi.h Makefile testsuite/Makefile man/Makefile libffi.pc)
|
||||
|
||||
AC_OUTPUT
|
||||
@@ -1,4 +0,0 @@
|
||||
@set UPDATED 16 March 2013
|
||||
@set UPDATED-MONTH March 2013
|
||||
@set EDITION 3.0.13
|
||||
@set VERSION 3.0.13
|
||||
@@ -1,4 +0,0 @@
|
||||
@set UPDATED 16 March 2013
|
||||
@set UPDATED-MONTH March 2013
|
||||
@set EDITION 3.0.13
|
||||
@set VERSION 3.0.13
|
||||
@@ -1,160 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import subprocess
|
||||
import re
|
||||
import os
|
||||
import errno
|
||||
import collections
|
||||
import sys
|
||||
|
||||
class Platform(object):
|
||||
pass
|
||||
|
||||
sdk_re = re.compile(r'.*-sdk ([a-zA-Z0-9.]*)')
|
||||
|
||||
def sdkinfo(sdkname):
|
||||
ret = {}
|
||||
for line in subprocess.Popen(['xcodebuild', '-sdk', sdkname, '-version'], stdout=subprocess.PIPE).stdout:
|
||||
kv = line.strip().split(': ', 1)
|
||||
if len(kv) == 2:
|
||||
k,v = kv
|
||||
ret[k] = v
|
||||
return ret
|
||||
|
||||
sim_sdk_info = sdkinfo('iphonesimulator')
|
||||
device_sdk_info = sdkinfo('iphoneos')
|
||||
|
||||
def latest_sdks():
|
||||
latest_sim = None
|
||||
latest_device = None
|
||||
for line in subprocess.Popen(['xcodebuild', '-showsdks'], stdout=subprocess.PIPE).stdout:
|
||||
match = sdk_re.match(line)
|
||||
if match:
|
||||
if 'Simulator' in line:
|
||||
latest_sim = match.group(1)
|
||||
elif 'iOS' in line:
|
||||
latest_device = match.group(1)
|
||||
|
||||
return latest_sim, latest_device
|
||||
|
||||
sim_sdk, device_sdk = latest_sdks()
|
||||
|
||||
class simulator_platform(Platform):
|
||||
sdk='iphonesimulator'
|
||||
arch = 'i386'
|
||||
name = 'simulator'
|
||||
triple = 'i386-apple-darwin10'
|
||||
sdkroot = sim_sdk_info['Path']
|
||||
|
||||
prefix = "#if !defined(__arm__) && defined(__i386__)\n\n"
|
||||
suffix = "\n\n#endif"
|
||||
|
||||
class device_platform(Platform):
|
||||
sdk='iphoneos'
|
||||
name = 'ios'
|
||||
arch = 'armv7'
|
||||
triple = 'arm-apple-darwin10'
|
||||
sdkroot = device_sdk_info['Path']
|
||||
|
||||
prefix = "#ifdef __arm__\n\n"
|
||||
suffix = "\n\n#endif"
|
||||
|
||||
|
||||
def move_file(src_dir, dst_dir, filename, file_suffix=None, prefix='', suffix=''):
|
||||
if not os.path.exists(dst_dir):
|
||||
os.makedirs(dst_dir)
|
||||
|
||||
out_filename = filename
|
||||
|
||||
if file_suffix:
|
||||
split_name = os.path.splitext(filename)
|
||||
out_filename = "%s_%s%s" % (split_name[0], file_suffix, split_name[1])
|
||||
|
||||
with open(os.path.join(src_dir, filename)) as in_file:
|
||||
with open(os.path.join(dst_dir, out_filename), 'w') as out_file:
|
||||
if prefix:
|
||||
out_file.write(prefix)
|
||||
|
||||
out_file.write(in_file.read())
|
||||
|
||||
if suffix:
|
||||
out_file.write(suffix)
|
||||
|
||||
headers_seen = collections.defaultdict(set)
|
||||
|
||||
def move_source_tree(src_dir, dest_dir, dest_include_dir, arch=None, prefix=None, suffix=None):
|
||||
for root, dirs, files in os.walk(src_dir, followlinks=True):
|
||||
relroot = os.path.relpath(root,src_dir)
|
||||
|
||||
def move_dir(arch, prefix='', suffix='', files=[]):
|
||||
for file in files:
|
||||
file_suffix = None
|
||||
if file.endswith('.h'):
|
||||
if dest_include_dir:
|
||||
file_suffix = arch
|
||||
if arch:
|
||||
headers_seen[file].add(arch)
|
||||
move_file(root, dest_include_dir, file, arch, prefix=prefix, suffix=suffix)
|
||||
|
||||
elif dest_dir:
|
||||
outroot = os.path.join(dest_dir, relroot)
|
||||
move_file(root, outroot, file, prefix=prefix, suffix=suffix)
|
||||
|
||||
if relroot == '.':
|
||||
move_dir(arch=arch,
|
||||
files=files,
|
||||
prefix=prefix,
|
||||
suffix=suffix)
|
||||
elif relroot == 'arm':
|
||||
move_dir(arch='arm',
|
||||
prefix="#ifdef __arm__\n\n",
|
||||
suffix="\n\n#endif",
|
||||
files=files)
|
||||
elif relroot == 'x86':
|
||||
move_dir(arch='i386',
|
||||
prefix="#if !defined(__arm__) && defined(__i386__)\n\n",
|
||||
suffix="\n\n#endif",
|
||||
files=files)
|
||||
|
||||
def build_target(platform):
|
||||
def xcrun_cmd(cmd):
|
||||
return subprocess.check_output(['xcrun', '-sdk', platform.sdkroot, '-find', cmd]).strip()
|
||||
|
||||
build_dir = 'build_' + platform.name
|
||||
if not os.path.exists(build_dir):
|
||||
os.makedirs(build_dir)
|
||||
env = dict(CC=xcrun_cmd('clang'),
|
||||
LD=xcrun_cmd('ld'),
|
||||
CFLAGS='-arch %s -isysroot %s -miphoneos-version-min=4.0' % (platform.arch, platform.sdkroot))
|
||||
working_dir=os.getcwd()
|
||||
try:
|
||||
os.chdir(build_dir)
|
||||
subprocess.check_call(['../configure', '-host', platform.triple], env=env)
|
||||
move_source_tree('.', None, '../ios/include',
|
||||
arch=platform.arch,
|
||||
prefix=platform.prefix,
|
||||
suffix=platform.suffix)
|
||||
move_source_tree('./include', None, '../ios/include',
|
||||
arch=platform.arch,
|
||||
prefix=platform.prefix,
|
||||
suffix=platform.suffix)
|
||||
finally:
|
||||
os.chdir(working_dir)
|
||||
|
||||
for header_name, archs in headers_seen.iteritems():
|
||||
basename, suffix = os.path.splitext(header_name)
|
||||
|
||||
def main():
|
||||
move_source_tree('src', 'ios/src', 'ios/include')
|
||||
move_source_tree('include', None, 'ios/include')
|
||||
build_target(simulator_platform)
|
||||
build_target(device_platform)
|
||||
|
||||
for header_name, archs in headers_seen.iteritems():
|
||||
basename, suffix = os.path.splitext(header_name)
|
||||
with open(os.path.join('ios/include', header_name), 'w') as header:
|
||||
for arch in archs:
|
||||
header.write('#include <%s_%s%s>\n' % (basename, arch, suffix))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -1,153 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
import subprocess
|
||||
import re
|
||||
import os
|
||||
import errno
|
||||
import collections
|
||||
import sys
|
||||
|
||||
class Platform(object):
|
||||
pass
|
||||
|
||||
sdk_re = re.compile(r'.*-sdk ([a-zA-Z0-9.]*)')
|
||||
|
||||
def sdkinfo(sdkname):
|
||||
ret = {}
|
||||
for line in subprocess.Popen(['xcodebuild', '-sdk', sdkname, '-version'], stdout=subprocess.PIPE).stdout:
|
||||
kv = line.strip().split(': ', 1)
|
||||
if len(kv) == 2:
|
||||
k,v = kv
|
||||
ret[k] = v
|
||||
return ret
|
||||
|
||||
desktop_sdk_info = sdkinfo('macosx')
|
||||
|
||||
def latest_sdks():
|
||||
latest_desktop = None
|
||||
for line in subprocess.Popen(['xcodebuild', '-showsdks'], stdout=subprocess.PIPE).stdout:
|
||||
match = sdk_re.match(line)
|
||||
if match:
|
||||
if 'OS X' in line:
|
||||
latest_desktop = match.group(1)
|
||||
|
||||
return latest_desktop
|
||||
|
||||
desktop_sdk = latest_sdks()
|
||||
|
||||
class desktop_platform_32(Platform):
|
||||
sdk='macosx'
|
||||
arch = 'i386'
|
||||
name = 'mac32'
|
||||
triple = 'i386-apple-darwin10'
|
||||
sdkroot = desktop_sdk_info['Path']
|
||||
|
||||
prefix = "#if defined(__i386__) && !defined(__x86_64__)\n\n"
|
||||
suffix = "\n\n#endif"
|
||||
|
||||
class desktop_platform_64(Platform):
|
||||
sdk='macosx'
|
||||
arch = 'x86_64'
|
||||
name = 'mac'
|
||||
triple = 'x86_64-apple-darwin10'
|
||||
sdkroot = desktop_sdk_info['Path']
|
||||
|
||||
prefix = "#if !defined(__i386__) && defined(__x86_64__)\n\n"
|
||||
suffix = "\n\n#endif"
|
||||
|
||||
def move_file(src_dir, dst_dir, filename, file_suffix=None, prefix='', suffix=''):
|
||||
if not os.path.exists(dst_dir):
|
||||
os.makedirs(dst_dir)
|
||||
|
||||
out_filename = filename
|
||||
|
||||
if file_suffix:
|
||||
split_name = os.path.splitext(filename)
|
||||
out_filename = "%s_%s%s" % (split_name[0], file_suffix, split_name[1])
|
||||
|
||||
with open(os.path.join(src_dir, filename)) as in_file:
|
||||
with open(os.path.join(dst_dir, out_filename), 'w') as out_file:
|
||||
if prefix:
|
||||
out_file.write(prefix)
|
||||
|
||||
out_file.write(in_file.read())
|
||||
|
||||
if suffix:
|
||||
out_file.write(suffix)
|
||||
|
||||
headers_seen = collections.defaultdict(set)
|
||||
|
||||
def move_source_tree(src_dir, dest_dir, dest_include_dir, arch=None, prefix=None, suffix=None):
|
||||
for root, dirs, files in os.walk(src_dir, followlinks=True):
|
||||
relroot = os.path.relpath(root,src_dir)
|
||||
|
||||
def move_dir(arch, prefix='', suffix='', files=[]):
|
||||
for file in files:
|
||||
file_suffix = None
|
||||
if file.endswith('.h'):
|
||||
if dest_include_dir:
|
||||
file_suffix = arch
|
||||
if arch:
|
||||
headers_seen[file].add(arch)
|
||||
move_file(root, dest_include_dir, file, arch, prefix=prefix, suffix=suffix)
|
||||
|
||||
elif dest_dir:
|
||||
outroot = os.path.join(dest_dir, relroot)
|
||||
move_file(root, outroot, file, prefix=prefix, suffix=suffix)
|
||||
|
||||
if relroot == '.':
|
||||
move_dir(arch=arch,
|
||||
files=files,
|
||||
prefix=prefix,
|
||||
suffix=suffix)
|
||||
elif relroot == 'x86':
|
||||
move_dir(arch='i386',
|
||||
prefix="#if defined(__i386__) && !defined(__x86_64__)\n\n",
|
||||
suffix="\n\n#endif",
|
||||
files=files)
|
||||
move_dir(arch='x86_64',
|
||||
prefix="#if !defined(__i386__) && defined(__x86_64__)\n\n",
|
||||
suffix="\n\n#endif",
|
||||
files=files)
|
||||
|
||||
def build_target(platform):
|
||||
def xcrun_cmd(cmd):
|
||||
return subprocess.check_output(['xcrun', '-sdk', platform.sdkroot, '-find', cmd]).strip()
|
||||
|
||||
build_dir = 'build_' + platform.name
|
||||
if not os.path.exists(build_dir):
|
||||
os.makedirs(build_dir)
|
||||
env = dict(CC=xcrun_cmd('clang'),
|
||||
LD=xcrun_cmd('ld'),
|
||||
CFLAGS='-arch %s -isysroot %s -mmacosx-version-min=10.6' % (platform.arch, platform.sdkroot))
|
||||
working_dir=os.getcwd()
|
||||
try:
|
||||
os.chdir(build_dir)
|
||||
subprocess.check_call(['../configure', '-host', platform.triple], env=env)
|
||||
move_source_tree('.', None, '../osx/include',
|
||||
arch=platform.arch,
|
||||
prefix=platform.prefix,
|
||||
suffix=platform.suffix)
|
||||
move_source_tree('./include', None, '../osx/include',
|
||||
arch=platform.arch,
|
||||
prefix=platform.prefix,
|
||||
suffix=platform.suffix)
|
||||
finally:
|
||||
os.chdir(working_dir)
|
||||
|
||||
for header_name, archs in headers_seen.iteritems():
|
||||
basename, suffix = os.path.splitext(header_name)
|
||||
|
||||
def main():
|
||||
move_source_tree('src', 'osx/src', 'osx/include')
|
||||
move_source_tree('include', None, 'osx/include')
|
||||
build_target(desktop_platform_32)
|
||||
build_target(desktop_platform_64)
|
||||
|
||||
for header_name, archs in headers_seen.iteritems():
|
||||
basename, suffix = os.path.splitext(header_name)
|
||||
with open(os.path.join('osx/include', header_name), 'w') as header:
|
||||
for arch in archs:
|
||||
header.write('#include <%s_%s%s>\n' % (basename, arch, suffix))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
-520
@@ -1,520 +0,0 @@
|
||||
#!/bin/sh
|
||||
# install - install a program, script, or datafile
|
||||
|
||||
scriptversion=2009-04-28.21; # UTC
|
||||
|
||||
# This originates from X11R5 (mit/util/scripts/install.sh), which was
|
||||
# later released in X11R6 (xc/config/util/install.sh) with the
|
||||
# following copyright and license.
|
||||
#
|
||||
# Copyright (C) 1994 X Consortium
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to
|
||||
# deal in the Software without restriction, including without limitation the
|
||||
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
# sell copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
|
||||
# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
#
|
||||
# Except as contained in this notice, the name of the X Consortium shall not
|
||||
# be used in advertising or otherwise to promote the sale, use or other deal-
|
||||
# ings in this Software without prior written authorization from the X Consor-
|
||||
# tium.
|
||||
#
|
||||
#
|
||||
# FSF changes to this file are in the public domain.
|
||||
#
|
||||
# Calling this script install-sh is preferred over install.sh, to prevent
|
||||
# `make' implicit rules from creating a file called install from it
|
||||
# when there is no Makefile.
|
||||
#
|
||||
# This script is compatible with the BSD install script, but was written
|
||||
# from scratch.
|
||||
|
||||
nl='
|
||||
'
|
||||
IFS=" "" $nl"
|
||||
|
||||
# set DOITPROG to echo to test this script
|
||||
|
||||
# Don't use :- since 4.3BSD and earlier shells don't like it.
|
||||
doit=${DOITPROG-}
|
||||
if test -z "$doit"; then
|
||||
doit_exec=exec
|
||||
else
|
||||
doit_exec=$doit
|
||||
fi
|
||||
|
||||
# Put in absolute file names if you don't have them in your path;
|
||||
# or use environment vars.
|
||||
|
||||
chgrpprog=${CHGRPPROG-chgrp}
|
||||
chmodprog=${CHMODPROG-chmod}
|
||||
chownprog=${CHOWNPROG-chown}
|
||||
cmpprog=${CMPPROG-cmp}
|
||||
cpprog=${CPPROG-cp}
|
||||
mkdirprog=${MKDIRPROG-mkdir}
|
||||
mvprog=${MVPROG-mv}
|
||||
rmprog=${RMPROG-rm}
|
||||
stripprog=${STRIPPROG-strip}
|
||||
|
||||
posix_glob='?'
|
||||
initialize_posix_glob='
|
||||
test "$posix_glob" != "?" || {
|
||||
if (set -f) 2>/dev/null; then
|
||||
posix_glob=
|
||||
else
|
||||
posix_glob=:
|
||||
fi
|
||||
}
|
||||
'
|
||||
|
||||
posix_mkdir=
|
||||
|
||||
# Desired mode of installed file.
|
||||
mode=0755
|
||||
|
||||
chgrpcmd=
|
||||
chmodcmd=$chmodprog
|
||||
chowncmd=
|
||||
mvcmd=$mvprog
|
||||
rmcmd="$rmprog -f"
|
||||
stripcmd=
|
||||
|
||||
src=
|
||||
dst=
|
||||
dir_arg=
|
||||
dst_arg=
|
||||
|
||||
copy_on_change=false
|
||||
no_target_directory=
|
||||
|
||||
usage="\
|
||||
Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
|
||||
or: $0 [OPTION]... SRCFILES... DIRECTORY
|
||||
or: $0 [OPTION]... -t DIRECTORY SRCFILES...
|
||||
or: $0 [OPTION]... -d DIRECTORIES...
|
||||
|
||||
In the 1st form, copy SRCFILE to DSTFILE.
|
||||
In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
|
||||
In the 4th, create DIRECTORIES.
|
||||
|
||||
Options:
|
||||
--help display this help and exit.
|
||||
--version display version info and exit.
|
||||
|
||||
-c (ignored)
|
||||
-C install only if different (preserve the last data modification time)
|
||||
-d create directories instead of installing files.
|
||||
-g GROUP $chgrpprog installed files to GROUP.
|
||||
-m MODE $chmodprog installed files to MODE.
|
||||
-o USER $chownprog installed files to USER.
|
||||
-s $stripprog installed files.
|
||||
-t DIRECTORY install into DIRECTORY.
|
||||
-T report an error if DSTFILE is a directory.
|
||||
|
||||
Environment variables override the default commands:
|
||||
CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
|
||||
RMPROG STRIPPROG
|
||||
"
|
||||
|
||||
while test $# -ne 0; do
|
||||
case $1 in
|
||||
-c) ;;
|
||||
|
||||
-C) copy_on_change=true;;
|
||||
|
||||
-d) dir_arg=true;;
|
||||
|
||||
-g) chgrpcmd="$chgrpprog $2"
|
||||
shift;;
|
||||
|
||||
--help) echo "$usage"; exit $?;;
|
||||
|
||||
-m) mode=$2
|
||||
case $mode in
|
||||
*' '* | *' '* | *'
|
||||
'* | *'*'* | *'?'* | *'['*)
|
||||
echo "$0: invalid mode: $mode" >&2
|
||||
exit 1;;
|
||||
esac
|
||||
shift;;
|
||||
|
||||
-o) chowncmd="$chownprog $2"
|
||||
shift;;
|
||||
|
||||
-s) stripcmd=$stripprog;;
|
||||
|
||||
-t) dst_arg=$2
|
||||
shift;;
|
||||
|
||||
-T) no_target_directory=true;;
|
||||
|
||||
--version) echo "$0 $scriptversion"; exit $?;;
|
||||
|
||||
--) shift
|
||||
break;;
|
||||
|
||||
-*) echo "$0: invalid option: $1" >&2
|
||||
exit 1;;
|
||||
|
||||
*) break;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
|
||||
# When -d is used, all remaining arguments are directories to create.
|
||||
# When -t is used, the destination is already specified.
|
||||
# Otherwise, the last argument is the destination. Remove it from $@.
|
||||
for arg
|
||||
do
|
||||
if test -n "$dst_arg"; then
|
||||
# $@ is not empty: it contains at least $arg.
|
||||
set fnord "$@" "$dst_arg"
|
||||
shift # fnord
|
||||
fi
|
||||
shift # arg
|
||||
dst_arg=$arg
|
||||
done
|
||||
fi
|
||||
|
||||
if test $# -eq 0; then
|
||||
if test -z "$dir_arg"; then
|
||||
echo "$0: no input file specified." >&2
|
||||
exit 1
|
||||
fi
|
||||
# It's OK to call `install-sh -d' without argument.
|
||||
# This can happen when creating conditional directories.
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if test -z "$dir_arg"; then
|
||||
trap '(exit $?); exit' 1 2 13 15
|
||||
|
||||
# Set umask so as not to create temps with too-generous modes.
|
||||
# However, 'strip' requires both read and write access to temps.
|
||||
case $mode in
|
||||
# Optimize common cases.
|
||||
*644) cp_umask=133;;
|
||||
*755) cp_umask=22;;
|
||||
|
||||
*[0-7])
|
||||
if test -z "$stripcmd"; then
|
||||
u_plus_rw=
|
||||
else
|
||||
u_plus_rw='% 200'
|
||||
fi
|
||||
cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
|
||||
*)
|
||||
if test -z "$stripcmd"; then
|
||||
u_plus_rw=
|
||||
else
|
||||
u_plus_rw=,u+rw
|
||||
fi
|
||||
cp_umask=$mode$u_plus_rw;;
|
||||
esac
|
||||
fi
|
||||
|
||||
for src
|
||||
do
|
||||
# Protect names starting with `-'.
|
||||
case $src in
|
||||
-*) src=./$src;;
|
||||
esac
|
||||
|
||||
if test -n "$dir_arg"; then
|
||||
dst=$src
|
||||
dstdir=$dst
|
||||
test -d "$dstdir"
|
||||
dstdir_status=$?
|
||||
else
|
||||
|
||||
# Waiting for this to be detected by the "$cpprog $src $dsttmp" command
|
||||
# might cause directories to be created, which would be especially bad
|
||||
# if $src (and thus $dsttmp) contains '*'.
|
||||
if test ! -f "$src" && test ! -d "$src"; then
|
||||
echo "$0: $src does not exist." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if test -z "$dst_arg"; then
|
||||
echo "$0: no destination specified." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
dst=$dst_arg
|
||||
# Protect names starting with `-'.
|
||||
case $dst in
|
||||
-*) dst=./$dst;;
|
||||
esac
|
||||
|
||||
# If destination is a directory, append the input filename; won't work
|
||||
# if double slashes aren't ignored.
|
||||
if test -d "$dst"; then
|
||||
if test -n "$no_target_directory"; then
|
||||
echo "$0: $dst_arg: Is a directory" >&2
|
||||
exit 1
|
||||
fi
|
||||
dstdir=$dst
|
||||
dst=$dstdir/`basename "$src"`
|
||||
dstdir_status=0
|
||||
else
|
||||
# Prefer dirname, but fall back on a substitute if dirname fails.
|
||||
dstdir=`
|
||||
(dirname "$dst") 2>/dev/null ||
|
||||
expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
|
||||
X"$dst" : 'X\(//\)[^/]' \| \
|
||||
X"$dst" : 'X\(//\)$' \| \
|
||||
X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
|
||||
echo X"$dst" |
|
||||
sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
|
||||
s//\1/
|
||||
q
|
||||
}
|
||||
/^X\(\/\/\)[^/].*/{
|
||||
s//\1/
|
||||
q
|
||||
}
|
||||
/^X\(\/\/\)$/{
|
||||
s//\1/
|
||||
q
|
||||
}
|
||||
/^X\(\/\).*/{
|
||||
s//\1/
|
||||
q
|
||||
}
|
||||
s/.*/./; q'
|
||||
`
|
||||
|
||||
test -d "$dstdir"
|
||||
dstdir_status=$?
|
||||
fi
|
||||
fi
|
||||
|
||||
obsolete_mkdir_used=false
|
||||
|
||||
if test $dstdir_status != 0; then
|
||||
case $posix_mkdir in
|
||||
'')
|
||||
# Create intermediate dirs using mode 755 as modified by the umask.
|
||||
# This is like FreeBSD 'install' as of 1997-10-28.
|
||||
umask=`umask`
|
||||
case $stripcmd.$umask in
|
||||
# Optimize common cases.
|
||||
*[2367][2367]) mkdir_umask=$umask;;
|
||||
.*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
|
||||
|
||||
*[0-7])
|
||||
mkdir_umask=`expr $umask + 22 \
|
||||
- $umask % 100 % 40 + $umask % 20 \
|
||||
- $umask % 10 % 4 + $umask % 2
|
||||
`;;
|
||||
*) mkdir_umask=$umask,go-w;;
|
||||
esac
|
||||
|
||||
# With -d, create the new directory with the user-specified mode.
|
||||
# Otherwise, rely on $mkdir_umask.
|
||||
if test -n "$dir_arg"; then
|
||||
mkdir_mode=-m$mode
|
||||
else
|
||||
mkdir_mode=
|
||||
fi
|
||||
|
||||
posix_mkdir=false
|
||||
case $umask in
|
||||
*[123567][0-7][0-7])
|
||||
# POSIX mkdir -p sets u+wx bits regardless of umask, which
|
||||
# is incompatible with FreeBSD 'install' when (umask & 300) != 0.
|
||||
;;
|
||||
*)
|
||||
tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
|
||||
trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
|
||||
|
||||
if (umask $mkdir_umask &&
|
||||
exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
|
||||
then
|
||||
if test -z "$dir_arg" || {
|
||||
# Check for POSIX incompatibilities with -m.
|
||||
# HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
|
||||
# other-writeable bit of parent directory when it shouldn't.
|
||||
# FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
|
||||
ls_ld_tmpdir=`ls -ld "$tmpdir"`
|
||||
case $ls_ld_tmpdir in
|
||||
d????-?r-*) different_mode=700;;
|
||||
d????-?--*) different_mode=755;;
|
||||
*) false;;
|
||||
esac &&
|
||||
$mkdirprog -m$different_mode -p -- "$tmpdir" && {
|
||||
ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
|
||||
test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
|
||||
}
|
||||
}
|
||||
then posix_mkdir=:
|
||||
fi
|
||||
rmdir "$tmpdir/d" "$tmpdir"
|
||||
else
|
||||
# Remove any dirs left behind by ancient mkdir implementations.
|
||||
rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
|
||||
fi
|
||||
trap '' 0;;
|
||||
esac;;
|
||||
esac
|
||||
|
||||
if
|
||||
$posix_mkdir && (
|
||||
umask $mkdir_umask &&
|
||||
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
|
||||
)
|
||||
then :
|
||||
else
|
||||
|
||||
# The umask is ridiculous, or mkdir does not conform to POSIX,
|
||||
# or it failed possibly due to a race condition. Create the
|
||||
# directory the slow way, step by step, checking for races as we go.
|
||||
|
||||
case $dstdir in
|
||||
/*) prefix='/';;
|
||||
-*) prefix='./';;
|
||||
*) prefix='';;
|
||||
esac
|
||||
|
||||
eval "$initialize_posix_glob"
|
||||
|
||||
oIFS=$IFS
|
||||
IFS=/
|
||||
$posix_glob set -f
|
||||
set fnord $dstdir
|
||||
shift
|
||||
$posix_glob set +f
|
||||
IFS=$oIFS
|
||||
|
||||
prefixes=
|
||||
|
||||
for d
|
||||
do
|
||||
test -z "$d" && continue
|
||||
|
||||
prefix=$prefix$d
|
||||
if test -d "$prefix"; then
|
||||
prefixes=
|
||||
else
|
||||
if $posix_mkdir; then
|
||||
(umask=$mkdir_umask &&
|
||||
$doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
|
||||
# Don't fail if two instances are running concurrently.
|
||||
test -d "$prefix" || exit 1
|
||||
else
|
||||
case $prefix in
|
||||
*\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
|
||||
*) qprefix=$prefix;;
|
||||
esac
|
||||
prefixes="$prefixes '$qprefix'"
|
||||
fi
|
||||
fi
|
||||
prefix=$prefix/
|
||||
done
|
||||
|
||||
if test -n "$prefixes"; then
|
||||
# Don't fail if two instances are running concurrently.
|
||||
(umask $mkdir_umask &&
|
||||
eval "\$doit_exec \$mkdirprog $prefixes") ||
|
||||
test -d "$dstdir" || exit 1
|
||||
obsolete_mkdir_used=true
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if test -n "$dir_arg"; then
|
||||
{ test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
|
||||
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
|
||||
{ test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
|
||||
test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
|
||||
else
|
||||
|
||||
# Make a couple of temp file names in the proper directory.
|
||||
dsttmp=$dstdir/_inst.$$_
|
||||
rmtmp=$dstdir/_rm.$$_
|
||||
|
||||
# Trap to clean up those temp files at exit.
|
||||
trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
|
||||
|
||||
# Copy the file name to the temp name.
|
||||
(umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
|
||||
|
||||
# and set any options; do chmod last to preserve setuid bits.
|
||||
#
|
||||
# If any of these fail, we abort the whole thing. If we want to
|
||||
# ignore errors from any of these, just make sure not to ignore
|
||||
# errors from the above "$doit $cpprog $src $dsttmp" command.
|
||||
#
|
||||
{ test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
|
||||
{ test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
|
||||
{ test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
|
||||
{ test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
|
||||
|
||||
# If -C, don't bother to copy if it wouldn't change the file.
|
||||
if $copy_on_change &&
|
||||
old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` &&
|
||||
new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` &&
|
||||
|
||||
eval "$initialize_posix_glob" &&
|
||||
$posix_glob set -f &&
|
||||
set X $old && old=:$2:$4:$5:$6 &&
|
||||
set X $new && new=:$2:$4:$5:$6 &&
|
||||
$posix_glob set +f &&
|
||||
|
||||
test "$old" = "$new" &&
|
||||
$cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
|
||||
then
|
||||
rm -f "$dsttmp"
|
||||
else
|
||||
# Rename the file to the real destination.
|
||||
$doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
|
||||
|
||||
# The rename failed, perhaps because mv can't rename something else
|
||||
# to itself, or perhaps because mv is so ancient that it does not
|
||||
# support -f.
|
||||
{
|
||||
# Now remove or move aside any old file at destination location.
|
||||
# We try this two ways since rm can't unlink itself on some
|
||||
# systems and the destination file might be busy for other
|
||||
# reasons. In this case, the final cleanup might fail but the new
|
||||
# file should still install successfully.
|
||||
{
|
||||
test ! -f "$dst" ||
|
||||
$doit $rmcmd -f "$dst" 2>/dev/null ||
|
||||
{ $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
|
||||
{ $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
|
||||
} ||
|
||||
{ echo "$0: cannot unlink or rename $dst" >&2
|
||||
(exit 1); exit 1
|
||||
}
|
||||
} &&
|
||||
|
||||
# Now rename the file to the real destination.
|
||||
$doit $mvcmd "$dsttmp" "$dst"
|
||||
}
|
||||
fi || exit 1
|
||||
|
||||
trap '' 0
|
||||
fi
|
||||
done
|
||||
|
||||
# Local variables:
|
||||
# eval: (add-hook 'write-file-hooks 'time-stamp)
|
||||
# time-stamp-start: "scriptversion="
|
||||
# time-stamp-format: "%:y-%02m-%02d.%02H"
|
||||
# time-stamp-time-zone: "UTC"
|
||||
# time-stamp-end: "; # UTC"
|
||||
# End:
|
||||
Arquivo executável
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" output="build.eclipse/test-classes" path="test"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
|
||||
<classpathentry kind="output" path="build.eclipse/classes"/>
|
||||
</classpath>
|
||||
Arquivo executável
+17
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>jna</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,62 @@
|
||||
#Wed Aug 29 20:43:29 EDT 2007
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.5
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.deprecation=warning
|
||||
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
|
||||
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
|
||||
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
|
||||
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
|
||||
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
|
||||
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
|
||||
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
|
||||
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.nullReference=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
|
||||
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.rawTypeReference=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
|
||||
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedImport=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
|
||||
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.5
|
||||
@@ -0,0 +1,3 @@
|
||||
#Tue Mar 27 21:18:08 EDT 2007
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
|
||||
Arquivo executável
+504
@@ -0,0 +1,504 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 2.1, February 1999
|
||||
|
||||
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
[This is the first released version of the Lesser GPL. It also counts
|
||||
as the successor of the GNU Library Public License, version 2, hence
|
||||
the version number 2.1.]
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
Licenses are intended to guarantee your freedom to share and change
|
||||
free software--to make sure the software is free for all its users.
|
||||
|
||||
This license, the Lesser General Public License, applies to some
|
||||
specially designated software packages--typically libraries--of the
|
||||
Free Software Foundation and other authors who decide to use it. You
|
||||
can use it too, but we suggest you first think carefully about whether
|
||||
this license or the ordinary General Public License is the better
|
||||
strategy to use in any particular case, based on the explanations below.
|
||||
|
||||
When we speak of free software, we are referring to freedom of use,
|
||||
not price. Our General Public Licenses are designed to make sure that
|
||||
you have the freedom to distribute copies of free software (and charge
|
||||
for this service if you wish); that you receive source code or can get
|
||||
it if you want it; that you can change the software and use pieces of
|
||||
it in new free programs; and that you are informed that you can do
|
||||
these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
distributors to deny you these rights or to ask you to surrender these
|
||||
rights. These restrictions translate to certain responsibilities for
|
||||
you if you distribute copies of the library or if you modify it.
|
||||
|
||||
For example, if you distribute copies of the library, whether gratis
|
||||
or for a fee, you must give the recipients all the rights that we gave
|
||||
you. You must make sure that they, too, receive or can get the source
|
||||
code. If you link other code with the library, you must provide
|
||||
complete object files to the recipients, so that they can relink them
|
||||
with the library after making changes to the library and recompiling
|
||||
it. And you must show them these terms so they know their rights.
|
||||
|
||||
We protect your rights with a two-step method: (1) we copyright the
|
||||
library, and (2) we offer you this license, which gives you legal
|
||||
permission to copy, distribute and/or modify the library.
|
||||
|
||||
To protect each distributor, we want to make it very clear that
|
||||
there is no warranty for the free library. Also, if the library is
|
||||
modified by someone else and passed on, the recipients should know
|
||||
that what they have is not the original version, so that the original
|
||||
author's reputation will not be affected by problems that might be
|
||||
introduced by others.
|
||||
|
||||
Finally, software patents pose a constant threat to the existence of
|
||||
any free program. We wish to make sure that a company cannot
|
||||
effectively restrict the users of a free program by obtaining a
|
||||
restrictive license from a patent holder. Therefore, we insist that
|
||||
any patent license obtained for a version of the library must be
|
||||
consistent with the full freedom of use specified in this license.
|
||||
|
||||
Most GNU software, including some libraries, is covered by the
|
||||
ordinary GNU General Public License. This license, the GNU Lesser
|
||||
General Public License, applies to certain designated libraries, and
|
||||
is quite different from the ordinary General Public License. We use
|
||||
this license for certain libraries in order to permit linking those
|
||||
libraries into non-free programs.
|
||||
|
||||
When a program is linked with a library, whether statically or using
|
||||
a shared library, the combination of the two is legally speaking a
|
||||
combined work, a derivative of the original library. The ordinary
|
||||
General Public License therefore permits such linking only if the
|
||||
entire combination fits its criteria of freedom. The Lesser General
|
||||
Public License permits more lax criteria for linking other code with
|
||||
the library.
|
||||
|
||||
We call this license the "Lesser" General Public License because it
|
||||
does Less to protect the user's freedom than the ordinary General
|
||||
Public License. It also provides other free software developers Less
|
||||
of an advantage over competing non-free programs. These disadvantages
|
||||
are the reason we use the ordinary General Public License for many
|
||||
libraries. However, the Lesser license provides advantages in certain
|
||||
special circumstances.
|
||||
|
||||
For example, on rare occasions, there may be a special need to
|
||||
encourage the widest possible use of a certain library, so that it becomes
|
||||
a de-facto standard. To achieve this, non-free programs must be
|
||||
allowed to use the library. A more frequent case is that a free
|
||||
library does the same job as widely used non-free libraries. In this
|
||||
case, there is little to gain by limiting the free library to free
|
||||
software only, so we use the Lesser General Public License.
|
||||
|
||||
In other cases, permission to use a particular library in non-free
|
||||
programs enables a greater number of people to use a large body of
|
||||
free software. For example, permission to use the GNU C Library in
|
||||
non-free programs enables many more people to use the whole GNU
|
||||
operating system, as well as its variant, the GNU/Linux operating
|
||||
system.
|
||||
|
||||
Although the Lesser General Public License is Less protective of the
|
||||
users' freedom, it does ensure that the user of a program that is
|
||||
linked with the Library has the freedom and the wherewithal to run
|
||||
that program using a modified version of the Library.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow. Pay close attention to the difference between a
|
||||
"work based on the library" and a "work that uses the library". The
|
||||
former contains code derived from the library, whereas the latter must
|
||||
be combined with the library in order to run.
|
||||
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License Agreement applies to any software library or other
|
||||
program which contains a notice placed by the copyright holder or
|
||||
other authorized party saying it may be distributed under the terms of
|
||||
this Lesser General Public License (also called "this License").
|
||||
Each licensee is addressed as "you".
|
||||
|
||||
A "library" means a collection of software functions and/or data
|
||||
prepared so as to be conveniently linked with application programs
|
||||
(which use some of those functions and data) to form executables.
|
||||
|
||||
The "Library", below, refers to any such software library or work
|
||||
which has been distributed under these terms. A "work based on the
|
||||
Library" means either the Library or any derivative work under
|
||||
copyright law: that is to say, a work containing the Library or a
|
||||
portion of it, either verbatim or with modifications and/or translated
|
||||
straightforwardly into another language. (Hereinafter, translation is
|
||||
included without limitation in the term "modification".)
|
||||
|
||||
"Source code" for a work means the preferred form of the work for
|
||||
making modifications to it. For a library, complete source code means
|
||||
all the source code for all modules it contains, plus any associated
|
||||
interface definition files, plus the scripts used to control compilation
|
||||
and installation of the library.
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running a program using the Library is not restricted, and output from
|
||||
such a program is covered only if its contents constitute a work based
|
||||
on the Library (independent of the use of the Library in a tool for
|
||||
writing it). Whether that is true depends on what the Library does
|
||||
and what the program that uses the Library does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Library's
|
||||
complete source code as you receive it, in any medium, provided that
|
||||
you conspicuously and appropriately publish on each copy an
|
||||
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||
all the notices that refer to this License and to the absence of any
|
||||
warranty; and distribute a copy of this License along with the
|
||||
Library.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy,
|
||||
and you may at your option offer warranty protection in exchange for a
|
||||
fee.
|
||||
|
||||
2. You may modify your copy or copies of the Library or any portion
|
||||
of it, thus forming a work based on the Library, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) The modified work must itself be a software library.
|
||||
|
||||
b) You must cause the files modified to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
c) You must cause the whole of the work to be licensed at no
|
||||
charge to all third parties under the terms of this License.
|
||||
|
||||
d) If a facility in the modified Library refers to a function or a
|
||||
table of data to be supplied by an application program that uses
|
||||
the facility, other than as an argument passed when the facility
|
||||
is invoked, then you must make a good faith effort to ensure that,
|
||||
in the event an application does not supply such function or
|
||||
table, the facility still operates, and performs whatever part of
|
||||
its purpose remains meaningful.
|
||||
|
||||
(For example, a function in a library to compute square roots has
|
||||
a purpose that is entirely well-defined independent of the
|
||||
application. Therefore, Subsection 2d requires that any
|
||||
application-supplied function or table used by this function must
|
||||
be optional: if the application does not supply it, the square
|
||||
root function must still compute square roots.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Library,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Library, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote
|
||||
it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Library.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Library
|
||||
with the Library (or with a work based on the Library) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||
License instead of this License to a given copy of the Library. To do
|
||||
this, you must alter all the notices that refer to this License, so
|
||||
that they refer to the ordinary GNU General Public License, version 2,
|
||||
instead of to this License. (If a newer version than version 2 of the
|
||||
ordinary GNU General Public License has appeared, then you can specify
|
||||
that version instead if you wish.) Do not make any other change in
|
||||
these notices.
|
||||
|
||||
Once this change is made in a given copy, it is irreversible for
|
||||
that copy, so the ordinary GNU General Public License applies to all
|
||||
subsequent copies and derivative works made from that copy.
|
||||
|
||||
This option is useful when you wish to copy part of the code of
|
||||
the Library into a program that is not a library.
|
||||
|
||||
4. You may copy and distribute the Library (or a portion or
|
||||
derivative of it, under Section 2) in object code or executable form
|
||||
under the terms of Sections 1 and 2 above provided that you accompany
|
||||
it with the complete corresponding machine-readable source code, which
|
||||
must be distributed under the terms of Sections 1 and 2 above on a
|
||||
medium customarily used for software interchange.
|
||||
|
||||
If distribution of object code is made by offering access to copy
|
||||
from a designated place, then offering equivalent access to copy the
|
||||
source code from the same place satisfies the requirement to
|
||||
distribute the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
5. A program that contains no derivative of any portion of the
|
||||
Library, but is designed to work with the Library by being compiled or
|
||||
linked with it, is called a "work that uses the Library". Such a
|
||||
work, in isolation, is not a derivative work of the Library, and
|
||||
therefore falls outside the scope of this License.
|
||||
|
||||
However, linking a "work that uses the Library" with the Library
|
||||
creates an executable that is a derivative of the Library (because it
|
||||
contains portions of the Library), rather than a "work that uses the
|
||||
library". The executable is therefore covered by this License.
|
||||
Section 6 states terms for distribution of such executables.
|
||||
|
||||
When a "work that uses the Library" uses material from a header file
|
||||
that is part of the Library, the object code for the work may be a
|
||||
derivative work of the Library even though the source code is not.
|
||||
Whether this is true is especially significant if the work can be
|
||||
linked without the Library, or if the work is itself a library. The
|
||||
threshold for this to be true is not precisely defined by law.
|
||||
|
||||
If such an object file uses only numerical parameters, data
|
||||
structure layouts and accessors, and small macros and small inline
|
||||
functions (ten lines or less in length), then the use of the object
|
||||
file is unrestricted, regardless of whether it is legally a derivative
|
||||
work. (Executables containing this object code plus portions of the
|
||||
Library will still fall under Section 6.)
|
||||
|
||||
Otherwise, if the work is a derivative of the Library, you may
|
||||
distribute the object code for the work under the terms of Section 6.
|
||||
Any executables containing that work also fall under Section 6,
|
||||
whether or not they are linked directly with the Library itself.
|
||||
|
||||
6. As an exception to the Sections above, you may also combine or
|
||||
link a "work that uses the Library" with the Library to produce a
|
||||
work containing portions of the Library, and distribute that work
|
||||
under terms of your choice, provided that the terms permit
|
||||
modification of the work for the customer's own use and reverse
|
||||
engineering for debugging such modifications.
|
||||
|
||||
You must give prominent notice with each copy of the work that the
|
||||
Library is used in it and that the Library and its use are covered by
|
||||
this License. You must supply a copy of this License. If the work
|
||||
during execution displays copyright notices, you must include the
|
||||
copyright notice for the Library among them, as well as a reference
|
||||
directing the user to the copy of this License. Also, you must do one
|
||||
of these things:
|
||||
|
||||
a) Accompany the work with the complete corresponding
|
||||
machine-readable source code for the Library including whatever
|
||||
changes were used in the work (which must be distributed under
|
||||
Sections 1 and 2 above); and, if the work is an executable linked
|
||||
with the Library, with the complete machine-readable "work that
|
||||
uses the Library", as object code and/or source code, so that the
|
||||
user can modify the Library and then relink to produce a modified
|
||||
executable containing the modified Library. (It is understood
|
||||
that the user who changes the contents of definitions files in the
|
||||
Library will not necessarily be able to recompile the application
|
||||
to use the modified definitions.)
|
||||
|
||||
b) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (1) uses at run time a
|
||||
copy of the library already present on the user's computer system,
|
||||
rather than copying library functions into the executable, and (2)
|
||||
will operate properly with a modified version of the library, if
|
||||
the user installs one, as long as the modified version is
|
||||
interface-compatible with the version that the work was made with.
|
||||
|
||||
c) Accompany the work with a written offer, valid for at
|
||||
least three years, to give the same user the materials
|
||||
specified in Subsection 6a, above, for a charge no more
|
||||
than the cost of performing this distribution.
|
||||
|
||||
d) If distribution of the work is made by offering access to copy
|
||||
from a designated place, offer equivalent access to copy the above
|
||||
specified materials from the same place.
|
||||
|
||||
e) Verify that the user has already received a copy of these
|
||||
materials or that you have already sent this user a copy.
|
||||
|
||||
For an executable, the required form of the "work that uses the
|
||||
Library" must include any data and utility programs needed for
|
||||
reproducing the executable from it. However, as a special exception,
|
||||
the materials to be distributed need not include anything that is
|
||||
normally distributed (in either source or binary form) with the major
|
||||
components (compiler, kernel, and so on) of the operating system on
|
||||
which the executable runs, unless that component itself accompanies
|
||||
the executable.
|
||||
|
||||
It may happen that this requirement contradicts the license
|
||||
restrictions of other proprietary libraries that do not normally
|
||||
accompany the operating system. Such a contradiction means you cannot
|
||||
use both them and the Library together in an executable that you
|
||||
distribute.
|
||||
|
||||
7. You may place library facilities that are a work based on the
|
||||
Library side-by-side in a single library together with other library
|
||||
facilities not covered by this License, and distribute such a combined
|
||||
library, provided that the separate distribution of the work based on
|
||||
the Library and of the other library facilities is otherwise
|
||||
permitted, and provided that you do these two things:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work
|
||||
based on the Library, uncombined with any other library
|
||||
facilities. This must be distributed under the terms of the
|
||||
Sections above.
|
||||
|
||||
b) Give prominent notice with the combined library of the fact
|
||||
that part of it is a work based on the Library, and explaining
|
||||
where to find the accompanying uncombined form of the same work.
|
||||
|
||||
8. You may not copy, modify, sublicense, link with, or distribute
|
||||
the Library except as expressly provided under this License. Any
|
||||
attempt otherwise to copy, modify, sublicense, link with, or
|
||||
distribute the Library is void, and will automatically terminate your
|
||||
rights under this License. However, parties who have received copies,
|
||||
or rights, from you under this License will not have their licenses
|
||||
terminated so long as such parties remain in full compliance.
|
||||
|
||||
9. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Library or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Library (or any work based on the
|
||||
Library), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Library or works based on it.
|
||||
|
||||
10. Each time you redistribute the Library (or any work based on the
|
||||
Library), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute, link with or modify the Library
|
||||
subject to these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties with
|
||||
this License.
|
||||
|
||||
11. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Library at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Library by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Library.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under any
|
||||
particular circumstance, the balance of the section is intended to apply,
|
||||
and the section as a whole is intended to apply in other circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
12. If the distribution and/or use of the Library is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Library under this License may add
|
||||
an explicit geographical distribution limitation excluding those countries,
|
||||
so that distribution is permitted only in or among countries not thus
|
||||
excluded. In such case, this License incorporates the limitation as if
|
||||
written in the body of this License.
|
||||
|
||||
13. The Free Software Foundation may publish revised and/or new
|
||||
versions of the Lesser General Public License from time to time.
|
||||
Such new versions will be similar in spirit to the present version,
|
||||
but may differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Library
|
||||
specifies a version number of this License which applies to it and
|
||||
"any later version", you have the option of following the terms and
|
||||
conditions either of that version or of any later version published by
|
||||
the Free Software Foundation. If the Library does not specify a
|
||||
license version number, you may choose any version ever published by
|
||||
the Free Software Foundation.
|
||||
|
||||
14. If you wish to incorporate parts of the Library into other free
|
||||
programs whose distribution conditions are incompatible with these,
|
||||
write to the author to ask for permission. For software which is
|
||||
copyrighted by the Free Software Foundation, write to the Free
|
||||
Software Foundation; we sometimes make exceptions for this. Our
|
||||
decision will be guided by the two goals of preserving the free status
|
||||
of all derivatives of our free software and of promoting the sharing
|
||||
and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||
DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Libraries
|
||||
|
||||
If you develop a new library, and you want it to be of the greatest
|
||||
possible use to the public, we recommend making it free software that
|
||||
everyone can redistribute and change. You can do so by permitting
|
||||
redistribution under these terms (or, alternatively, under the terms of the
|
||||
ordinary General Public License).
|
||||
|
||||
To apply these terms, attach the following notices to the library. It is
|
||||
safest to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least the
|
||||
"copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the library's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the library, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the
|
||||
library `Frob' (a library for tweaking knobs) written by James Random Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1990
|
||||
Ty Coon, President of Vice
|
||||
|
||||
That's all there is to it!
|
||||
|
||||
|
||||
Arquivo executável
+33
@@ -0,0 +1,33 @@
|
||||
* RELATED and/or SIMILAR PROJECTS:
|
||||
* Feel free to add notes and/or descriptions here (this should probably go
|
||||
* on a wiki somewhere).
|
||||
----
|
||||
* nlink.dev.java.net:
|
||||
pros: simple definitions (same as jna)
|
||||
cons: w32 only
|
||||
* sf.net/projects/jnative:
|
||||
cons: boilerplate, manual code generation by calling setup methods
|
||||
pros: callbacks, byref args?
|
||||
* JNIWrapper: kinda like jnative (commercial), includes platform "packs"
|
||||
* coroutine for Java, like jnative (commercial)
|
||||
* jnieasy: c++ mappings (http://www.innowhere.com:8080/webapp/jsp/products/jnieasy/index.jsp?_page=products.jnieasy)
|
||||
* j2native (www.smardec.com)
|
||||
* j-interop.sf.net
|
||||
* jawinproject.sf.net (COM DLL access)
|
||||
* jacob-project.sf.net (COM DLL access)
|
||||
* nativecall.sf.net (minimal)
|
||||
* cxxwrap.sf.net
|
||||
* J/Direct (defunct)
|
||||
* NoodleGlue
|
||||
* SWIG
|
||||
* ctypes4j.sf.net
|
||||
* ctypes-java (out of date)
|
||||
* jnbridge
|
||||
* xFunction (http://excelsior-usa.com/xfunction.html, commercial, osx)
|
||||
* JACE c++ mappings
|
||||
* JAW Java API wrapper http://www.aplu.ch/home/apluhome.jsp?site=5
|
||||
|
||||
# OTHER REFERENCES
|
||||
# JNI options: http://staff.develop.com/halloway/JavaWin32.html
|
||||
# List of JNI alternatives: http://weblog.janek.org/Archive/2005/07/28/AlternativestoJavaNativeI.html
|
||||
|
||||
+277
@@ -0,0 +1,277 @@
|
||||
# DESIGN GOALS/REQUIREMENTS
|
||||
o no permanent references to java objects in native code (hard to get rid of)
|
||||
this means no java object arguments to callbacks; use some sort of integer
|
||||
key instead (hashcode?) callbacks can hold local data anyway...
|
||||
o make simplest Java usage map to most common C usage
|
||||
- additional constructs provided for less-common cases
|
||||
(WString,Structure.ByValue/ByReference)
|
||||
o structure is treated as a pointer, except within a struct
|
||||
o primitive types are passed directly
|
||||
o arrays are treated as pointers, except within a struct
|
||||
- in structure (inline; otherwise pointer-to-X should be used)
|
||||
- as function argument (auto-convert to pointer via Memory)
|
||||
o pointer to type in struct should use Pointer or ByReference
|
||||
o "free" should be invisible wherever possible
|
||||
|
||||
# FUTURE DEMOS:
|
||||
* test keyboard keys' state (needs OSX)
|
||||
* get system process information, basic process control
|
||||
* additional file utilities (meta info, free space, etc)
|
||||
* enforce window minimum/maximum size (workaround java bug)
|
||||
|
||||
# TODO
|
||||
|
||||
* fix setFieldOrder to *always* apply if used
|
||||
* cache structure information
|
||||
|
||||
* make direct calls call back *once* to Java where conversion is required,
|
||||
and process all arguments from there (instead of potentially swapping back
|
||||
and forth multipel times). This also makes it easer to perform conversions
|
||||
(no native changes required).
|
||||
|
||||
* direct/raw non-primitive array arguments (String[], Pointer[], NativeMapped[])
|
||||
|
||||
* ppc64 direct/raw failures (multiple)
|
||||
|
||||
* direct calls on ppc to varargs (callbacks) with FP args fail; avoid them for
|
||||
now
|
||||
|
||||
* combine direct and interface mapping calling code where possible
|
||||
|
||||
* make native dll extraction from jar public, to use with user dlls packaged
|
||||
in a jar
|
||||
|
||||
* Callback.PostCallWrite.write() cf PostCallRead
|
||||
|
||||
* GetPrimitiveArrayCritical: use this if flagged (by annotation? method name?)
|
||||
|
||||
* MethodArgument/ReturnMapper: per method mapping of arguments/return type.
|
||||
Can use annotations as shorthand to initialize a map, but basically set up a
|
||||
per-NativeLibrary (or per-Function?) map of methods to mappers.
|
||||
|
||||
Requires separate compilation of annotation handling.
|
||||
|
||||
* ditch type conversion context (?)
|
||||
|
||||
* packaging: 'types', 'convert/marshal' subpackages?
|
||||
note: marshal/unmarshal vs to/fromnative: to/fromnative is more
|
||||
explicit, since marshal/unmarshal doesn't indicate src/dst.
|
||||
o moving conversion contexts to subpackage cleans up top level
|
||||
substantially, but we probably don't want to move things like Structure and
|
||||
Pointer into a types subpackage (which would leave just a few top-level
|
||||
classes). Javadoc is cluttered by example classes anyway.
|
||||
|
||||
* support annotations of parameters and return values w/o breaking
|
||||
1.4 compatibility (retroweaver?), e.g.
|
||||
-- retroweaver (requires retroweaver runtime classes to provide annotation
|
||||
features) not yet worth doing
|
||||
|
||||
void my_function(@MarshalAs(off_t)long arg);
|
||||
|
||||
trading off cruft in the interface def to avoid cruft in the usage:
|
||||
|
||||
my_function(0) versus my_function(new off_t(0))
|
||||
|
||||
this only really applies to NativeLong/IntegerType types that want to use a
|
||||
primitive value instead of creating an object instance.
|
||||
|
||||
* flag string(/wstring)-returning methods which need to free their result
|
||||
to avoid leaking memory whan auto-creating strings from the result
|
||||
(since normally we don't take explicit ownership of any returned pointers)
|
||||
this is a special case for returned strings only, since other returned
|
||||
pointers are available to the user for later "freeing"
|
||||
Use a map on library creation, an iface for the library, or annotation
|
||||
NOTE: how many methods actually do this? strdup...
|
||||
Maybe make function return "Memory", which can then be converted to a
|
||||
Structure or some other type. Then memory will free itself when no longer
|
||||
referenced.
|
||||
* make Pointer free-able (system allocates memory, client frees it); actually,
|
||||
this should probably be automatic so the user doesn't have to think about it.
|
||||
Maybe a custom type representing "function-allocated-pointer" or
|
||||
"pointer-requiring-free" (which is just Memory). For now, leave it up to
|
||||
the user to manage the pointer, since they have to define the free method
|
||||
anyway. use could always put a finalizer on a PointerType-derived type.
|
||||
* universal GCC build w/cross-compile (needs cross compilers...)
|
||||
* return Pointer.SIZE/LONG_SIZE/WCHAR_SIZE in bits (for consistency with 1.5)
|
||||
Long.SIZE, Integer.SIZE, et al.
|
||||
* interface "lvalue", which can provide a pointer to itself (reference() or
|
||||
addressOf())?
|
||||
* bitfields for structs (how?)
|
||||
|
||||
|
||||
# DONE
|
||||
* check Structure "final" fields; should never write back to native memory
|
||||
* OSX ObjC access (see rococoa)
|
||||
* do Structure.write for any callback args
|
||||
* pointer.setValue(), to handle NativeMapped types and move read/writeValue
|
||||
methods out of Structure, to be used by Function w/NativeMapped[] parameter
|
||||
|
||||
* if method has "GetLastErrorException/ErrnoException" in its signature, use
|
||||
result codes + GetLastError/errno/errstr to auto-generate
|
||||
runtime exceptions? (cf P/Invoke; also useful for X11 return types)
|
||||
provide annotation/custom invocation handler/hook to examine return value and
|
||||
throw an exception if the return value indicates an error
|
||||
|
||||
o are error return values consistent (if so, a single handler works)?
|
||||
if null -> call GetLastError
|
||||
if nonzero ?
|
||||
o otherwise, need an ExceptionOnZero, ExceptionOnNonZero runtime, from which
|
||||
derive GetLastError/ErrnoExceptionOnZero/NZ
|
||||
* verify get/set methods vs read/write for performance (Pointer)?
|
||||
(see RawTest for performance comparisons)
|
||||
* Allow Buffer in Structures (and callbacks) (auto-wrap in direct byte buffer)?
|
||||
o this gets tricky when reading structs from native memory; we don't know if
|
||||
the value is already mapped to a buffer (cf CallbackReference)
|
||||
* standard types for various platforms: posix/types.h, w32 (DWORD, HANDLE)
|
||||
|
||||
* embed version in DLL ('depends'-done)/so (symlink?)
|
||||
* use libffi closure allocation/deallocation
|
||||
|
||||
* ensure Library options are passed to NativeFunctionHandler
|
||||
(needs getLibraryOptions(Class cls))
|
||||
|
||||
* handle array of Structure.ByReference as parameter/return value (cf Pointer[])
|
||||
* test performance of setByte/getByte and pass pointer field directly if it
|
||||
makes sense to do so (done, halves access time to use pointer field directly,
|
||||
slight variations on 1.4/1.5/1.6).
|
||||
* test callback arg/return value for callback type
|
||||
* structure by value in callback
|
||||
|
||||
* call native to fix up FFIType on creation (avoid multithreading problems)
|
||||
properly handle union by value (or punt; must pass union field instead)
|
||||
|
||||
* hash javah-generated headers; when changed, invalidate platform-specific
|
||||
|
||||
* add main class which spits out version information
|
||||
|
||||
* docs: split pages: FAQ
|
||||
FAQ: J2ME, new platform builds, stdcall
|
||||
|
||||
* struct by reference within structure
|
||||
* struct by value
|
||||
(how to do struct value return (vs struct pointer) (uncommon)?)
|
||||
(how to do struct value argument (vs struct pointer) (uncommon)?)
|
||||
* use appropriate size_t and off_t sizes (use long offsets everywhere in
|
||||
Pointer)
|
||||
* Callback/function pointer as return value (e.g. signal())
|
||||
* type safety between returned and passed in pointers (w32 API); advantage of
|
||||
deriving from Pointer is that type mapping can be made automatic, without an
|
||||
explicit type mapping defined.
|
||||
* catch native crash/exception/faults and re-throw as java exception
|
||||
this is mostly for debugging a new mapping to avoid crashing the VM
|
||||
could do setjmp/longjmp on *nix and catch C++ exception on w32
|
||||
* NativeMapped: provide interface to automatically convert custom Java
|
||||
type to/from native types.
|
||||
* update X11 libs for 64-bit
|
||||
* use libffi from gcc to handle calls and callbacks?
|
||||
or move callback asm templates into dispatch_<arch>.c
|
||||
* more tests for argument types (2 args, all permutations of basic data types)
|
||||
ensures native stack handling is done properly (handled by libffi)
|
||||
* universal OSX build w/cross-compile (hard to do with libffi)
|
||||
* use jna.encoding property to affect string encoding instead of just using
|
||||
the system default encoding.
|
||||
* change/augment getWindowHandle0 to provide any heavyweight component window
|
||||
* unions (copy-on-call is problematic: which member is active?) must require
|
||||
explicit write, either per member or whole object before export
|
||||
* rename Argument/Result Converter to be fromNative/toNative
|
||||
* split unit tests
|
||||
* auto-convert struct pointers in callback args to Java Structure
|
||||
(may need a proxy wrapper around callback to avoid excessive JNI)
|
||||
use proxy for callbacks to enable auto-conversion of arguments and/or return
|
||||
value (in java-land instead of C-land).
|
||||
* review/use refactor nativelibrary/function
|
||||
* auto-generate stdcall decorated symbols (try if undecorated lookup fails)
|
||||
* per-library jna.library.path: many libraries have a "standard" location (or
|
||||
several); let the library author indicate what these are (X11, for example)
|
||||
* return array of struct (annotation to indicate which argument has the
|
||||
length of the returned value might be nice) (this can now be done with a
|
||||
type mapper)
|
||||
* callbacks need a dispose if they are to live beyond the lifetime of the
|
||||
function to which they are passed; maybe a simpler callback interface for
|
||||
transient callbacks, and require callback+dispose for most callbacks?
|
||||
TransientCallback: callback
|
||||
NonTransientCallback: callback+dispose
|
||||
(callback is disposed when no longer referenced; user must ensure callback
|
||||
is not GC'd until it is removed as a native callback)
|
||||
* auto-convert strings in w32 functions ending in 'W'? would this introduce
|
||||
any ambiguity?
|
||||
* Dispose/unload library on GC (use ref queue)
|
||||
* fix dnd on linux (no hole?) (mostly fixed, still some artifacts)
|
||||
* transparent/shaped drag image
|
||||
* windows handles need to be Pointer (void*), not 'int'
|
||||
* other demos: move to trash, file change notification
|
||||
* tests for other primitive array types
|
||||
* build test dll/dispatch lib w/cygwin/gcc instead of msvc (?) under w32
|
||||
* nested struct alignment (4/8 byte? depends on first element?)
|
||||
* nested structs in structs: easier to define using struct; use pointer
|
||||
if you need a pointer
|
||||
struct auto-converts to pointer as argument, should be inline in struct
|
||||
(struct should require explicit pointer, argument should require explicit
|
||||
non-pointer) (maybe use object version of basic type as "pointer" version)
|
||||
* provide JNA-only search path for libraries
|
||||
* callbacks
|
||||
* move javah-generated files to own space
|
||||
* darwin/PPC asm layer
|
||||
* enable w32 build with either GCC or MSVC (GCC-built dll doesn't work yet)
|
||||
* support pointer to basic type argument (int *) w/type safety - what's the
|
||||
best API from a user perspective? new Pointer(int)? new Pointer<int>?
|
||||
Base class "pointer to" gets converted to Pointer in invocation handler;
|
||||
provide a getValue() to retrieve the result; otherwise the memory is opaque
|
||||
|
||||
o IntPtr, WCharPtr, CharPtr, ShortPtr, LongPtr, DoublePtr, FloatPtr,
|
||||
Handle (PtrPtr), getValue(), getPointer()
|
||||
o add getCharArray() et al. to Pointer?
|
||||
|
||||
* inline arrays of primitive types
|
||||
* remove debug flags (they're not useful)
|
||||
* Use WString to identify return type and arg
|
||||
* use interface to identify native, instead of annotation
|
||||
* isolate stdcall to w32 (should be private to platform)
|
||||
* generic gcc build/osx(ppc/x86)/linux
|
||||
* remove generics/enable build under 1.4
|
||||
* tests for structs
|
||||
* test float/double
|
||||
* offset placeholders for structs (explicit alignment)
|
||||
* vanilla ant build file
|
||||
* build native stuff from build.xml
|
||||
* implement basic junit tests
|
||||
* auto-align struct fields
|
||||
* handle long/byte/short
|
||||
* make annotations for native method names optional
|
||||
// hard clip for now, alpha transparency later
|
||||
// also allow ImageIcon to be used as clip (getImage())
|
||||
void setWindowMask(Window w, Shape clip);
|
||||
// needs:
|
||||
int findNativeWindow(Window w);
|
||||
|
||||
#MAYBE NOT
|
||||
* should structure offsets be 64-bit? technically yes, but in practice I don't
|
||||
think a structure that big actually works.
|
||||
* (maybe) move all native functions into Native (limit header files, easier
|
||||
management)
|
||||
* Does it make sense to define Int16/UInt16, Int32/UInt32, etc? Probably not
|
||||
the signed versions, but maybe the unsigned ones, to facilitate generating
|
||||
unsigned values (maybe just provide utilities to pack an unsigned int into a
|
||||
signed int). What about size_t, off_t, et al.? Would either need a
|
||||
bunch of native lookup functions (more accurate) or java-side conditionals
|
||||
(less robust but easier to change).
|
||||
o bounds checking is handled by IntegerType (pass in a long, get an
|
||||
exception if the value is out of bounds).
|
||||
o when used as struct fields, could allow detection of field order by order
|
||||
of initialization (requires all-or-nothing usage, though)
|
||||
* Make a separate jar file for all OS-specific headers
|
||||
Maybe make interfaces per-header file (winbase, winnt, stdlib, etc),
|
||||
aggregated per-library (interface CLibrary extends stdlib, stdio, etc)
|
||||
(how useful would it really be, or is this just sorting legos?)
|
||||
o same for windowutils, fileutils, etc. (not useful)
|
||||
* StringBuffer/StringBuilder as mutable char*/wchar_t* argument
|
||||
NOTE: byte[]/char[] is probably better; it's trivial to convert to String
|
||||
and native code can't change the size anyway
|
||||
* provide library load/unload hooks (Runnables in options?). Examples:
|
||||
o GetLastError (no longer needed)
|
||||
o WSAInit?
|
||||
* determine X11 display name from current java program (if any); null is ok
|
||||
since it uses getenv(DISPLAY), which is what java would do
|
||||
note: DISPLAY may be available in GraphicsDevice->getIDstring
|
||||
|
||||
|
||||
@@ -0,0 +1,662 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="JNA" default="default" basedir=".">
|
||||
<description>Builds and tests JNA</description>
|
||||
|
||||
<!--
|
||||
Conventions (since ant can't easily specify arbitrary file dependencies):
|
||||
The uptodate property for a given target TARGET is "-TARGET"; the actual
|
||||
target to generate the uptodate property is named ":TARGET".
|
||||
|
||||
Properties (except for uptodate properties) separate words by dots, targets
|
||||
by dashes.
|
||||
-->
|
||||
|
||||
<!-- global properties -->
|
||||
<!-- (all build-related props should go in -dynamic-properties) -->
|
||||
<property name="name" value="jna"/>
|
||||
<property name="jar" value="${name}.jar"/>
|
||||
<property name="testjar" value="${name}-test.jar"/>
|
||||
<property name="debug" value="true"/>
|
||||
<property name="debug.native" value="false"/>
|
||||
<property name="cflags_extra.native" value=""/>
|
||||
<property name="dynlink.native" value="false"/>
|
||||
<property name="native" location="native"/>
|
||||
<property name="src" location="src"/>
|
||||
<property name="contrib" location="contrib/src"/>
|
||||
<property name="dist" location="dist"/>
|
||||
<property name="test.src" location="test"/>
|
||||
<property name="doc" location="doc"/>
|
||||
<property name="javadoc" location="${doc}/javadoc"/>
|
||||
<property name="stylesheet" location="${javadoc}/doc/css/javadoc.css"/>
|
||||
<property name="vendor" value="JNA Development Team"/>
|
||||
<property name="copyright"
|
||||
value="Copyright &copy; 2007-2009 Timothy Wall. All Rights Reserved."/>
|
||||
<buildnumber/>
|
||||
<!-- JNA library release version -->
|
||||
<property name="jna.major" value="3"/>
|
||||
<property name="jna.minor" value="2"/>
|
||||
<property name="jna.revision" value="5"/>
|
||||
<property name="jna.build" value="${build.number}"/>
|
||||
<property name="jna.version" value="${jna.major}.${jna.minor}.${jna.revision}"/>
|
||||
<!-- jnidispatch library release version -->
|
||||
<property name="jni.major" value="3"/>
|
||||
<property name="jni.minor" value="2"/>
|
||||
<property name="jni.revision" value="1"/>
|
||||
<property name="jni.build" value="${build.number}"/>
|
||||
<property name="jni.version" value="${jni.major}.${jni.minor}.${jni.revision}"/>
|
||||
<property name="jni.md5" value="c870290c36c8d3fdf85db7c782febc3f"/>
|
||||
<property name="spec.title" value="Java Native Access (JNA)"/>
|
||||
<property name="spec.vendor" value="${vendor}"/>
|
||||
<property name="spec.version" value="${jna.major}"/>
|
||||
<property name="impl.title" value="com.sun.jna"/>
|
||||
<property name="impl.vendor" value="${spec.vendor}"/>
|
||||
<property name="impl.version" value="${jna.version} (b${jna.build})"/>
|
||||
|
||||
<property name="compatibility" value="1.4"/>
|
||||
<property name="test.compatibility" value="1.5"/>
|
||||
|
||||
<!-- Miscellaneous -->
|
||||
<property name="build.compiler.emacs" value="true"/>
|
||||
|
||||
<target name="default" depends="test" description="Build and Test."/>
|
||||
|
||||
<!-- uncomment for netbeans profiling -->
|
||||
<!--<import file="nbproject/profiler-build-impl.xml"/>-->
|
||||
<target name="init" depends="-setup"/>
|
||||
<target name="compile-test-single" depends="compile-tests"/>
|
||||
<target name="compile-single" depends="compile"/>
|
||||
|
||||
<target name="-dynamic-properties">
|
||||
<echo>Java version ${java.version}, compatibility: ${compatibility}</echo>
|
||||
<echo>JNA version ${jna.version}, native ${jni.version}</echo>
|
||||
<echo>${java.vm.name} (${java.vm.vendor}, ${java.vm.version})</echo>
|
||||
<echo>java.home=${java.home}</echo>
|
||||
<echo>java.library.path=${java.library.path}</echo>
|
||||
|
||||
<replaceregexp match="(<version>).*(</version>)"
|
||||
replace="\1${jna.version}\2"
|
||||
file="pom.xml"/>
|
||||
<replaceregexp match='VERSION = ".*";'
|
||||
replace='VERSION = "${jna.version}";'
|
||||
file="src/com/sun/jna/Native.java"/>
|
||||
|
||||
<condition property="jar.omitted" value="**/*jnidispatch*" else="jnilib-included">
|
||||
<isset property="omit-jnilib"/>
|
||||
</condition>
|
||||
<condition property="vm.arch" value="-d64" else="">
|
||||
<or>
|
||||
<equals arg1="${sun.arch.data.model}" arg2="64" trim="true"/>
|
||||
<equals arg1="${com.ibm.vm.bitmode}" arg2="64" trim="true"/>
|
||||
<os arch="x86_64"/>
|
||||
<os arch="ppc64"/>
|
||||
<os arch="sparcv9"/>
|
||||
<os arch="amd64"/>
|
||||
</or>
|
||||
</condition>
|
||||
<condition property="ld.preload" value="LD_PRELOAD_64" else="LD_PRELOAD">
|
||||
<and>
|
||||
<os name="SunOS"/>
|
||||
<equals arg1="${vm.arch}" arg2="-d64"/>
|
||||
</and>
|
||||
</condition>
|
||||
<property name="build" value="build${vm.arch}"/>
|
||||
<property name="classes" location="${build}/classes"/>
|
||||
<property name="eclipse.classes" location="build.eclipse/classes"/>
|
||||
<property name="test.classes" location="${build}/test-classes"/>
|
||||
<property name="reports" value="${build}/reports"/>
|
||||
|
||||
<!-- Add other supported platforms here -->
|
||||
<condition property="jre.arch" value="i386">
|
||||
<equals arg1="x86" arg2="${os.arch}"/>
|
||||
</condition>
|
||||
<condition property="jre.arch" value="amd64">
|
||||
<equals arg1="x86_64" arg2="${os.arch}"/>
|
||||
</condition>
|
||||
<property name="jre.arch" value="${os.arch}"/>
|
||||
<condition property="os.prefix" value="linux-${jre.arch}">
|
||||
<os name="Linux"/>
|
||||
</condition>
|
||||
<condition property="os.prefix" value="win32-${os.arch}">
|
||||
<os family="windows"/>
|
||||
</condition>
|
||||
<!-- Darwin builds are universal, no arch required -->
|
||||
<condition property="os.prefix" value="darwin">
|
||||
<os family="mac"/>
|
||||
</condition>
|
||||
<condition property="os.prefix" value="sunos-${os.arch}">
|
||||
<os name="SunOS"/>
|
||||
</condition>
|
||||
<condition property="os.prefix" value="freebsd-${os.arch}">
|
||||
<os name="FreeBSD"/>
|
||||
</condition>
|
||||
<condition property="os.prefix" value="openbsd-${os.arch}">
|
||||
<os name="OpenBSD"/>
|
||||
</condition>
|
||||
<fail unless="os.prefix" message="OS/arch not supported (${os.name}/${os.arch}), edit build.xml and native/Makefile to add it."/>
|
||||
<condition property="jdk.home" value="${java.home}">
|
||||
<available file="${java.home}/include"/>
|
||||
</condition>
|
||||
<condition property="jdk.home" value="${java.home}/..">
|
||||
<available file="${java.home}/../include"/>
|
||||
</condition>
|
||||
<fail unless="jdk.home" message="JAVA_HOME/java.home must be a JDK, not JRE"/>
|
||||
<condition property="libjsig"
|
||||
value="${java.home}/lib/${jre.arch}/libjsig.so" else="">
|
||||
<available file="${java.home}/lib/${jre.arch}/libjsig.so"/>
|
||||
</condition>
|
||||
<property name="native.jar" value="${os.prefix}.jar"/>
|
||||
<property name="build.native" location="${build}/native"/>
|
||||
<property name="md5.file" location="${build.native}/sig"/>
|
||||
|
||||
<mkdir dir="${build}"/>
|
||||
<mkdir dir="${build.native}"/>
|
||||
<mkdir dir="${classes}"/>
|
||||
<mkdir dir="${test.classes}"/>
|
||||
<mkdir dir="${reports}"/>
|
||||
<mkdir dir="${doc}"/>
|
||||
|
||||
</target>
|
||||
|
||||
<target name="-setup" depends="-dynamic-properties">
|
||||
<path id="compile-test.path">
|
||||
<pathelement path="${test.src}"/>
|
||||
<path id="test.libs">
|
||||
<fileset dir="lib">
|
||||
<include name="junit.jar"/>
|
||||
</fileset>
|
||||
<pathelement path="${classes}"/>
|
||||
</path>
|
||||
<path id="compile.path">
|
||||
<path id="src.path">
|
||||
<pathelement location="${src}"/>
|
||||
</path>
|
||||
</path>
|
||||
</path>
|
||||
|
||||
<path id="test.runpath">
|
||||
<pathelement path="${build}/${jar}"/>
|
||||
<pathelement path="${test.classes}"/>
|
||||
<pathelement path="lib/clover.jar"/>
|
||||
<path refid="test.libs"/>
|
||||
</path>
|
||||
</target>
|
||||
|
||||
<target name="compile" depends="-setup"
|
||||
description="Compile all Java source">
|
||||
<javac classpathref="compile.path"
|
||||
source="${compatibility}"
|
||||
target="${compatibility}"
|
||||
destdir="${classes}"
|
||||
deprecation="on" debug="${debug}">
|
||||
<src path="${src}"/>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name=":jar">
|
||||
<uptodate property="-jar" targetfile="${build}/${jar}">
|
||||
<srcfiles dir="${classes}">
|
||||
<patternset id="jar-compiled">
|
||||
<include name="com/sun/jna/*"/>
|
||||
<include name="com/sun/jna/**/*"/>
|
||||
</patternset>
|
||||
</srcfiles>
|
||||
</uptodate>
|
||||
</target>
|
||||
<target name="jar" depends="-setup,native,:jar" unless="-jar"
|
||||
description="Build primary jar">
|
||||
<jar jarfile="${build}/${jar}">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="com.sun.jna.Native"/>
|
||||
<section name="com/sun/jna/">
|
||||
<attribute name="Manifest-Version" value="1.0"/>
|
||||
<attribute name="Implementation-Title" value="${impl.title}"/>
|
||||
<attribute name="Implementation-Vendor" value="${vendor}"/>
|
||||
<attribute name="Implementation-Version" value="${impl.version}"/>
|
||||
<attribute name="Specification-Title" value="${spec.title}"/>
|
||||
<attribute name="Specification-Vendor" value="${spec.vendor}"/>
|
||||
<attribute name="Specification-Version" value="${spec.version}"/>
|
||||
<!-- OSGi Bundle attributes -->
|
||||
<attribute name="Bundle-ManifestVersion" value="2"/>
|
||||
<attribute name="Bundle-Name" value="jna"/>
|
||||
<attribute name="Bundle-Description" value="JNA Library"/>
|
||||
<attribute name="Bundle-SymbolicName" value="com.sun.jna"/>
|
||||
<attribute name="Bundle-Version" value="${spec.version}"/>
|
||||
<attribute name="Bundle-RequiredExecutionEnvironment" value="J2SE-1.4"/>
|
||||
<attribute name="Bundle-Vendor" value="${vendor}"/>
|
||||
<attribute name="Bundle-ActivationPolicy" value="lazy"/>
|
||||
<attribute name="Export-Package" value="com.sun.jna*"/>
|
||||
</section>
|
||||
</manifest>
|
||||
<fileset dir="${classes}" excludes="${jar.omitted}">
|
||||
<patternset refid="jar-compiled"/>
|
||||
</fileset>
|
||||
</jar>
|
||||
<subant target="jar">
|
||||
<fileset dir="${contrib}" includes="platform/build.xml" />
|
||||
<fileset dir="${contrib}" includes="*/build.xml" />
|
||||
</subant>
|
||||
</target>
|
||||
<target name="javah" depends="compile">
|
||||
<javah classpath="${classes}" destdir="${build.native}" force="yes">
|
||||
<class name="com.sun.jna.Function"/>
|
||||
<class name="com.sun.jna.Pointer"/>
|
||||
<class name="com.sun.jna.Memory"/>
|
||||
<class name="com.sun.jna.Native"/>
|
||||
<class name="com.sun.jna.NativeLibrary"/>
|
||||
<class name="com.sun.jna.CallbackReference"/>
|
||||
</javah>
|
||||
<condition property="grep" value="/usr/sfw/bin/ggrep">
|
||||
<os name="SunOS"/>
|
||||
</condition>
|
||||
<condition property="grep" value="ggrep">
|
||||
<os name="OpenBSD"/>
|
||||
</condition>
|
||||
<property name="grep" value="grep"/>
|
||||
<apply dir="${build.native}" executable="${grep}" parallel="true"
|
||||
failonerror="true" relative="true" output="${md5.file}">
|
||||
<arg value="-A"/>
|
||||
<arg value="1"/>
|
||||
<arg value="JNIEXPORT"/>
|
||||
<fileset dir="${build.native}" includes="*.h"/>
|
||||
</apply>
|
||||
<fixcrlf srcdir="${build.native}" includes="sig" eol="unix"/>
|
||||
<checksum property="md5" file="${md5.file}" />
|
||||
<condition property="jni.valid" value="true">
|
||||
<or>
|
||||
<equals arg1="${jni.md5}" arg2="${md5}" trim="true"/>
|
||||
<equals arg1="${jni.md5}" arg2=""/>
|
||||
</or>
|
||||
</condition>
|
||||
</target>
|
||||
|
||||
<!-- Invalidate native libraries when native API changes -->
|
||||
<target name="-native-api-check" depends="javah" unless="jni.valid">
|
||||
<echo>Invalidating native code, new checksum is ${md5}</echo>
|
||||
<copy file="${dist}/out-of-date.jar" tofile="${dist}/darwin.jar" overwrite="true"/>
|
||||
<copy file="${dist}/out-of-date.jar" tofile="${dist}/win32-x86.jar" overwrite="true"/>
|
||||
<copy file="${dist}/out-of-date.jar" tofile="${dist}/win32-amd64.jar" overwrite="true"/>
|
||||
<copy file="${dist}/out-of-date.jar" tofile="${dist}/linux-i386.jar" overwrite="true"/>
|
||||
<copy file="${dist}/out-of-date.jar" tofile="${dist}/linux-amd64.jar" overwrite="true"/>
|
||||
<copy file="${dist}/out-of-date.jar" tofile="${dist}/linux-ia64.jar" overwrite="true"/>
|
||||
<copy file="${dist}/out-of-date.jar" tofile="${dist}/freebsd-i386.jar" overwrite="true"/>
|
||||
<copy file="${dist}/out-of-date.jar" tofile="${dist}/freebsd-amd64.jar" overwrite="true"/>
|
||||
<copy file="${dist}/out-of-date.jar" tofile="${dist}/openbsd-i386.jar" overwrite="true"/>
|
||||
<copy file="${dist}/out-of-date.jar" tofile="${dist}/sunos-x86.jar" overwrite="true"/>
|
||||
<copy file="${dist}/out-of-date.jar" tofile="${dist}/sunos-amd64.jar" overwrite="true"/>
|
||||
<copy file="${dist}/out-of-date.jar" tofile="${dist}/sunos-sparc.jar" overwrite="true"/>
|
||||
<copy file="${dist}/out-of-date.jar" tofile="${dist}/sunos-sparcv9.jar" overwrite="true"/>
|
||||
<delete failOnError="false" includeEmptyDirs="true">
|
||||
<fileset dir="${build.native}" includes="*.o,*jnidispatch*"/>
|
||||
</delete>
|
||||
<fail>API for native code has changed. Re-run this build after updating jni.version and jni.md5 in build.xml</fail>
|
||||
</target>
|
||||
|
||||
<target name=":rsrc">
|
||||
<condition property="-rsrc">
|
||||
<not><os family="windows"/></not>
|
||||
</condition>
|
||||
</target>
|
||||
<target name="rsrc" depends="-setup,:rsrc" unless="-rsrc"
|
||||
description="Generate w32 DLL version resource information">
|
||||
<property name="rsrc" location="${build.native}/jnidispatch.rc"/>
|
||||
<copy todir="${build.native}" file="${native}/jnidispatch.rc"/>
|
||||
<replaceregexp match="FILEVERSION.*"
|
||||
replace="FILEVERSION ${jni.major},${jni.minor},${jni.revision},${jni.build}"
|
||||
file="${rsrc}" byline="true"/>
|
||||
<replaceregexp match="PRODUCTVERSION.*"
|
||||
replace="PRODUCTVERSION ${jna.major},${jna.minor},${jna.revision},${jna.build}"
|
||||
file="${rsrc}" byline="true"/>
|
||||
<replaceregexp match="FileVersion.*"
|
||||
replace="FileVersion","${jni.version}""
|
||||
file="${rsrc}" byline="true"/>
|
||||
<replaceregexp match="Full Version.*"
|
||||
replace="Full Version","${jni.version} b${jni.build}""
|
||||
file="${rsrc}" byline="true"/>
|
||||
<replaceregexp match="ProductVersion.*"
|
||||
replace="ProductVersion","${spec.version}""
|
||||
file="${rsrc}" byline="true"/>
|
||||
</target>
|
||||
|
||||
<target name="native" depends="-setup,javah,-native-api-check,rsrc"
|
||||
description="Build native libraries. Use 'ant -DCC=xxx' to build using a compiler other than gcc">
|
||||
<property name="comment" value="# auto-generated by ant"/>
|
||||
<replaceregexp match="^VERSION=.*"
|
||||
replace="VERSION=${jni.version} ${comment}"
|
||||
file="native/Makefile" byline="true"/>
|
||||
<replaceregexp match="^CHECKSUM=.*"
|
||||
replace="CHECKSUM=${jni.md5} ${comment}"
|
||||
file="native/Makefile" byline="true"/>
|
||||
<!-- ensure ARCH is set properly for 64-bit capable platforms -->
|
||||
<!-- use ANT_OPTS=-d64 to build 64-bit if not the platform default -->
|
||||
<property name="ARCH" value="${os.arch}"/>
|
||||
<condition property="make.CC" value="CC=${CC}" else="IGNORE=">
|
||||
<isset property="CC"/>
|
||||
</condition>
|
||||
<condition property="make.ARCH" value="ARCH=${ARCH}" else="IGNORE=">
|
||||
<isset property="ARCH"/>
|
||||
</condition>
|
||||
<condition property="make.SDKROOT" value="SDKROOT=${SDKROOT}">
|
||||
<isset property="SDKROOT"/>
|
||||
</condition>
|
||||
<condition property="make.SDKROOT"
|
||||
value="SDKROOT=/Developer/SDKs/MacOSX10.5.sdk">
|
||||
<available file="/Developer/SDKs/MacOSX10.5.sdk"/>
|
||||
</condition>
|
||||
<condition property="make.SDKROOT"
|
||||
value="SDKROOT=/Developer/SDKs/MacOSX10.4u.sdk" else="IGNORE=">
|
||||
<available file="/Developer/SDKs/MacOSX10.4u.sdk"/>
|
||||
</condition>
|
||||
<!-- Windows' drive letters and spaces in absolute paths wreak havoc on
|
||||
make -->
|
||||
<condition property="make.BUILD" value="BUILD=../${build}/native" else="BUILD=${build.native}">
|
||||
<os family="windows"/>
|
||||
</condition>
|
||||
<condition property="make.PATH" value="PATH=/usr/sfw/bin:/usr/bin:/usr/ccs/bin" else="IGNORE=">
|
||||
<os name="SunOS"/>
|
||||
</condition>
|
||||
<condition property="make" value="/usr/sfw/bin/gmake">
|
||||
<os name="SunOS"/>
|
||||
</condition>
|
||||
<condition property="make" value="gmake">
|
||||
<or>
|
||||
<os name="FreeBSD"/>
|
||||
<os name="OpenBSD"/>
|
||||
</or>
|
||||
</condition>
|
||||
<!-- Default make program -->
|
||||
<property name="make" value="make"/>
|
||||
|
||||
<exec executable="${make}" dir="${native}" failonerror="true">
|
||||
<arg value="JAVA_HOME=${jdk.home}"/>
|
||||
<arg value="JAVAH=${build.native}"/>
|
||||
<arg value="DEBUG=${debug.native}"/>
|
||||
<arg value="CFLAGS_EXTRA=${cflags_extra.native}"/>
|
||||
<arg value="DYNAMIC_LIBFFI=${dynlink.native}"/>
|
||||
<arg value="${make.CC}"/>
|
||||
<arg value="${make.BUILD}"/>
|
||||
<arg value="${make.SDKROOT}"/>
|
||||
<arg value="${make.ARCH}"/>
|
||||
<arg value="${make.PATH}"/>
|
||||
<arg value="VERSION=${jni.version}"/>
|
||||
<arg value="CHECKSUM=${jni.md5}"/>
|
||||
</exec>
|
||||
<mkdir dir="${classes}/com/sun/jna/${os.prefix}"/>
|
||||
<copy todir="${classes}/com/sun/jna/${os.prefix}">
|
||||
<fileset dir="${build.native}"
|
||||
includes="jnidispatch.dll,libjnidispatch.*"/>
|
||||
</copy>
|
||||
<mkdir dir="${eclipse.classes}/com/sun/jna/${os.prefix}"/>
|
||||
<copy todir="${eclipse.classes}/com/sun/jna/${os.prefix}"
|
||||
failonerror="false">
|
||||
<fileset dir="${build.native}"
|
||||
includes="jnidispatch.dll,libjnidispatch.*"/>
|
||||
</copy>
|
||||
<!-- For web start, native libraries may be provided in the root of -->
|
||||
<!-- an included jar file -->
|
||||
<jar jarfile="${build}/${native.jar}">
|
||||
<fileset dir="${build.native}" includes="jnidispatch.dll,libjnidispatch.*"/>
|
||||
<manifest>
|
||||
<attribute name="Implementation-Version" value="${jni.version} b${jni.build}"/>
|
||||
<attribute name="Specification-Version" value="${jni.version}"/>
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
<target name="compile-tests" depends="compile,native,jar"
|
||||
description="Compile all test code">
|
||||
<javac classpathref="compile-test.path"
|
||||
source="${test.compatibility}"
|
||||
target="${test.compatibility}"
|
||||
destdir="${test.classes}"
|
||||
deprecation="on" debug="${debug}">
|
||||
<src path="${test.src}"/>
|
||||
</javac>
|
||||
<jar jarfile="${build}/${testjar}">
|
||||
<fileset dir="${test.classes}">
|
||||
<patternset refid="jar-compiled"/>
|
||||
</fileset>
|
||||
</jar>
|
||||
<mkdir dir="${build}/jws"/>
|
||||
<copy todir="${build}/jws" file="${build}/${jar}"/>
|
||||
<copy todir="${build}/jws" file="${build}/${testjar}"/>
|
||||
<copy todir="${build}/jws" file="lib/junit.jar"/>
|
||||
<copy todir="${build}/jws" file="lib/clover.jar"/>
|
||||
<jar jarfile="${build}/jws/jnidispatch.jar">
|
||||
<fileset dir="${build.native}" includes="*jnidispatch.*"/>
|
||||
</jar>
|
||||
<signjar alias="jna" keystore="jna.keystore" storepass="jnadev" lazy="true">
|
||||
<fileset dir="${build}/jws" includes="jna.jar,jna-test.jar,junit.jar,jnidispatch.jar,clover.jar"/>
|
||||
</signjar>
|
||||
</target>
|
||||
|
||||
<!-- When running tests from an IDE, be sure to set jna.library.path -->
|
||||
<!-- to where the test library (testlib) is found. -->
|
||||
<target name="test" depends="jar,compile-tests"
|
||||
description="Run all unit tests">
|
||||
<property name="test.fork" value="yes"/>
|
||||
<property name="reports.junit" location="${reports}/junit"/>
|
||||
<property name="results.junit" location="${build}/junit-results"/>
|
||||
<mkdir dir="${results.junit}"/>
|
||||
<echo>Saving test results in ${results.junit}</echo>
|
||||
<property name="tests.stdcall" value="**/win32/*StdCallTest.java"/>
|
||||
<condition property="tests.platform" value="**/win32/**/*Test.java">
|
||||
<os family="windows"/>
|
||||
</condition>
|
||||
<condition property="tests.exclude" value="**/win32/*StdCallTest.java">
|
||||
<and><os family="windows"/><not><os arch="x86"/></not></and>
|
||||
</condition>
|
||||
<condition property="tests.platform" value="**/unix/*Test.java">
|
||||
<and>
|
||||
<os family="unix"/>
|
||||
<not><os family="mac"/></not>
|
||||
</and>
|
||||
</condition>
|
||||
<condition property="vmopt.arch" value="-d64" else="-Dignore">
|
||||
<and>
|
||||
<!-- Sun 64-bit VM for windows doesn't support the -d64 switch -->
|
||||
<not><os family="windows"/></not>
|
||||
<equals arg1="${vm.arch}" arg2="-d64" trim="true"/>
|
||||
</and>
|
||||
</condition>
|
||||
<property name="tests.platform" value=""/>
|
||||
<property name="tests.exclude" value=""/>
|
||||
<junit printsummary="yes" fork="${test.fork}" failureproperty="testfailure">
|
||||
<!-- avoid VM conflicts with JNA protected mode -->
|
||||
<env key="${ld.preload}" file="${libjsig}"/>
|
||||
<jvmarg value="-Djna.library.path=${build.native}"/>
|
||||
<!-- Avoid VM crashes, if possible -->
|
||||
<jvmarg value="-Djna.protected=true"/>
|
||||
<jvmarg value="-Djna.builddir=${build}"/>
|
||||
<jvmarg value="${vmopt.arch}"/>
|
||||
<classpath><path refid="test.runpath"/></classpath>
|
||||
<formatter type="xml"/>
|
||||
<batchtest todir="${results.junit}">
|
||||
<fileset dir="${test.src}">
|
||||
<include name="com/sun/jna/*Test.java"/>
|
||||
<include name="${tests.platform}"/>
|
||||
<exclude name="${tests.exclude}"/>
|
||||
</fileset>
|
||||
</batchtest>
|
||||
</junit>
|
||||
<subant target="test">
|
||||
<fileset dir="${contrib}" includes="platform/build.xml"/>
|
||||
</subant>
|
||||
<junitreport todir="${results.junit}">
|
||||
<fileset dir="${results.junit}">
|
||||
<include name="TEST-*.xml"/>
|
||||
</fileset>
|
||||
<report todir="${reports.junit}"/>
|
||||
</junitreport>
|
||||
<echo>View test report in file://${reports.junit}/index.html</echo>
|
||||
<fail if="testfailure" unless="clover">One or more tests failed</fail>
|
||||
</target>
|
||||
|
||||
<target name="with.clover" description="Enable code coverage for tests">
|
||||
<taskdef resource="cloverlib.xml" classpath="lib/clover.jar"/>
|
||||
<property name="clover" value="true"/>
|
||||
<property name="build" value="build.clover"/>
|
||||
<clover-setup/>
|
||||
</target>
|
||||
|
||||
<target name="clover" depends="with.clover,test"
|
||||
description="Generate test code coverage reports">
|
||||
<property name="reports.clover" value="${reports}/clover"/>
|
||||
<mkdir dir="${reports.clover}"/>
|
||||
<clover-report>
|
||||
<current outfile="${reports.clover}" title="clover">
|
||||
<fileset dir="." includes="**/*.java" />
|
||||
<testresults dir="${results.junit}" includes="TEST-*.xml"/>
|
||||
<format type="html"/>
|
||||
</current>
|
||||
</clover-report>
|
||||
<echo>Reports generated in ${reports.clover}</echo>
|
||||
</target>
|
||||
|
||||
<target name="javadoc" depends="-setup">
|
||||
<property name="header"
|
||||
value="<b>JNA API</><font size="-1"> ${jna.version}</font>"/>
|
||||
<property name="footer"
|
||||
value="<center><i>${copyright}</i></center>"/>
|
||||
|
||||
<mkdir dir="${javadoc}"/>
|
||||
<javadoc package="true"
|
||||
windowtitle="JNA API"
|
||||
sourcepathref="src.path"
|
||||
classpathref="compile.path"
|
||||
maxmemory="256m"
|
||||
packagenames="com.sun.jna,com.sun.jna.ptr,com.sun.jna.types,com.sun.jna.platform,com.sun.jna.platform.win32,com.sun.jna.exmaples.unix"
|
||||
overview="${src}/com/sun/jna/overview.html"
|
||||
destdir="${javadoc}">
|
||||
<!-- stylesheetfile="${stylesheet}" -->
|
||||
<doctitle>JNA API Documentation</doctitle>
|
||||
<header>${header}</header>
|
||||
<bottom>${footer}</bottom>
|
||||
<link href="http://java.sun.com/j2se/1.4.2/docs/api/"/>
|
||||
|
||||
<packageset dir="${src}" defaultexcludes="yes">
|
||||
<patternset>
|
||||
<include name="com/sun/jna/**/*"/>
|
||||
</patternset>
|
||||
</packageset>
|
||||
|
||||
<group title="Java Native Access" packages="com.sun.jna,com.sun.jna.ptr,com.sun.jna.types,com.sun.jna.win32"/>
|
||||
<group title="Platform Specific" packages="com.sun.jna.platform"/>
|
||||
|
||||
<arg value="-notimestamp"/>
|
||||
</javadoc>
|
||||
<subant target="javadoc">
|
||||
<fileset dir="${contrib}" includes="platform/build.xml"/>
|
||||
</subant>
|
||||
</target>
|
||||
|
||||
<target name="dist" depends="jar,compile-tests,native,javadoc"
|
||||
description="Build distribution files">
|
||||
<jar jarfile="${dist}/jna.jar" duplicate="preserve">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="com.sun.jna.Native"/>
|
||||
<section name="com/sun/jna/">
|
||||
<attribute name="Implementation-Title" value="${impl.title}"/>
|
||||
<attribute name="Implementation-Vendor" value="${vendor}"/>
|
||||
<attribute name="Implementation-Version" value="${impl.version}"/>
|
||||
<attribute name="Specification-Title" value="${spec.title}"/>
|
||||
<attribute name="Specification-Vendor" value="${spec.vendor}"/>
|
||||
<attribute name="Specification-Version" value="${spec.version}"/>
|
||||
</section>
|
||||
</manifest>
|
||||
<zipfileset src="${build}/${jar}"/>
|
||||
<zipfileset src="${dist}/win32-x86.jar"
|
||||
includes="*jnidispatch*"
|
||||
prefix="com/sun/jna/win32-x86"/>
|
||||
<zipfileset src="${dist}/darwin.jar"
|
||||
includes="*jnidispatch*"
|
||||
prefix="com/sun/jna/darwin"/>
|
||||
<zipfileset src="${dist}/linux-i386.jar"
|
||||
includes="*jnidispatch*"
|
||||
prefix="com/sun/jna/linux-i386"/>
|
||||
<zipfileset src="${dist}/linux-amd64.jar"
|
||||
includes="*jnidispatch*"
|
||||
prefix="com/sun/jna/linux-amd64"/>
|
||||
<zipfileset src="${dist}/linux-ia64.jar"
|
||||
includes="*jnidispatch*"
|
||||
prefix="com/sun/jna/linux-ia64"/>
|
||||
<zipfileset src="${dist}/sunos-x86.jar"
|
||||
includes="*jnidispatch*"
|
||||
prefix="com/sun/jna/sunos-x86"/>
|
||||
<zipfileset src="${dist}/sunos-amd64.jar"
|
||||
includes="*jnidispatch*"
|
||||
prefix="com/sun/jna/sunos-amd64"/>
|
||||
<zipfileset src="${dist}/sunos-sparc.jar"
|
||||
includes="*jnidispatch*"
|
||||
prefix="com/sun/jna/sunos-sparc"/>
|
||||
<zipfileset src="${dist}/sunos-sparcv9.jar"
|
||||
includes="*jnidispatch*"
|
||||
prefix="com/sun/jna/sunos-sparcv9"/>
|
||||
<zipfileset src="${dist}/freebsd-i386.jar"
|
||||
includes="*jnidispatch*"
|
||||
prefix="com/sun/jna/freebsd-i386"/>
|
||||
<zipfileset src="${dist}/freebsd-amd64.jar"
|
||||
includes="*jnidispatch*"
|
||||
prefix="com/sun/jna/freebsd-amd64"/>
|
||||
<zipfileset src="${dist}/openbsd-i386.jar"
|
||||
includes="*jnidispatch*"
|
||||
prefix="com/sun/jna/openbsd-i386"/>
|
||||
<zipfileset src="${dist}/win32-amd64.jar"
|
||||
includes="*jnidispatch*"
|
||||
prefix="com/sun/jna/win32-amd64"/>
|
||||
</jar>
|
||||
<copy todir="${dist}">
|
||||
<fileset dir="${build}">
|
||||
<include name="${native.jar}"/>
|
||||
</fileset>
|
||||
<fileset dir="${contrib}/platform/dist">
|
||||
<include name="platform.jar" />
|
||||
</fileset>
|
||||
</copy>
|
||||
<copy todir="${dist}/jnacontrib" flatten="true">
|
||||
<fileset dir="${contrib}">
|
||||
<include name="**/build/demo-*.jar" />
|
||||
</fileset>
|
||||
</copy>
|
||||
<zip zipfile="${dist}/doc.zip">
|
||||
<zipfileset dir="${javadoc}" prefix="javadoc"/>
|
||||
<zipfileset dir="${contrib}/platform/dist/javadoc" prefix="platform/javadoc"/>
|
||||
</zip>
|
||||
<!-- JNA sources only, for use in Linux build from source/shared libffi -->
|
||||
<zip zipfile="${dist}/src.zip">
|
||||
<zipfileset dir="." includes="build.xml,LICENSE.txt"/>
|
||||
<zipfileset dir="${src}" includes="**/*.java" prefix="src"/>
|
||||
<zipfileset dir="${test.src}" includes="**/*.java" prefix="test"/>
|
||||
<zipfileset dir="${native}" excludes="libffi,libffi/**/*" prefix="native"/>
|
||||
<zipfileset dir="${contrib}/platform" includes="**/*.java" prefix="contrib/platform"/>
|
||||
</zip>
|
||||
<!-- Full sources required to build and test everything -->
|
||||
<zip zipfile="${dist}/src-full.zip">
|
||||
<zipfileset src="${dist}/src.zip"/>
|
||||
<zipfileset dir="lib" includes="junit.jar,clover.jar" prefix="lib"/>
|
||||
<zipfileset dir="." includes=".classpath,.project"/>
|
||||
<zipfileset dir="nbproject" includes="**/*" prefix="nbproject"/>
|
||||
<zipfileset dir="${native}" includes="libffi,libffi/**/*" prefix="native"/>
|
||||
</zip>
|
||||
<!-- Sources package as required by maven -->
|
||||
<zip zipfile="${dist}/src-mvn.zip">
|
||||
<zipfileset dir="${src}" includes="**/*.java,**/*.html,**/*.png"/>
|
||||
</zip>
|
||||
</target>
|
||||
|
||||
<target name="clean" depends="-dynamic-properties">
|
||||
<delete failOnError="false" includeEmptyDirs="true">
|
||||
<fileset dir="${build}"/>
|
||||
</delete>
|
||||
<delete quiet="true" includeEmptyDirs="true">
|
||||
<fileset dir=".clover"/>
|
||||
<fileset dir="${javadoc}"/>
|
||||
<fileset dir="." includes="*~,**/*~"/>
|
||||
</delete>
|
||||
<subant target="clean">
|
||||
<fileset dir="${contrib}" includes="*/build.xml"/>
|
||||
</subant>
|
||||
</target>
|
||||
|
||||
</project>
|
||||
|
||||
|
||||
Arquivo executável
+4
@@ -0,0 +1,4 @@
|
||||
This directory contains code which has been contributed by JNA users. If no
|
||||
tests are included, you should assume the code has only been checked for
|
||||
compile-time errors :)
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path=""/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="/jna/dist/jna.jar"/>
|
||||
<classpathentry kind="src" path="/platform"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>alphamaskdemo</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,78 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="jnacontrib.alphamaskdemo" default="jar" basedir=".">
|
||||
<description>Builds, tests, and runs the project jnacontrib.alphamaskdemo.</description>
|
||||
<!-- Locations -->
|
||||
<property name="src" location="."/>
|
||||
<property name="build" location="build"/>
|
||||
<property name="jna-dist" location="../../../dist"/>
|
||||
|
||||
<property name="buildClasses" location="${build}/classes"/>
|
||||
<property name="buildJar" location="${build}/demo-alphamask.jar"/>
|
||||
|
||||
<property name="main-class" value="com.sun.jna.contrib.demo.AlphaMaskDemo" />
|
||||
|
||||
<path id="classpath">
|
||||
<fileset dir="../../../build">
|
||||
<include name="jna.jar"/>
|
||||
</fileset>
|
||||
<fileset dir="../platform/dist">
|
||||
<include name="platform.jar"/>
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<!-- Run Demo. -->
|
||||
<target name="run" depends="compile">
|
||||
<java classname="${main-class}" fork="true">
|
||||
<classpath>
|
||||
<pathelement location="${buildClasses}" />
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<!-- Delete class and jar files. -->
|
||||
<target name="clean">
|
||||
<delete dir="${buildClasses}"/>
|
||||
<delete file="${buildJar}"/>
|
||||
<delete dir="${build}"/>
|
||||
</target>
|
||||
|
||||
<!-- Compile all classes. -->
|
||||
<target name="compile">
|
||||
<mkdir dir="${buildClasses}"/>
|
||||
|
||||
<!-- Compile the project. -->
|
||||
<javac srcdir="${src}" destdir="${buildClasses}" target="1.5" source="1.5" encoding="UTF-8" debug="on">
|
||||
<classpath>
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
<src>
|
||||
<dirset dir="${src}"/>
|
||||
</src>
|
||||
</javac>
|
||||
|
||||
<!-- Copy all non-java files to classes. -->
|
||||
<copy todir="${buildClasses}/com">
|
||||
<fileset dir="${src}/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
<!-- platform -->
|
||||
<fileset dir="../platform/build/classes/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
<!-- jna -->
|
||||
<fileset dir="../../../build/classes/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<!-- Create jar-file. -->
|
||||
<target name="jar" depends="compile">
|
||||
<jar jarfile="${buildJar}" basedir="${buildClasses}">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="${main-class}"/>
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,527 @@
|
||||
/* Copyright (c) 2007-2008 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.sun.jna.contrib.demo;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.Window;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.awt.image.ImageObserver;
|
||||
import java.awt.image.Raster;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.JWindow;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.TransferHandler;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.event.MouseInputAdapter;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.NativeLong;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.platform.WindowUtils;
|
||||
import com.sun.jna.platform.unix.X11;
|
||||
import com.sun.jna.platform.unix.X11.Display;
|
||||
import com.sun.jna.platform.unix.X11.GC;
|
||||
import com.sun.jna.platform.win32.GDI32;
|
||||
import com.sun.jna.platform.win32.User32;
|
||||
import com.sun.jna.platform.win32.GDI32.BITMAPINFO;
|
||||
import com.sun.jna.platform.win32.User32.BLENDFUNCTION;
|
||||
import com.sun.jna.platform.win32.User32.POINT;
|
||||
import com.sun.jna.platform.win32.User32.SIZE;
|
||||
import com.sun.jna.platform.win32.W32API.HANDLE;
|
||||
import com.sun.jna.platform.win32.W32API.HBITMAP;
|
||||
import com.sun.jna.platform.win32.W32API.HDC;
|
||||
import com.sun.jna.platform.win32.W32API.HWND;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
|
||||
// TODO: put this into a reasonable API; right now this is pretty much
|
||||
// just hard-coded blitting of an image into a window
|
||||
// Thanks to Rui Lopes for the C# example on which this is based:
|
||||
// rui@ruilopes.com
|
||||
// http://www.codeproject.com/cs/media/perpxalpha_sharp.asp?df=100&forumid=3270&exp=0&select=773155
|
||||
public class AlphaMaskDemo implements Runnable {
|
||||
|
||||
private static final DataFlavor URL_FLAVOR =
|
||||
new DataFlavor("application/x-java-url; class=java.net.URL", "URL");
|
||||
private static final DataFlavor URI_LIST_FLAVOR =
|
||||
new DataFlavor("text/uri-list; class=java.lang.String", "URI list");
|
||||
|
||||
private JFrame frame;
|
||||
private JWindow alphaWindow;
|
||||
private float alpha = 1f;
|
||||
private Image image;
|
||||
|
||||
private void update() {
|
||||
update(false, true);
|
||||
}
|
||||
|
||||
private void update(boolean a, boolean i) {
|
||||
String os = System.getProperty("os.name");
|
||||
if (os.startsWith("Windows"))
|
||||
updateW32(a, i);
|
||||
else if (os.startsWith("Linux"))
|
||||
updateX11(a, i);
|
||||
else if (os.startsWith("Mac"))
|
||||
updateMac(a, i);
|
||||
}
|
||||
|
||||
private void updateMac(boolean a, boolean i) {
|
||||
if (!alphaWindow.isDisplayable()) {
|
||||
alphaWindow.pack();
|
||||
}
|
||||
if (a)
|
||||
WindowUtils.setWindowAlpha(alphaWindow, alpha);
|
||||
if (i) {
|
||||
alphaWindow.setBackground(new Color(0,0,0,0));
|
||||
alphaWindow.setContentPane(new JLabel(new ImageIcon(image)));
|
||||
alphaWindow.setSize(alphaWindow.getPreferredSize());
|
||||
}
|
||||
if (!alphaWindow.isVisible()) {
|
||||
Window parent = alphaWindow.getOwner();
|
||||
Point where = parent.getLocationOnScreen();
|
||||
where.translate(parent.getWidth(), 0);
|
||||
alphaWindow.setLocation(where);
|
||||
alphaWindow.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
private com.sun.jna.Memory buffer;
|
||||
private int[] pixels;
|
||||
private void updateX11(boolean a, boolean i) {
|
||||
X11 x11 = X11.INSTANCE;
|
||||
X11.Window win = X11.Window.None;
|
||||
Display dpy = x11.XOpenDisplay(null);
|
||||
try {
|
||||
if (!alphaWindow.isDisplayable()) {
|
||||
alphaWindow.pack();
|
||||
if (System.getProperty("java.version").matches("^1\\.4\\..*"))
|
||||
alphaWindow.setVisible(true);
|
||||
win = new X11.Window((int)Native.getWindowID(alphaWindow));
|
||||
Window parent = alphaWindow.getOwner();
|
||||
Point where = parent.getLocationOnScreen();
|
||||
where.translate(parent.getWidth(), 0);
|
||||
alphaWindow.removeAll();
|
||||
alphaWindow.setLocation(where);
|
||||
alphaWindow.setBackground(new Color(0,0,0,0));
|
||||
}
|
||||
else {
|
||||
win = new X11.Window((int)Native.getWindowID(alphaWindow));
|
||||
}
|
||||
|
||||
if (i) {
|
||||
int w = image.getWidth(null);
|
||||
int h = image.getHeight(null);
|
||||
alphaWindow.setSize(w, h);
|
||||
if (buffer == null || buffer.getSize() != w*h*4) {
|
||||
buffer = new com.sun.jna.Memory(w*h*4);
|
||||
pixels = new int[w*h];
|
||||
}
|
||||
|
||||
BufferedImage buf = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
|
||||
Graphics g = buf.getGraphics();
|
||||
g.drawImage(image, 0, 0, w, h, null);
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
long blitTime, putImageTime, write;
|
||||
GC gc = x11.XCreateGC(dpy, win, new NativeLong(0), null);
|
||||
long gcTime = System.currentTimeMillis();
|
||||
try {
|
||||
Raster raster = buf.getData();
|
||||
int[] pixel = new int[4];
|
||||
for (int y=0;y < h;y++) {
|
||||
for (int x=0;x < w;x++) {
|
||||
raster.getPixel(x, y, pixel);
|
||||
int alpha = (pixel[3]&0xFF)<<24;
|
||||
int red = (pixel[2]&0xFF);
|
||||
int green = (pixel[1]&0xFF)<<8;
|
||||
int blue = (pixel[0]&0xFF)<<16;
|
||||
pixels[y*w+x] = alpha|red|green|blue;
|
||||
}
|
||||
}
|
||||
blitTime = System.currentTimeMillis();
|
||||
X11.XWindowAttributes xwa = new X11.XWindowAttributes();
|
||||
x11.XGetWindowAttributes(dpy, win, xwa);
|
||||
X11.XImage image = x11.XCreateImage(dpy, xwa.visual,
|
||||
32, X11.ZPixmap,
|
||||
0, buffer, w, h, 32, w*4);
|
||||
buffer.write(0, pixels, 0, pixels.length);
|
||||
write = System.currentTimeMillis();
|
||||
x11.XPutImage(dpy, win, gc, image, 0,0,0,0,w,h);
|
||||
x11.XFree(image.getPointer());
|
||||
putImageTime = System.currentTimeMillis();
|
||||
}
|
||||
finally {
|
||||
if (gc != null)
|
||||
x11.XFreeGC(dpy, gc);
|
||||
}
|
||||
long end = System.currentTimeMillis();
|
||||
//System.out.println("gc: " + (gcTime-start) + "ms");
|
||||
//System.out.println("blit: " + (blitTime-gcTime) + "ms");
|
||||
//System.out.println("write: " + (write-blitTime) + "ms");
|
||||
//System.out.println("put image: " + (putImageTime-write) + "ms");
|
||||
//System.out.println("total: " + (end-start) + "ms");
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (dpy != null)
|
||||
x11.XCloseDisplay(dpy);
|
||||
}
|
||||
if (a)
|
||||
WindowUtils.setWindowAlpha(alphaWindow, alpha);
|
||||
|
||||
if (!alphaWindow.isVisible()) {
|
||||
alphaWindow.setVisible(true);
|
||||
// hack for initial refresh (X11)
|
||||
update(true, true);
|
||||
}
|
||||
}
|
||||
|
||||
private HWND getHwnd(Window w) {
|
||||
HWND hwnd = new HWND();
|
||||
hwnd.setPointer(Native.getWindowPointer(w));
|
||||
return hwnd;
|
||||
}
|
||||
|
||||
private void updateW32(boolean a, boolean i) {
|
||||
User32 user = User32.INSTANCE;
|
||||
GDI32 gdi = GDI32.INSTANCE;
|
||||
HWND hWnd = null;
|
||||
|
||||
if (!alphaWindow.isDisplayable()) {
|
||||
alphaWindow.pack();
|
||||
hWnd = getHwnd(alphaWindow);
|
||||
int flags = user.GetWindowLong(hWnd, User32.GWL_EXSTYLE);
|
||||
flags |= User32.WS_EX_LAYERED;
|
||||
user.SetWindowLong(hWnd, User32.GWL_EXSTYLE, flags);
|
||||
Window parent = alphaWindow.getOwner();
|
||||
Point where = parent.getLocationOnScreen();
|
||||
where.translate(parent.getWidth(), 0);
|
||||
alphaWindow.setLocation(where);
|
||||
}
|
||||
else {
|
||||
hWnd = getHwnd(alphaWindow);
|
||||
}
|
||||
|
||||
if (i) {
|
||||
int w = image.getWidth(null);
|
||||
int h = image.getHeight(null);
|
||||
HDC screenDC = user.GetDC(null);
|
||||
HDC memDC = gdi.CreateCompatibleDC(screenDC);
|
||||
HBITMAP hBitmap = null;
|
||||
HANDLE oldBitmap = null;
|
||||
|
||||
try {
|
||||
BufferedImage buf = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
|
||||
Graphics g = buf.getGraphics();
|
||||
g.drawImage(image, 0, 0, w, h, null);
|
||||
|
||||
BITMAPINFO bmi = new BITMAPINFO();
|
||||
bmi.bmiHeader.biWidth = w;
|
||||
bmi.bmiHeader.biHeight = h;
|
||||
bmi.bmiHeader.biPlanes = 1;
|
||||
bmi.bmiHeader.biBitCount = 32;
|
||||
bmi.bmiHeader.biCompression = GDI32.BI_RGB;
|
||||
bmi.bmiHeader.biSizeImage = w * h * 4;
|
||||
|
||||
PointerByReference ppbits = new PointerByReference();
|
||||
hBitmap = gdi.CreateDIBSection(memDC, bmi, GDI32.DIB_RGB_COLORS,
|
||||
ppbits, null, 0);
|
||||
oldBitmap = gdi.SelectObject(memDC, hBitmap);
|
||||
Pointer pbits = ppbits.getValue();
|
||||
|
||||
Raster raster = buf.getData();
|
||||
int[] pixel = new int[4];
|
||||
int[] bits = new int[w*h];
|
||||
for (int y=0;y < h;y++) {
|
||||
for (int x=0;x < w;x++) {
|
||||
raster.getPixel(x, h-y-1, pixel);
|
||||
int alpha = (pixel[3]&0xFF)<<24;
|
||||
int red = (pixel[2]&0xFF);
|
||||
int green = (pixel[1]&0xFF)<<8;
|
||||
int blue = (pixel[0]&0xFF)<<16;
|
||||
bits[x + y * w] = alpha|red|green|blue;
|
||||
}
|
||||
}
|
||||
pbits.write(0, bits, 0, bits.length);
|
||||
|
||||
SIZE size = new SIZE();
|
||||
size.cx = w;
|
||||
size.cy = h;
|
||||
POINT loc = new POINT();
|
||||
loc.x = alphaWindow.getX();
|
||||
loc.y = alphaWindow.getY();
|
||||
POINT srcLoc = new POINT();
|
||||
BLENDFUNCTION blend = new BLENDFUNCTION();
|
||||
blend.SourceConstantAlpha = (byte)(alpha * 255);
|
||||
blend.AlphaFormat = User32.AC_SRC_ALPHA;
|
||||
user.UpdateLayeredWindow(hWnd, screenDC, loc, size, memDC, srcLoc,
|
||||
0, blend, User32.ULW_ALPHA);
|
||||
}
|
||||
finally {
|
||||
user.ReleaseDC(null, screenDC);
|
||||
if (hBitmap != null) {
|
||||
gdi.SelectObject(memDC, oldBitmap);
|
||||
gdi.DeleteObject(hBitmap);
|
||||
}
|
||||
gdi.DeleteDC(memDC);
|
||||
}
|
||||
}
|
||||
else if (a) {
|
||||
BLENDFUNCTION blend = new BLENDFUNCTION();
|
||||
blend.SourceConstantAlpha = (byte)(alpha * 255);
|
||||
blend.AlphaFormat = User32.AC_SRC_ALPHA;
|
||||
user.UpdateLayeredWindow(hWnd, null, null, null, null, null,
|
||||
0, blend, User32.ULW_ALPHA);
|
||||
}
|
||||
|
||||
if (!alphaWindow.isVisible()) {
|
||||
alphaWindow.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
private ImageObserver observer = new ImageObserver() {
|
||||
public boolean imageUpdate(final Image img, int infoflags, int x, int y, int width, int height) {
|
||||
if ((infoflags & (ImageObserver.ALLBITS|ImageObserver.FRAMEBITS)) != 0) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
setImage(img);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
else if ((infoflags & (ImageObserver.ERROR|ImageObserver.ABORT)) != 0) {
|
||||
System.out.println("Image load error: " + img);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
};
|
||||
private void setImage(final Image image) {
|
||||
int w = image.getWidth(observer);
|
||||
int h = image.getHeight(observer);
|
||||
if (w > 0 && h > 0) {
|
||||
this.image = image;
|
||||
frame.setIconImage(image);
|
||||
update(false, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void setAlpha(float alpha) {
|
||||
this.alpha = alpha = Math.min(1f, Math.max(0f, alpha));
|
||||
update(true, false);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
// Must find a graphics configuration with a depth of 32 bits
|
||||
GraphicsConfiguration gconfig = WindowUtils.getAlphaCompatibleGraphicsConfiguration();
|
||||
frame = new JFrame("Alpha Mask Demo");
|
||||
alphaWindow = new JWindow(frame, gconfig);
|
||||
MouseInputAdapter handler = new MouseInputAdapter() {
|
||||
private Point offset;
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (SwingUtilities.isLeftMouseButton(e))
|
||||
offset = e.getPoint();
|
||||
}
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
offset = null;
|
||||
// hack (w32) calling this has the side effect of re-enabling
|
||||
// hit testing; not sure why it gets disabled
|
||||
if (System.getProperty("os.name").startsWith("Windows"))
|
||||
update(true, true);
|
||||
}
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
if (offset != null) {
|
||||
Window w = (Window)e.getSource();
|
||||
Point where = e.getPoint();
|
||||
where.translate(-offset.x, -offset.y);
|
||||
Point loc = w.getLocationOnScreen();
|
||||
loc.translate(where.x, where.y);
|
||||
w.setLocation(loc.x, loc.y);
|
||||
}
|
||||
}
|
||||
};
|
||||
alphaWindow.addMouseListener(handler);
|
||||
alphaWindow.addMouseMotionListener(handler);
|
||||
JPanel p = new JPanel(new BorderLayout(8, 8));
|
||||
p.setBorder(new EmptyBorder(8, 8, 8, 8));
|
||||
p.setTransferHandler(new TransferHandler() {
|
||||
public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
|
||||
List list = Arrays.asList(transferFlavors);
|
||||
if (list.contains(URL_FLAVOR)
|
||||
|| list.contains(URI_LIST_FLAVOR)
|
||||
|| list.contains(DataFlavor.imageFlavor)
|
||||
|| list.contains(DataFlavor.javaFileListFlavor)) {
|
||||
return true;
|
||||
}
|
||||
if (DataFlavor.selectBestTextFlavor(transferFlavors) != null) {
|
||||
return true;
|
||||
}
|
||||
System.out.println("No acceptable flavor found in "
|
||||
+ Arrays.asList(transferFlavors));
|
||||
return false;
|
||||
}
|
||||
public boolean importData(JComponent comp, Transferable t) {
|
||||
try {
|
||||
if (t.isDataFlavorSupported(URL_FLAVOR)) {
|
||||
URL url = (URL)t.getTransferData(URL_FLAVOR);
|
||||
setImage(Toolkit.getDefaultToolkit().getImage(url));
|
||||
return true;
|
||||
}
|
||||
if (t.isDataFlavorSupported(URI_LIST_FLAVOR)) {
|
||||
String s = (String)t.getTransferData(URI_LIST_FLAVOR);
|
||||
String[] uris = s.split("[\r\n]");
|
||||
if (uris.length > 0) {
|
||||
URL url = new URL(uris[0]);
|
||||
setImage(Toolkit.getDefaultToolkit().getImage(url));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
|
||||
Image image = (Image)t.getTransferData(DataFlavor.imageFlavor);
|
||||
setImage(image);
|
||||
return true;
|
||||
}
|
||||
if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)){
|
||||
List files = (List)t.getTransferData(DataFlavor.javaFileListFlavor);
|
||||
File f = (File)files.get(0);
|
||||
URL url = new URL("file://" + f.toURI().toURL().getPath());
|
||||
Image image = Toolkit.getDefaultToolkit().getImage(url);
|
||||
setImage(image);
|
||||
return true;
|
||||
}
|
||||
DataFlavor flavor = DataFlavor.selectBestTextFlavor(t.getTransferDataFlavors());
|
||||
if (flavor != null) {
|
||||
Reader reader = flavor.getReaderForText(t);
|
||||
char[] buf = new char[512];
|
||||
StringBuffer b = new StringBuffer();
|
||||
int count;
|
||||
// excise excess NUL characters (bug in firefox, java
|
||||
// or my code, not sure which). someone got the
|
||||
// encoding wrong
|
||||
while ((count = reader.read(buf)) > 0) {
|
||||
for (int i=0;i < count;i++) {
|
||||
if (buf[i] != 0)
|
||||
b.append(buf, i, 1);
|
||||
}
|
||||
}
|
||||
String html = b.toString();
|
||||
Pattern p = Pattern.compile("<img.*src=\"([^\\\"\">]+)\"",
|
||||
Pattern.CANON_EQ|Pattern.UNICODE_CASE);
|
||||
Matcher m = p.matcher(html);
|
||||
if (m.find()) {
|
||||
URL url = new URL(m.group(1));
|
||||
System.out.println("Load image from " + url);
|
||||
Image image = Toolkit.getDefaultToolkit().getImage(url);
|
||||
setImage(image);
|
||||
return true;
|
||||
}
|
||||
System.out.println("Can't parse text: " + html);
|
||||
return false;
|
||||
}
|
||||
System.out.println("No flavor available: "
|
||||
+ Arrays.asList(t.getTransferDataFlavors()));
|
||||
}
|
||||
catch (UnsupportedFlavorException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch(Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
p.add(new JLabel("<html><center>Drop an image with an alpha channel onto this window<br>"
|
||||
+ "You may also adjust the overall transparency with the slider</center></html>"),
|
||||
BorderLayout.NORTH);
|
||||
final JSlider slider = new JSlider(0, 255, 255);
|
||||
slider.addChangeListener(new ChangeListener() {
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
int value = slider.getValue();
|
||||
setAlpha(value / 255f);
|
||||
}
|
||||
});
|
||||
p.add(slider, BorderLayout.SOUTH);
|
||||
|
||||
frame.getContentPane().add(p);
|
||||
frame.pack();
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
centerOnScreen(frame);
|
||||
frame.setVisible(true);
|
||||
p.addMouseListener(new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
update();
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
URL url = getClass().getResource("tardis.png");
|
||||
if (url != null) {
|
||||
setImage(Toolkit.getDefaultToolkit().getImage(url));
|
||||
}
|
||||
}
|
||||
catch(Exception e) { }
|
||||
}
|
||||
|
||||
/** Center the given {@link Window} on the default screen. */
|
||||
private static void centerOnScreen(Window window) {
|
||||
Point center = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
|
||||
Rectangle max = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
|
||||
int x = Math.max(center.x - Math.round(window.getWidth()/2f), max.x);
|
||||
int y = Math.max(center.y - Math.round(window.getHeight()/2f), max.y);
|
||||
window.setLocation(new Point(x, y));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
SwingUtilities.invokeLater(new AlphaMaskDemo());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generic JNLP/Web Start Configuration -->
|
||||
<jnlp spec="1.0" codebase="http://abbot.sf.net/demo" href="AlphaMaskDemo.jnlp">
|
||||
<information>
|
||||
<title>Alpha Mask Demo</title>
|
||||
<vendor>Technomage</vendor>
|
||||
<homepage href="http://rabbit-hole.blogspot.com"/>
|
||||
<description>Demo of a per-pixel alpha masked window.</description>
|
||||
<description kind="short">Alpha Mask</description>
|
||||
</information>
|
||||
<resources>
|
||||
<j2se version="1.3+" href="http://java.sun.com/products/autodl/j2se"/>
|
||||
<!-- Required for window transparency -->
|
||||
<property name="sun.java2d.noddraw" value="true"/>
|
||||
<jar href="examples.jar" main="true"/>
|
||||
<jar href="jna.jar"/>
|
||||
</resources>
|
||||
<resources os="Windows" arch="x86">
|
||||
<nativelib href="win32-x86.jar"/>
|
||||
</resources>
|
||||
<resources os="Linux" arch="i386">
|
||||
<!-- Use 32-bit X11 libs on 64-bit systems (Ubuntu) -->
|
||||
<property name="jna.library.path" value="/usr/X11R6/lib:/usr/lib32:/usr/lib"/>
|
||||
<nativelib href="linux-i386.jar"/>
|
||||
</resources>
|
||||
<resources os="Mac">
|
||||
<nativelib href="darwin.jar"/>
|
||||
</resources>
|
||||
<application-desc main-class="com.sun.jna.examples.AlphaMaskDemo"/>
|
||||
<security>
|
||||
<all-permissions/>
|
||||
</security>
|
||||
</jnlp>
|
||||
@@ -0,0 +1,301 @@
|
||||
/*
|
||||
* Copyright (c) 2007-2008 Timothy Wall, All Rights Reserved This library is
|
||||
* free software; you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* your option) any later version. This library is distributed in the
|
||||
* hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
||||
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.contrib.demo;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.Window;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.image.ImageObserver;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JSlider;
|
||||
import javax.swing.JWindow;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.TransferHandler;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
import javax.swing.event.MouseInputAdapter;
|
||||
|
||||
import com.sun.jna.platform.WindowUtils;
|
||||
|
||||
public class AlphaMaskDemo2 implements Runnable {
|
||||
private static final DataFlavor URL_FLAVOR =
|
||||
new DataFlavor("application/x-java-url; class=java.net.URL", "URL");
|
||||
private static final DataFlavor URI_LIST_FLAVOR =
|
||||
new DataFlavor("text/uri-list; class=java.lang.String", "URI list");
|
||||
private JFrame frame;
|
||||
private JWindow alphaWindow;
|
||||
private JLabel icon;
|
||||
private ImageObserver observer = new ImageObserver() {
|
||||
public boolean imageUpdate(final Image img, int infoflags, int x,
|
||||
int y, int width, int height) {
|
||||
if ((infoflags & (ImageObserver.ALLBITS | ImageObserver.FRAMEBITS)) != 0) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
setImage(img);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
else if ((infoflags & (ImageObserver.ERROR | ImageObserver.ABORT)) != 0) {
|
||||
System.err.println("Image load error: " + img);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
private void setImage(final Image image) {
|
||||
final int w = image.getWidth(observer);
|
||||
final int h = image.getHeight(observer);
|
||||
if (w > 0 && h > 0) {
|
||||
frame.setIconImage(image);
|
||||
icon.setIcon(new ImageIcon(image));
|
||||
if (!alphaWindow.isVisible()) {
|
||||
alphaWindow.pack();
|
||||
alphaWindow.setVisible(true);
|
||||
}
|
||||
else {
|
||||
alphaWindow.setSize(alphaWindow.getPreferredSize());
|
||||
}
|
||||
icon.getParent().invalidate();
|
||||
icon.getParent().repaint();
|
||||
}
|
||||
}
|
||||
|
||||
public void run() {
|
||||
// Must find a graphics configuration with a depth of 32 bits
|
||||
GraphicsConfiguration gconfig = WindowUtils.getAlphaCompatibleGraphicsConfiguration();
|
||||
frame = new JFrame("Alpha Mask Demo");
|
||||
alphaWindow = new JWindow(frame, gconfig);
|
||||
icon = new JLabel();
|
||||
icon.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
alphaWindow.getContentPane().add(icon);
|
||||
JButton quit = new JButton("Quit");
|
||||
JLabel label = new JLabel("Drag this window by its image");
|
||||
label.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
alphaWindow.getContentPane().add(label, BorderLayout.NORTH);
|
||||
alphaWindow.getContentPane().add(quit, BorderLayout.SOUTH);
|
||||
quit.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
MouseInputAdapter handler = new MouseInputAdapter() {
|
||||
private Point offset;
|
||||
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (SwingUtilities.isLeftMouseButton(e))
|
||||
offset = e.getPoint();
|
||||
}
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
offset = null;
|
||||
}
|
||||
|
||||
public void mouseDragged(MouseEvent e) {
|
||||
if (offset != null) {
|
||||
Window w = (Window)e.getSource();
|
||||
Point where = e.getPoint();
|
||||
where.translate(-offset.x, -offset.y);
|
||||
Point loc = w.getLocationOnScreen();
|
||||
loc.translate(where.x, where.y);
|
||||
w.setLocation(loc.x, loc.y);
|
||||
}
|
||||
}
|
||||
};
|
||||
alphaWindow.addMouseListener(handler);
|
||||
alphaWindow.addMouseMotionListener(handler);
|
||||
JPanel p = new JPanel(new BorderLayout(8, 8));
|
||||
p.setBorder(new EmptyBorder(8, 8, 8, 8));
|
||||
p.setTransferHandler(new TransferHandler() {
|
||||
public boolean canImport(JComponent comp,
|
||||
DataFlavor[] transferFlavors) {
|
||||
List list = Arrays.asList(transferFlavors);
|
||||
if (list.contains(URL_FLAVOR) || list.contains(URI_LIST_FLAVOR)
|
||||
|| list.contains(DataFlavor.imageFlavor)
|
||||
|| list.contains(DataFlavor.javaFileListFlavor)) {
|
||||
return true;
|
||||
}
|
||||
if (DataFlavor.selectBestTextFlavor(transferFlavors) != null) {
|
||||
return true;
|
||||
}
|
||||
System.err.println("No acceptable flavor found in "
|
||||
+ Arrays.asList(transferFlavors));
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean importData(JComponent comp, Transferable t) {
|
||||
try {
|
||||
if (t.isDataFlavorSupported(URL_FLAVOR)) {
|
||||
URL url = (URL)t.getTransferData(URL_FLAVOR);
|
||||
setImage(Toolkit.getDefaultToolkit().getImage(url));
|
||||
return true;
|
||||
}
|
||||
if (t.isDataFlavorSupported(URI_LIST_FLAVOR)) {
|
||||
String s = (String)t.getTransferData(URI_LIST_FLAVOR);
|
||||
String[] uris = s.split("[\r\n]");
|
||||
if (uris.length > 0) {
|
||||
URL url = new URL(uris[0]);
|
||||
setImage(Toolkit.getDefaultToolkit().getImage(url));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
|
||||
Image image = (Image)t
|
||||
.getTransferData(DataFlavor.imageFlavor);
|
||||
setImage(image);
|
||||
return true;
|
||||
}
|
||||
if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
|
||||
List files = (List)t
|
||||
.getTransferData(DataFlavor.javaFileListFlavor);
|
||||
File f = (File)files.get(0);
|
||||
URL url = new URL("file://"
|
||||
+ f.toURI().toURL().getPath());
|
||||
Image image = Toolkit.getDefaultToolkit().getImage(url);
|
||||
setImage(image);
|
||||
return true;
|
||||
}
|
||||
DataFlavor flavor = DataFlavor
|
||||
.selectBestTextFlavor(t
|
||||
.getTransferDataFlavors());
|
||||
if (flavor != null) {
|
||||
Reader reader = flavor.getReaderForText(t);
|
||||
char[] buf = new char[512];
|
||||
StringBuffer b = new StringBuffer();
|
||||
int count;
|
||||
// excise excess NUL characters (bug in firefox,
|
||||
// java
|
||||
// or my code, not sure which). someone got the
|
||||
// encoding wrong
|
||||
while ((count = reader.read(buf)) > 0) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (buf[i] != 0)
|
||||
b.append(buf, i, 1);
|
||||
}
|
||||
}
|
||||
String html = b.toString();
|
||||
Pattern p = Pattern
|
||||
.compile(
|
||||
"<img.*src=\"([^\\\"\">]+)\"",
|
||||
Pattern.CANON_EQ
|
||||
| Pattern.UNICODE_CASE);
|
||||
Matcher m = p.matcher(html);
|
||||
if (m.find()) {
|
||||
URL url = new URL(m.group(1));
|
||||
System.out.println("Load image from " + url);
|
||||
Image image = Toolkit.getDefaultToolkit()
|
||||
.getImage(url);
|
||||
setImage(image);
|
||||
return true;
|
||||
}
|
||||
System.err.println("Can't parse text: " + html);
|
||||
return false;
|
||||
}
|
||||
System.err.println("No flavor available: "
|
||||
+ Arrays.asList(t.getTransferDataFlavors()));
|
||||
}
|
||||
catch (UnsupportedFlavorException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
p
|
||||
.add(
|
||||
new JLabel(
|
||||
"<html><center>Drop an image with an alpha channel onto this window<br>"
|
||||
+ "You may also adjust the overall transparency with the slider</center></html>"),
|
||||
BorderLayout.NORTH);
|
||||
p.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||
final JSlider slider = new JSlider(0, 255, 255);
|
||||
slider.addChangeListener(new ChangeListener() {
|
||||
public void stateChanged(ChangeEvent e) {
|
||||
int value = slider.getValue();
|
||||
WindowUtils.setWindowAlpha(alphaWindow, value / 255f);
|
||||
}
|
||||
});
|
||||
p.add(slider, BorderLayout.SOUTH);
|
||||
frame.getContentPane().add(p);
|
||||
frame.pack();
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
centerOnScreen(frame);
|
||||
frame.setVisible(true);
|
||||
WindowUtils.setWindowTransparent(alphaWindow, true);
|
||||
alphaWindow.setLocation(frame.getX() + frame.getWidth() + 4,
|
||||
frame.getY());
|
||||
try {
|
||||
URL url = getClass().getResource("tardis.png");
|
||||
if (url != null) {
|
||||
setImage(Toolkit.getDefaultToolkit().getImage(url));
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
/** Center the given {@link Window} on the default screen. */
|
||||
private static void centerOnScreen(Window window) {
|
||||
Point center = GraphicsEnvironment.getLocalGraphicsEnvironment()
|
||||
.getCenterPoint();
|
||||
Rectangle max = GraphicsEnvironment.getLocalGraphicsEnvironment()
|
||||
.getMaximumWindowBounds();
|
||||
int x = Math.max(center.x - Math.round(window.getWidth() / 2f), max.x);
|
||||
int y = Math.max(center.y - Math.round(window.getHeight() / 2f), max.y);
|
||||
window.setLocation(new Point(x, y));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
System.setProperty("sun.java2d.noddraw", "true");
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
catch (Exception e) {
|
||||
}
|
||||
SwingUtilities.invokeLater(new AlphaMaskDemo2());
|
||||
}
|
||||
}
|
||||
Arquivo binário não exibido.
|
Depois Largura: | Altura: | Tamanho: 18 KiB |
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path=""/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="src" path="/platform"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>balloonmanagerdemo</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,77 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="jnacontrib.balloonmanagerdemo" default="jar" basedir=".">
|
||||
<description>Builds, tests, and runs the project jnacontrib.balloonmanagerdemo.</description>
|
||||
<!-- Locations -->
|
||||
<property name="src" location="."/>
|
||||
<property name="build" location="build"/>
|
||||
<property name="jna-dist" location="../../../dist"/>
|
||||
|
||||
<property name="buildClasses" location="${build}/classes"/>
|
||||
<property name="buildJar" location="${build}/demo-balloonmanager.jar"/>
|
||||
<property name="main-class" value="com.sun.jna.contrib.demo.BalloonManagerDemo" />
|
||||
|
||||
<path id="classpath">
|
||||
<fileset dir="../../../build">
|
||||
<include name="jna.jar"/>
|
||||
</fileset>
|
||||
<fileset dir="../platform/dist">
|
||||
<include name="platform.jar"/>
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<!-- Run Demo. -->
|
||||
<target name="run" depends="compile">
|
||||
<java classname="${main-class}" fork="true">
|
||||
<classpath>
|
||||
<pathelement location="${buildClasses}" />
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<!-- Delete class and jar files. -->
|
||||
<target name="clean">
|
||||
<delete dir="${buildClasses}"/>
|
||||
<delete file="${buildJar}"/>
|
||||
<delete dir="${build}"/>
|
||||
</target>
|
||||
|
||||
<!-- Compile all classes. -->
|
||||
<target name="compile">
|
||||
<mkdir dir="${buildClasses}"/>
|
||||
|
||||
<!-- Compile the project. -->
|
||||
<javac srcdir="${src}" destdir="${buildClasses}" target="1.5" source="1.5" encoding="UTF-8" debug="on">
|
||||
<classpath>
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
<src>
|
||||
<dirset dir="${src}"/>
|
||||
</src>
|
||||
</javac>
|
||||
|
||||
<!-- Copy all non-java files to classes. -->
|
||||
<copy todir="${buildClasses}/com">
|
||||
<fileset dir="${src}/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
<!-- platform -->
|
||||
<fileset dir="../platform/build/classes/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
<!-- jna -->
|
||||
<fileset dir="../../../build/classes/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<!-- Create jar-file. -->
|
||||
<target name="jar" depends="compile">
|
||||
<jar jarfile="${buildJar}" basedir="${buildClasses}">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="${main-class}"/>
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,261 @@
|
||||
/*
|
||||
* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
* Free Software Foundation; either version 2.1 of the License, or (at
|
||||
* your option) any later version. <p/> This library is distributed in
|
||||
* the hope that it will be useful, but WITHOUT ANY WARRANTY; without
|
||||
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
||||
* more details.
|
||||
*/
|
||||
package com.sun.jna.contrib.demo;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GradientPaint;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
import java.awt.Shape;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.geom.AffineTransform;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.GeneralPath;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
|
||||
import javax.swing.Box;
|
||||
import javax.swing.JWindow;
|
||||
import javax.swing.Popup;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import com.sun.jna.platform.WindowUtils;
|
||||
|
||||
/**
|
||||
* Provides a popup balloon containing an arbitrary component. This provides
|
||||
* a form of content-specific decoration less transient than a tooltip, and less
|
||||
* heavyweight and more adaptable to changing content than a dedicated window.
|
||||
* Clients are responsible for invoking show and hide on the provided popup.
|
||||
*/
|
||||
// TODO: anchor balloon point
|
||||
// TODO: connect drop shadow and parent masks
|
||||
// TODO: proper preferred size for html
|
||||
// TODO: lightweight popups
|
||||
public class BalloonManager {
|
||||
|
||||
// Avoid using drop shadow in some instances
|
||||
private static boolean useDropShadow() {
|
||||
return WindowUtils.isWindowAlphaSupported();
|
||||
}
|
||||
|
||||
private static class DropShadow extends JWindow {
|
||||
private static final float SHADOW_ALPHA = .25f;
|
||||
private static final float YSCALE = .80f;
|
||||
private static final double ANGLE = 2*Math.PI/24;
|
||||
private static final Point OFFSET = new Point(8, 8);
|
||||
private static final Color COLOR = new Color(0, 0, 0, 50);
|
||||
|
||||
private Shape parentMask;
|
||||
private ComponentListener listener;
|
||||
public DropShadow(final Window parent, Shape mask) {
|
||||
super(parent);
|
||||
setFocusableWindowState(false);
|
||||
setName("###overrideRedirect###");
|
||||
|
||||
Point where = parent.isShowing()
|
||||
? parent.getLocationOnScreen() : parent.getLocation();
|
||||
setLocation(where.x + OFFSET.x, where.y + OFFSET.y);
|
||||
setBackground(COLOR);
|
||||
getContentPane().setBackground(COLOR);
|
||||
|
||||
parentMask = mask;
|
||||
parent.addComponentListener(listener = new ComponentAdapter() {
|
||||
public void componentMoved(ComponentEvent e) {
|
||||
Point where = getOwner().isShowing()
|
||||
? getOwner().getLocationOnScreen()
|
||||
: getOwner().getLocation();
|
||||
setLocation(where.x + OFFSET.x, where.y + OFFSET.y);
|
||||
}
|
||||
public void componentResized(ComponentEvent e) {
|
||||
Component c = e.getComponent();
|
||||
int extra = c.getWidth() + (int)Math.sin(ANGLE)*c.getHeight();
|
||||
setSize(c.getWidth() + extra, c.getHeight());
|
||||
WindowUtils.setWindowMask(DropShadow.this, getMask());
|
||||
}
|
||||
public void componentShown(ComponentEvent e) {
|
||||
if (!isVisible()) {
|
||||
pack();
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosed(WindowEvent e) {
|
||||
if (listener != null) {
|
||||
parent.removeComponentListener(listener);
|
||||
listener = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
WindowUtils.setWindowMask(DropShadow.this, getMask());
|
||||
WindowUtils.setWindowAlpha(DropShadow.this, SHADOW_ALPHA);
|
||||
if (parent.isVisible()) {
|
||||
pack();
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void paint(Graphics graphics) {
|
||||
Graphics2D g = (Graphics2D)graphics.create();
|
||||
// Workaround for OSX since we only get automatic clipping
|
||||
// on the content pane and below
|
||||
g.setClip(getMask());
|
||||
g.setPaint(new GradientPaint(0, getHeight()/2, new Color(0,0,0,0), getWidth(), getHeight()/2, new Color(0,0,0,255)));
|
||||
g.fillRect(0, 0, getWidth(), getHeight());
|
||||
g.dispose();
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
Dimension size = getOwner().getPreferredSize();
|
||||
size.width += 100;
|
||||
size.height += 100;
|
||||
return size;
|
||||
}
|
||||
|
||||
private Shape getMask() {
|
||||
Area area = new Area(parentMask);
|
||||
Area clip = new Area(parentMask);
|
||||
|
||||
AffineTransform tx = new AffineTransform();
|
||||
tx.translate(Math.sin(ANGLE)*getOwner().getHeight(), 0);
|
||||
tx.shear(-Math.tan(ANGLE), 0);
|
||||
tx.scale(1, YSCALE);
|
||||
tx.translate(0, (1-YSCALE)*getOwner().getHeight());
|
||||
area.transform(tx);
|
||||
tx = new AffineTransform();
|
||||
tx.translate(-OFFSET.x, -OFFSET.y);
|
||||
clip.transform(tx);
|
||||
area.subtract(clip);
|
||||
return area;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class BubbleWindow extends JWindow {
|
||||
private static final int Y_OFFSET = 50;
|
||||
private static final int ARC = 25;
|
||||
|
||||
private Point offset;
|
||||
private Area mask;
|
||||
private Dimension maskSize;
|
||||
private ComponentListener moveTracker = new ComponentAdapter() {
|
||||
public void componentMoved(ComponentEvent e) {
|
||||
Point where =
|
||||
e.getComponent().isShowing()
|
||||
? e.getComponent().getLocationOnScreen()
|
||||
: e.getComponent().getLocation();
|
||||
setLocation(where.x - offset.x, where.y - offset.y);
|
||||
// TODO preserve stacking order (linux)
|
||||
}
|
||||
};
|
||||
|
||||
public BubbleWindow(Window owner, Component content) {
|
||||
super(owner);
|
||||
setFocusableWindowState(false);
|
||||
setName("###overrideRedirect###");
|
||||
getContentPane().setBackground(Color.white);
|
||||
getContentPane().add(content, BorderLayout.CENTER);
|
||||
getContentPane().add(Box.createVerticalStrut(Y_OFFSET), BorderLayout.SOUTH);
|
||||
owner.addComponentListener(moveTracker);
|
||||
setSize(getPreferredSize());
|
||||
mask = new Area(getMask(getWidth(), getHeight()));
|
||||
maskSize = getSize();
|
||||
WindowUtils.setWindowMask(BubbleWindow.this, mask);
|
||||
if (useDropShadow()) {
|
||||
new DropShadow(this, mask);
|
||||
}
|
||||
}
|
||||
|
||||
public void setBounds(int x, int y, int w, int h) {
|
||||
super.setBounds(x, y, w, h);
|
||||
Dimension size = new Dimension(w, h);
|
||||
if (mask != null && !size.equals(maskSize)) {
|
||||
mask.subtract(mask);
|
||||
mask.add(new Area(getMask(w, h)));
|
||||
maskSize = size;
|
||||
}
|
||||
}
|
||||
|
||||
public void setAnchorLocation(int x, int y) {
|
||||
super.setLocation(x, y);
|
||||
Window owner = getOwner();
|
||||
if (owner != null) {
|
||||
Point ref = owner.isShowing()
|
||||
? owner.getLocationOnScreen() : owner.getLocation();
|
||||
offset = new Point(ref.x - x, ref.y - y);
|
||||
}
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
super.dispose();
|
||||
getOwner().removeComponentListener(moveTracker);
|
||||
}
|
||||
|
||||
private Shape getMask(int w, int h) {
|
||||
Shape shape = new RoundRectangle2D.Float(0, 0, w, h-Y_OFFSET,
|
||||
ARC, ARC);
|
||||
Area area = new Area(shape);
|
||||
GeneralPath path = new GeneralPath();
|
||||
path.moveTo(w/3, h-1);
|
||||
path.lineTo(w/2, h-1-Y_OFFSET);
|
||||
path.lineTo(w*2/3, h-1-Y_OFFSET);
|
||||
path.closePath();
|
||||
area.add(new Area(path));
|
||||
return area;
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
Dimension size = super.getPreferredSize();
|
||||
size.height += Y_OFFSET;
|
||||
return size;
|
||||
}
|
||||
}
|
||||
|
||||
/** Get a balloon pointing to the given location. The coordinates are
|
||||
* relative to <code>owner</code>, which if null, indicates the coordinates
|
||||
* are absolute.
|
||||
*/
|
||||
public static Popup getBalloon(final Component owner, final Component content, int x, int y) {
|
||||
|
||||
// Simulate PopupFactory, ensuring we get a heavyweight "popup"
|
||||
final Point origin =
|
||||
owner == null ? new Point(0, 0)
|
||||
: (owner.isShowing()
|
||||
? owner.getLocationOnScreen() : owner.getLocation());
|
||||
final Window parent = owner != null
|
||||
? SwingUtilities.getWindowAncestor(owner) : null;
|
||||
origin.translate(x, y);
|
||||
return new Popup() {
|
||||
private BubbleWindow w;
|
||||
public void show() {
|
||||
w = new BubbleWindow(parent, content);
|
||||
w.pack();
|
||||
Point where = new Point(origin);
|
||||
where.translate(-w.getWidth()/3, -w.getHeight());
|
||||
w.setAnchorLocation(where.x, where.y);
|
||||
w.setVisible(true);
|
||||
}
|
||||
public void hide() {
|
||||
w.setVisible(false);
|
||||
w.dispose();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+136
@@ -0,0 +1,136 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.contrib.demo;
|
||||
|
||||
import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTextArea;
|
||||
import javax.swing.Popup;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
|
||||
import com.sun.jna.platform.WindowUtils;
|
||||
|
||||
/** Demonstration of BalloonManager. */
|
||||
public class BalloonManagerDemo {
|
||||
private static final int ICON_SIZE = 48;
|
||||
private static class InfoIcon implements Icon {
|
||||
public int getIconHeight() {
|
||||
return ICON_SIZE;
|
||||
}
|
||||
public int getIconWidth() {
|
||||
return ICON_SIZE;
|
||||
}
|
||||
public void paintIcon(Component c, Graphics graphics, int x, int y) {
|
||||
Font font = UIManager.getFont("TextField.font");
|
||||
Graphics2D g = (Graphics2D)graphics.create(x, y, getIconWidth(), getIconHeight());
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
|
||||
g.setFont(font.deriveFont(Font.BOLD, getIconWidth()*3/4));
|
||||
g.setColor(Color.green.darker());
|
||||
final int SW = Math.max(getIconWidth()/10, 4);
|
||||
g.setStroke(new BasicStroke(SW));
|
||||
g.drawArc(SW/2, SW/2, getIconWidth()-SW-1, getIconHeight()-SW-1, 0, 360);
|
||||
Rectangle2D bounds =
|
||||
font.getStringBounds("i", g.getFontRenderContext());
|
||||
g.drawString("i", Math.round((getIconWidth() - bounds.getWidth())/2 - getIconWidth()/12),
|
||||
SW/2 + Math.round((getIconHeight()-bounds.getHeight())/2 - bounds.getY() + getIconHeight()/8));
|
||||
g.dispose();
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
System.setProperty("sun.java2d.noddraw", "true");
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
catch(Exception e) {
|
||||
}
|
||||
JFrame f = new JFrame("Balloon Test");
|
||||
final String BALLOON_TEXT = "<html><center>"
|
||||
+ "This is some sample balloon text<br>"
|
||||
+ "which has been formatted with html.<br>"
|
||||
+ "Click to dismiss.</center></html>";
|
||||
final JLabel content = new JLabel(BALLOON_TEXT);
|
||||
content.setIconTextGap(10);
|
||||
content.setBorder(new EmptyBorder(0, 8, 0, 8));
|
||||
content.setSize(content.getPreferredSize());
|
||||
content.setIcon(new InfoIcon());
|
||||
JLabel label = new JLabel("Click anywhere for more information");
|
||||
label.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
label.addMouseListener(new MouseAdapter() {
|
||||
private MouseListener listener = new MouseAdapter() {
|
||||
public void mousePressed(MouseEvent e) {
|
||||
hidePopup(e);
|
||||
}
|
||||
};
|
||||
private Popup popup;
|
||||
private void hidePopup(MouseEvent e) {
|
||||
e.getComponent().removeMouseListener(listener);
|
||||
if (popup != null)
|
||||
popup.hide();
|
||||
}
|
||||
public void mousePressed(MouseEvent e) {
|
||||
hidePopup(e);
|
||||
popup = BalloonManager.getBalloon(e.getComponent(), content, e.getX(), e.getY());
|
||||
popup.show();
|
||||
content.getParent().addMouseListener(listener);
|
||||
}
|
||||
});
|
||||
f.getContentPane().add(label);
|
||||
f.pack();
|
||||
f.setSize(new Dimension(300, 300));
|
||||
f.setLocation(100, 100);
|
||||
try {
|
||||
// Force a load of JNA
|
||||
WindowUtils.setWindowMask(f, WindowUtils.MASK_NONE);
|
||||
f.setVisible(true);
|
||||
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
}
|
||||
catch(UnsatisfiedLinkError e) {
|
||||
e.printStackTrace();
|
||||
String msg = e.getMessage()
|
||||
+ "\nError loading the JNA library";
|
||||
JTextArea area = new JTextArea(msg);
|
||||
area.setOpaque(false);
|
||||
area.setFont(UIManager.getFont("Label.font"));
|
||||
area.setEditable(false);
|
||||
area.setColumns(80);
|
||||
area.setRows(8);
|
||||
area.setWrapStyleWord(true);
|
||||
area.setLineWrap(true);
|
||||
JOptionPane.showMessageDialog(null, new JScrollPane(area),
|
||||
"Library Load Error: "
|
||||
+ System.getProperty("os.name")
|
||||
+ "/" + System.getProperty("os.arch"),
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path=""/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="src" path="/platform"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>balloontips</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
Arquivo executável
+5
@@ -0,0 +1,5 @@
|
||||
Compile the two classes in this directory. Requires Java 1.5+.
|
||||
|
||||
javac -cp examples.jar *.java
|
||||
java -cp .:examples.jar FilteredTextField
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="jnacontrib.balloontipsdemo" default="jar" basedir=".">
|
||||
<description>Builds, tests, and runs the project jnacontrib.balloontipsdemo.</description>
|
||||
<!-- Locations -->
|
||||
<property name="src" location="."/>
|
||||
<property name="build" location="build"/>
|
||||
<property name="jna-dist" location="../../../dist"/>
|
||||
|
||||
<property name="buildClasses" location="${build}/classes"/>
|
||||
<property name="buildJar" location="${build}/demo-balloontips.jar"/>
|
||||
<property name="main-class" value="com.sun.jna.contrib.demo.FilteredTextField" />
|
||||
|
||||
<path id="classpath">
|
||||
<fileset dir="../../../build">
|
||||
<include name="jna.jar"/>
|
||||
</fileset>
|
||||
<fileset dir="../platform/dist">
|
||||
<include name="platform.jar"/>
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<!-- Run Demo. -->
|
||||
<target name="run" depends="compile">
|
||||
<java classname="${main-class}" fork="true">
|
||||
<classpath>
|
||||
<pathelement location="${buildClasses}" />
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<!-- Delete class and jar files. -->
|
||||
<target name="clean">
|
||||
<delete dir="${buildClasses}"/>
|
||||
<delete file="${buildJar}"/>
|
||||
<delete dir="${build}"/>
|
||||
</target>
|
||||
|
||||
<!-- Compile all classes. -->
|
||||
<target name="compile">
|
||||
<mkdir dir="${buildClasses}"/>
|
||||
|
||||
<!-- Compile the project. -->
|
||||
<javac srcdir="${src}" destdir="${buildClasses}" target="1.5" source="1.5" encoding="UTF-8" debug="on">
|
||||
<classpath>
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
<src>
|
||||
<dirset dir="${src}"/>
|
||||
</src>
|
||||
</javac>
|
||||
|
||||
<!-- Copy all non-java files to classes. -->
|
||||
<copy todir="${buildClasses}/com">
|
||||
<fileset dir="${src}/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
<!-- platform -->
|
||||
<fileset dir="../platform/build/classes/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
<!-- jna -->
|
||||
<fileset dir="../../../build/classes/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<!-- Create jar-file. -->
|
||||
<target name="jar" depends="compile">
|
||||
<jar jarfile="${buildJar}" basedir="${buildClasses}">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="${main-class}"/>
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,521 @@
|
||||
package com.sun.jna.contrib.demo;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Point;
|
||||
import java.awt.Polygon;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Shape;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.FocusAdapter;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.geom.Area;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JWindow;
|
||||
import javax.swing.Popup;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.Timer;
|
||||
|
||||
import com.sun.jna.platform.WindowUtils;
|
||||
|
||||
/**
|
||||
* The BalloonTipManager class handles creation and disposal of balloon style
|
||||
* tips that are typically used to display warning/error information based on
|
||||
* results from input validation. The balloon tip location and direction are
|
||||
* computed based on the owner component location on the screen. The balloon
|
||||
* tip is only displayed for a limited amount of time that is configurable.
|
||||
* The balloon tip is also disposed when the owner component loses focus or the
|
||||
* mouse is pressed.
|
||||
*/
|
||||
public class BalloonTipManager {
|
||||
public static final Color DEFAULT_BORDER_COLOR = Color.BLACK;
|
||||
public static final Color DEFAULT_BACKGROUND_COLOR = new Color(255, 255, 225);
|
||||
public static final Color DEFAULT_TEXT_COLOR = Color.BLACK;
|
||||
|
||||
private static final Integer VPOS_ABOVE = 0; // Positioned above component.
|
||||
private static final Integer VPOS_BELOW = 1; // Positioned below component.
|
||||
private static final Integer HPOS_LEFT = 0; // Arrow is on the left side.
|
||||
private static final Integer HPOS_RIGHT = 1; // Arros is on the right side.
|
||||
|
||||
private static Integer vpos = null;
|
||||
private static Integer hpos = null;
|
||||
|
||||
private static Timer hidePopupTimer = null;
|
||||
private static boolean isShowing = false;
|
||||
|
||||
|
||||
/*
|
||||
* The BalloonTip class defines the look of the BalloonTip object.
|
||||
*/
|
||||
private static final class BalloonTip extends JWindow {
|
||||
private static final Integer HMARGIN = 10;
|
||||
private static final Integer VMARGIN = 6;
|
||||
private static final Integer VSPACER = 4;
|
||||
private static final int ARC_D = 16;
|
||||
|
||||
private Area mask = null;
|
||||
private Dimension maskSize = null;
|
||||
private String[] textList = null;
|
||||
|
||||
private Color backgroundColor = null;
|
||||
private Color borderColor = null;
|
||||
private Color textColor = null;
|
||||
|
||||
/**
|
||||
* Create a BalloonTip object.
|
||||
* @param owner the parent window for the components
|
||||
* @param content the string for the balloon tip
|
||||
* @param position the position for the balloon; either above or below the
|
||||
* owner component
|
||||
* @param origin the origin point for the balloon tip
|
||||
* @param bordercolor the background color for the balloon tip
|
||||
* @param backgroundcolor the border color for the balloon tip
|
||||
* @param textcolor the text color for the balloon tip
|
||||
*/
|
||||
public BalloonTip (
|
||||
Window owner, String content, Point origin, Color bordercolor,
|
||||
Color backgroundcolor, Color textcolor)
|
||||
{
|
||||
super(owner);
|
||||
textList = content.split("\n");
|
||||
borderColor = bordercolor;
|
||||
backgroundColor = backgroundcolor;
|
||||
textColor = textcolor;
|
||||
setFocusableWindowState(false);
|
||||
setName("###overrideRedirect###");
|
||||
setSize(getPreferredSize());
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets the mask for the Balloon Tip.
|
||||
*/
|
||||
private void setWindowMask () {
|
||||
mask = new Area(getMask());
|
||||
maskSize = getSize();
|
||||
WindowUtils.setWindowMask(BalloonTip.this, mask);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.awt.Container#paint(java.awt.Graphics)
|
||||
*/
|
||||
public void paint (Graphics g) {
|
||||
super.paint(g);
|
||||
Dimension d = getMinimumWindowSize();
|
||||
int width = d.width + 2 * HMARGIN;
|
||||
int height = d.height + 2 * VMARGIN;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
if (vpos == VPOS_BELOW) {
|
||||
y += 15;
|
||||
}
|
||||
// Draw the filled rounded rectangle and clean up the missed pixels.
|
||||
g.setColor(backgroundColor);
|
||||
g.fillRoundRect(x, y, width, height, ARC_D, ARC_D);
|
||||
g.drawLine(x + 6, y + height - 1, x + 6, y + height - 1);
|
||||
g.drawLine(x + width - 1, y + 6, x + width - 1, y + 6);
|
||||
g.drawLine(x + width - 1, y + height - 6, x + width - 1, y + height - 7);
|
||||
g.drawLine(x + width - 2, y + height - 4, x + width - 4, y + height - 2);
|
||||
g.drawLine(x + width - 6, y + height - 1, x + width - 7, y + height - 1);
|
||||
g.clearRect(x + 2, y + 2, 1, 1);
|
||||
// Draw the border of the rounded rectangle.
|
||||
g.setColor(borderColor);
|
||||
g.drawRoundRect(x, y, width, height, ARC_D, ARC_D);
|
||||
// Draw the external triangle for the balloon.
|
||||
if (vpos == VPOS_BELOW) {
|
||||
if (hpos == HPOS_LEFT) {
|
||||
g.setColor(backgroundColor);
|
||||
int[] xPts = {16, 16, 31};
|
||||
int[] yPts = {0, 16, 16};
|
||||
g.fillPolygon(xPts, yPts, 3);
|
||||
g.setColor(borderColor);
|
||||
g.drawLine(16, 0, 16, 15);
|
||||
g.drawLine(16, 0, 31, 15);
|
||||
g.drawLine(16, 1, 30, 15);
|
||||
}
|
||||
else {
|
||||
g.setColor(backgroundColor);
|
||||
int[] xPts = {width - 16, width - 16, width - 31};
|
||||
int[] yPts = {0, 16, 16};
|
||||
g.fillPolygon(xPts, yPts, 3);
|
||||
g.setColor(borderColor);
|
||||
g.drawLine(width - 16, 0, width - 16, 15);
|
||||
g.drawLine(width - 16, 0, width - 31, 15);
|
||||
g.drawLine(width - 16, 1, width - 30, 15);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (hpos == HPOS_LEFT) {
|
||||
g.setColor(backgroundColor);
|
||||
int[] xPts = {16, 16, 31};
|
||||
int[] yPts = {height, height + 16, height};
|
||||
g.fillPolygon(xPts, yPts, 3);
|
||||
g.setColor(borderColor);
|
||||
g.drawLine(16, height, 16, height + 15);
|
||||
g.drawLine(16, height + 15, 31, height);
|
||||
g.drawLine(16, height + 14, 30, height);
|
||||
}
|
||||
else {
|
||||
g.setColor(backgroundColor);
|
||||
int[] xPts = {width - 16, width - 16, width - 31};
|
||||
int[] yPts = {height, height + 16, height};
|
||||
g.fillPolygon(xPts, yPts, 3);
|
||||
g.setColor(borderColor);
|
||||
g.drawLine(width - 16, height, width - 16, height + 15);
|
||||
g.drawLine(width - 16, height + 15, width - 31, height);
|
||||
g.drawLine(width - 16, height + 14, width - 30, height);
|
||||
}
|
||||
}
|
||||
// Draw the inner component for the balloon.
|
||||
g.setColor(textColor);
|
||||
g.setFont(new Font("Tahoma", Font.PLAIN, 11));
|
||||
int stringY = y + VMARGIN / 2;
|
||||
for (int i = 0; i < textList.length; i++) {
|
||||
stringY += new JLabel(textList[i]).getPreferredSize().height;
|
||||
if (i > 0) {
|
||||
stringY += VSPACER;
|
||||
}
|
||||
g.drawString(textList[i], HMARGIN, stringY);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the mask for the balloon tip window.
|
||||
*/
|
||||
private Shape getMask () {
|
||||
Dimension d = getMinimumWindowSize();
|
||||
int width = d.width + 2 * HMARGIN;
|
||||
int height = d.height + 2 * VMARGIN;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
if (vpos == VPOS_BELOW) {
|
||||
y += 15;
|
||||
}
|
||||
// Start by creating the area of the main rounded rectangle.
|
||||
Area area = new Area(
|
||||
new RoundRectangle2D.Float(x, y, width + 1, height + 1, ARC_D, ARC_D));
|
||||
// Add in the remaining pixels that are not included by default due to
|
||||
// the differences between Graphics drawing and Shape creation.
|
||||
area.add(new Area(new Rectangle(0, y + 6, 1, 2)));
|
||||
area.add(new Area(new Rectangle(0, y + height - 7, 1, 2)));
|
||||
area.add(new Area(new Rectangle(1, y + 4, 1, 1)));
|
||||
area.add(new Area(new Rectangle(1, y + height - 5, 1, 2)));
|
||||
area.add(new Area(new Rectangle(4, y + 1, 1, 1)));
|
||||
area.add(new Area(new Rectangle(6, y, 2, 1)));
|
||||
area.add(new Area(new Rectangle(width - 7, y, 2, 1)));
|
||||
// Subtract the extra pixels that are not included by default due to the
|
||||
// differences between Graphics drawing and Shape creation.
|
||||
area.subtract(new Area(new Rectangle(2, y + height - 2, 1, 1)));
|
||||
area.subtract(new Area(new Rectangle(3, y + height - 1, 1, 1)));
|
||||
area.subtract(new Area(new Rectangle(5, y + height, 1, 1)));
|
||||
area.subtract(new Area(new Rectangle(width - 5, y + height, 2, 1)));
|
||||
area.subtract(new Area(new Rectangle(width - 3, y + height - 1, 2, 1)));
|
||||
area.subtract(new Area(new Rectangle(width - 2, y + 2, 1, 1)));
|
||||
area.subtract(new Area(new Rectangle(width - 2, y + height - 2, 2, 1)));
|
||||
area.subtract(new Area(new Rectangle(width - 1, y + 3, 1, 1)));
|
||||
area.subtract(new Area(new Rectangle(width - 1, y + height - 3, 1, 1)));
|
||||
area.subtract(new Area(new Rectangle(width, y + 5, 1, 1)));
|
||||
area.subtract(new Area(new Rectangle(width, y + height - 5, 1, 2)));
|
||||
// Add in the triangle piece for the balloon.
|
||||
if (vpos == VPOS_BELOW) {
|
||||
if (hpos == HPOS_LEFT) {
|
||||
int[] xPts = {16, 16, 32};
|
||||
int[] yPts = {-1, 16, 16};
|
||||
area.add(new Area(new Polygon(xPts, yPts, 3)));
|
||||
}
|
||||
else {
|
||||
int[] xPts = {width - 15, width - 15, width - 32};
|
||||
int[] yPts = {-1, 16, 16};
|
||||
area.add(new Area(new Polygon(xPts, yPts, 3)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (hpos == HPOS_LEFT) {
|
||||
int[] xPts = {16, 16, 31};
|
||||
int[] yPts = {height, height + 16, height};
|
||||
area.add(new Area(new Polygon(xPts, yPts, 3)));
|
||||
}
|
||||
else {
|
||||
int[] xPts = {width - 15, width - 15, width - 32};
|
||||
int[] yPts = {height, height + 16, height};
|
||||
area.add(new Area(new Polygon(xPts, yPts, 3)));
|
||||
}
|
||||
}
|
||||
return area;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the dimension of the window based on the preferred component
|
||||
* sizes.
|
||||
*/
|
||||
private Dimension getMinimumWindowSize () {
|
||||
int maxWidth = 0;
|
||||
int textHeight = 0;
|
||||
JLabel tempLabel = null;
|
||||
for (int i = 0; i < textList.length; i++) {
|
||||
tempLabel = new JLabel(textList[i]);
|
||||
maxWidth = Math.max(maxWidth, tempLabel.getPreferredSize().width);
|
||||
textHeight += tempLabel.getPreferredSize().height;
|
||||
}
|
||||
int w = Math.max(maxWidth, 32);
|
||||
int h = Math.max(textHeight + (textList.length - 1) * VSPACER, 8);
|
||||
return new Dimension(w, h);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.awt.Window#setBounds(int, int, int, int)
|
||||
*/
|
||||
public void setBounds (int x, int y, int w, int h) {
|
||||
super.setBounds(x, y, w, h);
|
||||
Dimension size = new Dimension(w, h);
|
||||
if (mask != null && !size.equals(maskSize)) {
|
||||
mask.subtract(mask);
|
||||
mask.add(new Area(getMask()));
|
||||
maskSize = size;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.awt.Container#getPreferredSize()
|
||||
*/
|
||||
public Dimension getPreferredSize () {
|
||||
Dimension d = getMinimumWindowSize();
|
||||
int w = d.width + 2 * HMARGIN + 1;
|
||||
int h = d.height + 2 * VMARGIN + 16;
|
||||
return new Dimension(w, h);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the popup window of the balloon tip.
|
||||
* @param owner the owner component for the balloon tip
|
||||
* @param content the text string to display in the balloon tip
|
||||
* @param x the x coordinate for the origin for the balloon tip in relation
|
||||
* to the owner component
|
||||
* @param y the y coordinate for the origin for the balloon tip in relation
|
||||
* to the owner component
|
||||
* @param position the position for the balloon; either above or below the
|
||||
* owner component
|
||||
* @param duration the duration in milliseconds to display balloon tip
|
||||
* @return the popup window of the balloon tip
|
||||
*/
|
||||
public static Popup getBalloonTip (final Component owner,
|
||||
final String content, int x, int y, final int duration)
|
||||
{
|
||||
return getBalloonTip(owner, content, x, y, duration, DEFAULT_BORDER_COLOR,
|
||||
DEFAULT_BACKGROUND_COLOR, DEFAULT_TEXT_COLOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the popup is showing or not.
|
||||
* @return true if the popup is showing, else false
|
||||
*/
|
||||
public static boolean isShowing () {
|
||||
return isShowing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restarts the popup timer.
|
||||
*/
|
||||
public static void restartTimer () {
|
||||
hidePopupTimer.restart();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the popup window of the balloon tip.
|
||||
* @param owner the owner component for the balloon tip
|
||||
* @param content the text string to display in the balloon tip
|
||||
* @param x the x coordinate for the origin for the balloon tip in relation
|
||||
* to the owner component
|
||||
* @param y the y coordinate for the origin for the balloon tip in relation
|
||||
* to the owner component
|
||||
* @param position the position for the balloon; either above or below the
|
||||
* owner component
|
||||
* @param duration the duration in milliseconds to display balloon tip
|
||||
* @param bordercolor the background color for the balloon tip
|
||||
* @param backgroundcolor the border color for the balloon tip
|
||||
* @param textcolor the text color for the balloon tip
|
||||
* @return the popup window of the balloon tip
|
||||
*/
|
||||
public static Popup getBalloonTip (final Component owner,
|
||||
final String content, int x, int y, final Integer duration,
|
||||
final Color bordercolor, final Color backgroundcolor,
|
||||
final Color textcolor)
|
||||
{
|
||||
final Point origin =
|
||||
owner == null ? new Point(0, 0) : owner.getLocationOnScreen();
|
||||
final Window parent =
|
||||
owner != null ? SwingUtilities.getWindowAncestor(owner) : null;
|
||||
final String text =
|
||||
content != null ? content : "";
|
||||
final Integer timerDuration =
|
||||
duration != null ? duration : 10000;
|
||||
origin.translate(x, y);
|
||||
vpos = VPOS_BELOW;
|
||||
hpos = HPOS_LEFT;
|
||||
return new Popup () {
|
||||
private BalloonTip bt = null;
|
||||
final ComponentEar componentEar = new ComponentEar();
|
||||
final MouseEar mouseEar = new MouseEar();
|
||||
final FocusEar focusEar = new FocusEar();
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see javax.swing.Popup#show()
|
||||
*/
|
||||
public void show () {
|
||||
hidePopupTimer = new Timer(timerDuration, new TimerAction());
|
||||
bt = new BalloonTip(parent, text, origin, bordercolor,
|
||||
backgroundcolor, textcolor);
|
||||
bt.pack();
|
||||
Point pt = new Point(origin);
|
||||
pt.translate(10, owner.getHeight());
|
||||
bt.setLocation(getAdjustedOrigin(pt));
|
||||
bt.setWindowMask();
|
||||
bt.setVisible(true);
|
||||
owner.addFocusListener(focusEar);
|
||||
owner.addMouseListener(mouseEar);
|
||||
parent.addMouseListener(mouseEar);
|
||||
parent.addComponentListener(componentEar);
|
||||
hidePopupTimer.start();
|
||||
isShowing = true;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see javax.swing.Popup#hide()
|
||||
*/
|
||||
public void hide () {
|
||||
if (bt != null) {
|
||||
isShowing = false;
|
||||
hidePopupTimer.stop();
|
||||
parent.removeComponentListener(componentEar);
|
||||
parent.removeMouseListener(mouseEar);
|
||||
owner.removeMouseListener(mouseEar);
|
||||
owner.removeFocusListener(focusEar);
|
||||
bt.setVisible(false);
|
||||
bt.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Adjust the location of the balloon popup so that is drawn completely
|
||||
* on the screen and specify the orientation.
|
||||
*/
|
||||
private Point getAdjustedOrigin (Point pt) {
|
||||
Point ret = new Point(pt.x, pt.y);
|
||||
GraphicsConfiguration gc = owner.getGraphicsConfiguration();
|
||||
Rectangle sBounds = gc.getBounds();
|
||||
Insets sInsets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
|
||||
sBounds.x += sInsets.left;
|
||||
sBounds.y += sInsets.top;
|
||||
sBounds.width -= (sInsets.left + sInsets.right);
|
||||
sBounds.height -= (sInsets.top + sInsets.bottom);
|
||||
|
||||
if (ret.x < sBounds.x) {
|
||||
ret.x = sBounds.x;
|
||||
}
|
||||
else if (ret.x - sBounds.x + bt.getWidth() > sBounds.width) {
|
||||
ret.x = owner.getLocationOnScreen().x - bt.getWidth() + 43;
|
||||
}
|
||||
if (ret.x >= pt.x) {
|
||||
hpos = HPOS_LEFT;
|
||||
}
|
||||
else {
|
||||
hpos = HPOS_RIGHT;
|
||||
}
|
||||
|
||||
if (ret.y < sBounds.y) {
|
||||
ret.y = sBounds.y;
|
||||
}
|
||||
else if (ret.y - sBounds.y + bt.getHeight() > sBounds.height) {
|
||||
ret.y = owner.getLocationOnScreen().y - bt.getHeight();
|
||||
}
|
||||
if (ret.y >= pt.y) {
|
||||
vpos = VPOS_BELOW;
|
||||
}
|
||||
else {
|
||||
vpos = VPOS_ABOVE;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* This class handles actions from the balloon tip timer.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
final class TimerAction extends AbstractAction {
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.awt.event.ActionListener#actionPerformed(
|
||||
* java.awt.event.ActionEvent)
|
||||
*/
|
||||
public void actionPerformed (ActionEvent e) {
|
||||
hide();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This class handles events spawned from moving the component.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
final class ComponentEar extends ComponentAdapter {
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.awt.event.ComponentAdapter#componentMoved(
|
||||
* java.awt.event.ComponentEvent)
|
||||
*/
|
||||
public void componentMoved (ComponentEvent e) {
|
||||
hide();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This class handles events spawned when a mouse button is pressed.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
final class MouseEar extends MouseAdapter {
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.awt.event.MouseAdapter#mousePressed(
|
||||
* java.awt.event.MouseEvent)
|
||||
*/
|
||||
public void mousePressed (MouseEvent e) {
|
||||
hide();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This class handles events spawned when the component loses focus.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
final class FocusEar extends FocusAdapter {
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.awt.event.FocusAdapter#focusLost(
|
||||
* java.awt.event.FocusEvent)
|
||||
*/
|
||||
public void focusLost (FocusEvent e) {
|
||||
hide();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,422 @@
|
||||
package com.sun.jna.contrib.demo;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Color;
|
||||
import java.awt.event.FocusAdapter;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.Popup;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
import javax.swing.text.AttributeSet;
|
||||
import javax.swing.text.BadLocationException;
|
||||
import javax.swing.text.Document;
|
||||
import javax.swing.text.PlainDocument;
|
||||
//TODO: FilteredTextField - Comment this class.
|
||||
/**
|
||||
* The FilteredTextField class is a JTextField that only allows specified
|
||||
* characters to be entered into it. The allowed characters can be added to
|
||||
* the text field, and entry validation is performed as each character is
|
||||
* typed. In addition, complete string validation is tested against a
|
||||
* configurable regular expression when leaving the field. If the string is
|
||||
* invalid the text field is bordered with a red line, and the user is notified
|
||||
* of the error upon returning to the text field. The text field can also be
|
||||
* configured to accept a limited number of characters.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class FilteredTextField extends JTextField {
|
||||
public static final Character[] UPPERCASE_CHARS = {'A', 'B', 'C', 'D', 'E',
|
||||
'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
|
||||
'U', 'V', 'W', 'X', 'Y', 'Z'};
|
||||
public static final Character[] LOWERCASE_CHARS = {'a', 'b', 'c', 'd', 'e',
|
||||
'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
|
||||
'u', 'v', 'w', 'x', 'y', 'z'};
|
||||
public static final Character[] NUMERIC_CHARS = {'1', '2', '3', '4', '5',
|
||||
'6', '7', '8', '9', '0'};
|
||||
|
||||
private static final Integer ENTRY_BALLOON = 0;
|
||||
private static final Integer VALID_BALLOON = 1;
|
||||
private static final Integer LENGTH_BALLOON = 2;
|
||||
private static final Border RED_BORDER =
|
||||
BorderFactory.createLineBorder(Color.RED, 2);
|
||||
|
||||
private ArrayList<Character> allowable = new ArrayList<Character>();
|
||||
private int maximumLength = String.valueOf(Long.MAX_VALUE).length();
|
||||
|
||||
private Border defaultBorder = null;
|
||||
private boolean isValid = true;
|
||||
|
||||
private Popup balloon = null;
|
||||
private String entryError = null;
|
||||
private String validRegex = null;
|
||||
private String validError = null;
|
||||
private Color balloonBorderColor = null;
|
||||
private Color balloonBackgroundColor = null;
|
||||
private Color balloonTextColor = null;
|
||||
private Integer balloonDuration = null;
|
||||
|
||||
private Integer balloonType = null;
|
||||
|
||||
/**
|
||||
* Create a FilteredTextField.
|
||||
*/
|
||||
public FilteredTextField () {
|
||||
super();
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a FilteredTextField.
|
||||
* @param columns the number of columns to use to calculate the preferred
|
||||
* width
|
||||
*/
|
||||
public FilteredTextField (int columns) {
|
||||
super(columns);
|
||||
init();
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the FilteredTextField.
|
||||
*/
|
||||
private void init () {
|
||||
defaultBorder = getBorder();
|
||||
entryError = "";
|
||||
validRegex = "";
|
||||
validError = "";
|
||||
balloonBorderColor = BalloonTipManager.DEFAULT_BORDER_COLOR;
|
||||
balloonBackgroundColor = BalloonTipManager.DEFAULT_BACKGROUND_COLOR;
|
||||
balloonTextColor = BalloonTipManager.DEFAULT_TEXT_COLOR;
|
||||
balloonDuration = 10000;
|
||||
balloonType = ENTRY_BALLOON;
|
||||
addFocusListener(new ValidationEar());
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the allowable character used for entry validation.
|
||||
* @param characters the allowable characters
|
||||
*/
|
||||
public void setCharacters (Character[] characters) {
|
||||
clearCharacters();
|
||||
for (int i = 0; i < characters.length; i++) {
|
||||
addCharacter(characters[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the character array to the list used for entry validation.
|
||||
* @param characters the character array
|
||||
*/
|
||||
public void addCharacters (Character[] characters) {
|
||||
for (int i = 0; i < characters.length; i++) {
|
||||
addCharacter(characters[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the character to the list used for entry validation.
|
||||
* @param characters the character
|
||||
*/
|
||||
public void addCharacter (Character character) {
|
||||
if (!allowable.contains(character)) {
|
||||
allowable.add(character);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the list of allowable characters for entry validation.
|
||||
*/
|
||||
public void clearCharacters () {
|
||||
allowable.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the character array from the list used for entry validation.
|
||||
* @param characters the character array
|
||||
*/
|
||||
public void removeCharacters (Character[] characters) {
|
||||
for (int i = 0; i < characters.length; i++) {
|
||||
removeCharacter(characters[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the character from the list used for entry validation.
|
||||
* @param character the character
|
||||
*/
|
||||
public void removeCharacter (Character character) {
|
||||
if (allowable.contains(character)) {
|
||||
allowable.remove(character);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the maximum number of characters for the length of the entry string.
|
||||
* @param maximumLength the number of characters
|
||||
*/
|
||||
public void setMaximumLength (int maximumLength) {
|
||||
this.maximumLength = maximumLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the message that is displayed when there is an entry error.
|
||||
* @param entryError the entry error message
|
||||
*/
|
||||
public void setEntryError (String entryError) {
|
||||
this.entryError = entryError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the regular expression that is used for string validation. String
|
||||
* validation is checked when exiting the text field.
|
||||
* @param validRegex the validation regular expression
|
||||
*/
|
||||
public void setValidRegex (String validRegex) {
|
||||
this.validRegex = validRegex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the message that is displayed when there is a validation error.
|
||||
* @param validError the validation error message
|
||||
*/
|
||||
public void setValidError (String validError) {
|
||||
this.validError = validError;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color to use for the balloon border.
|
||||
* @param borderColor the balloon border color
|
||||
*/
|
||||
public void setBalloonBorderColor (Color borderColor) {
|
||||
balloonBorderColor = borderColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color to use for the balloon background.
|
||||
* @param backgroundColor the balloon background color
|
||||
*/
|
||||
public void setBalloonBackgroundColor (Color backgroundColor) {
|
||||
balloonBackgroundColor = backgroundColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the color to use for the balloon text.
|
||||
* @param textColor the balloon text color
|
||||
*/
|
||||
public void setBalloonTextColor (Color textColor) {
|
||||
balloonTextColor = textColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the time in milliseconds that the balloon is visible before
|
||||
* disappearing. This is the maximum time that the balloon will be visible,
|
||||
* as other events can also make the balloon disappear.
|
||||
* @param duration the time in milliseconds
|
||||
*/
|
||||
public void setBalloonDuration (Integer duration) {
|
||||
balloonDuration = duration;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see javax.swing.JTextField#createDefaultModel()
|
||||
*/
|
||||
protected Document createDefaultModel () {
|
||||
return new FilteredTextFieldDocument();
|
||||
}
|
||||
|
||||
/*
|
||||
* This class defines the document used for the FilteredTextField.
|
||||
*/
|
||||
private class FilteredTextFieldDocument extends PlainDocument {
|
||||
/*
|
||||
* Create a FilteredTextFieldDocument.
|
||||
*/
|
||||
public FilteredTextFieldDocument () {
|
||||
addDocumentListener(new FilteredTextFieldEar());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see javax.swing.text.PlainDocument#insertString(
|
||||
* int, java.lang.String, javax.swing.text.AttributeSet)
|
||||
*/
|
||||
public void insertString (int offset, String str, AttributeSet a)
|
||||
throws BadLocationException
|
||||
{
|
||||
if (balloon != null && BalloonTipManager.isShowing()) {
|
||||
if (balloonType == VALID_BALLOON) {
|
||||
balloon.hide();
|
||||
}
|
||||
}
|
||||
StringBuffer buffer =
|
||||
new StringBuffer(FilteredTextField.this.getText());
|
||||
if (offset >= 0 && offset <= buffer.length()) {
|
||||
buffer.insert(offset, str);
|
||||
String strBuf = buffer.toString();
|
||||
|
||||
if (buffer.length() > maximumLength) {
|
||||
if (balloon != null && BalloonTipManager.isShowing()) {
|
||||
if (balloonType == LENGTH_BALLOON) {
|
||||
BalloonTipManager.restartTimer();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
balloon.hide();
|
||||
}
|
||||
}
|
||||
balloon = BalloonTipManager.getBalloonTip(FilteredTextField.this,
|
||||
"The number of characters must be less than or equal to " +
|
||||
maximumLength, 0, 0, balloonDuration, balloonBorderColor,
|
||||
balloonBackgroundColor, balloonTextColor);
|
||||
balloon.show();
|
||||
balloonType = LENGTH_BALLOON;
|
||||
return;
|
||||
}
|
||||
|
||||
if (strBuf == null || strBuf.equals("")) {
|
||||
remove(0, getLength());
|
||||
super.insertString(0, "", null);
|
||||
if (balloon != null && BalloonTipManager.isShowing()) {
|
||||
balloon.hide();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (allowable.contains(str.charAt(0))) {
|
||||
super.insertString(offset, str, a);
|
||||
if (balloon != null && BalloonTipManager.isShowing()) {
|
||||
balloon.hide();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (balloon != null && BalloonTipManager.isShowing()) {
|
||||
if (balloonType == ENTRY_BALLOON) {
|
||||
BalloonTipManager.restartTimer();
|
||||
return;
|
||||
}
|
||||
else {
|
||||
balloon.hide();
|
||||
}
|
||||
}
|
||||
balloon = BalloonTipManager.getBalloonTip(FilteredTextField.this,
|
||||
entryError, 0, 0, balloonDuration, balloonBorderColor,
|
||||
balloonBackgroundColor, balloonTextColor);
|
||||
balloon.show();
|
||||
balloonType = ENTRY_BALLOON;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This listener class is needed to catch character removal events.
|
||||
*/
|
||||
private class FilteredTextFieldEar implements DocumentListener {
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see javax.swing.event.DocumentListener#insertUpdate(
|
||||
* javax.swing.event.DocumentEvent)
|
||||
*/
|
||||
public void insertUpdate (DocumentEvent e) {/* N/A */}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see javax.swing.event.DocumentListener#removeUpdate(
|
||||
* javax.swing.event.DocumentEvent)
|
||||
*/
|
||||
public void removeUpdate (DocumentEvent e) {
|
||||
if (balloon != null && BalloonTipManager.isShowing())
|
||||
{
|
||||
balloon.hide();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see javax.swing.event.DocumentListener#changedUpdate(
|
||||
* javax.swing.event.DocumentEvent)
|
||||
*/
|
||||
public void changedUpdate (DocumentEvent e) {/* N/A */}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This listener class is used to determine whether the string is valid based
|
||||
* on a regular expression. The validation is tested when leaving the text
|
||||
* field, and notification is performed when returning to the text field.
|
||||
*/
|
||||
private class ValidationEar extends FocusAdapter {
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.awt.event.FocusAdapter#focusLost(java.awt.event.FocusEvent)
|
||||
*/
|
||||
public void focusLost (FocusEvent e) {
|
||||
String entered = getText().trim();
|
||||
if (!entered.matches(validRegex)) {
|
||||
if (balloon != null) {
|
||||
balloon.hide();
|
||||
}
|
||||
setBorder(
|
||||
BorderFactory.createCompoundBorder(RED_BORDER, defaultBorder));
|
||||
isValid = false;
|
||||
}
|
||||
else {
|
||||
setBorder(defaultBorder);
|
||||
isValid = true;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.awt.event.FocusAdapter#focusGained(java.awt.event.FocusEvent)
|
||||
*/
|
||||
public void focusGained (FocusEvent e) {
|
||||
if (!isValid) {
|
||||
balloon = BalloonTipManager.getBalloonTip(FilteredTextField.this,
|
||||
validError, 0, 0, balloonDuration, balloonBorderColor,
|
||||
balloonBackgroundColor, balloonTextColor);
|
||||
balloon.show();
|
||||
balloonType = VALID_BALLOON;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* A main entry point to test the FilteredTextField.
|
||||
* @param args application arguments
|
||||
*/
|
||||
public static void main (String[] args) {
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
JFrame jframe = new JFrame("FilteredTextField Test");
|
||||
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
jframe.setSize(400, 75);
|
||||
jframe.setLocation(400, 400);
|
||||
JPanel jpanel = new JPanel();
|
||||
jpanel.setLayout(new BorderLayout());
|
||||
FilteredTextField ftfield = new FilteredTextField(10);
|
||||
ftfield.setCharacters(LOWERCASE_CHARS);
|
||||
ftfield.addCharacter('-');
|
||||
ftfield.addCharacter('_');
|
||||
ftfield.addCharacter(' ');
|
||||
ftfield.setMaximumLength(10);
|
||||
ftfield.setEntryError(
|
||||
"Only lower case letters, hyphens, underscores, and spaces allowed.");
|
||||
ftfield.setValidRegex("^a+[a-z-_ ]*");
|
||||
ftfield.setValidError("The string must begin with the letter 'a'.");
|
||||
jpanel.add(ftfield, BorderLayout.CENTER);
|
||||
jpanel.add(new FilteredTextField(10), BorderLayout.SOUTH);
|
||||
jframe.getContentPane().add(jpanel);
|
||||
jframe.setVisible(true);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path=""/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="/jna/dist/jna.jar"/>
|
||||
<classpathentry kind="src" path="/platform"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>dnddemo</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,77 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="jnacontrib.dnddemo" default="jar" basedir=".">
|
||||
<description>Builds, tests, and runs the project jnacontrib.dnddemo.</description>
|
||||
<!-- Locations -->
|
||||
<property name="src" location="."/>
|
||||
<property name="build" location="build"/>
|
||||
<property name="jna-dist" location="../../../dist"/>
|
||||
|
||||
<property name="buildClasses" location="${build}/classes"/>
|
||||
<property name="buildJar" location="${build}/demo-dnd.jar"/>
|
||||
<property name="main-class" value="com.sun.jna.contrib.demo.GhostedDragImageDemo" />
|
||||
|
||||
<path id="classpath">
|
||||
<fileset dir="../../../build">
|
||||
<include name="jna.jar"/>
|
||||
</fileset>
|
||||
<fileset dir="../platform/dist">
|
||||
<include name="platform.jar"/>
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<!-- Run Demo. -->
|
||||
<target name="run" depends="compile">
|
||||
<java classname="${main-class}" fork="true">
|
||||
<classpath>
|
||||
<pathelement location="${buildClasses}" />
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<!-- Delete class and jar files. -->
|
||||
<target name="clean">
|
||||
<delete dir="${buildClasses}"/>
|
||||
<delete file="${buildJar}"/>
|
||||
<delete dir="${build}"/>
|
||||
</target>
|
||||
|
||||
<!-- Compile all classes. -->
|
||||
<target name="compile">
|
||||
<mkdir dir="${buildClasses}"/>
|
||||
|
||||
<!-- Compile the project. -->
|
||||
<javac srcdir="${src}" destdir="${buildClasses}" target="1.5" source="1.5" encoding="UTF-8" debug="on">
|
||||
<classpath>
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
<src>
|
||||
<dirset dir="${src}"/>
|
||||
</src>
|
||||
</javac>
|
||||
|
||||
<!-- Copy all non-java files to classes. -->
|
||||
<copy todir="${buildClasses}/com">
|
||||
<fileset dir="${src}/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
<!-- platform -->
|
||||
<fileset dir="../platform/build/classes/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
<!-- jna -->
|
||||
<fileset dir="../../../build/classes/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<!-- Create jar-file. -->
|
||||
<target name="jar" depends="compile">
|
||||
<jar jarfile="${buildJar}" basedir="${buildClasses}">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="${main-class}"/>
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,139 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.contrib.demo;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
import java.awt.datatransfer.ClipboardOwner;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.awt.dnd.DnDConstants;
|
||||
import java.awt.dnd.DragGestureEvent;
|
||||
import java.awt.dnd.DragSourceDropEvent;
|
||||
import java.awt.dnd.DropTargetDropEvent;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import com.sun.jna.platform.dnd.DragHandler;
|
||||
import com.sun.jna.platform.dnd.DropHandler;
|
||||
|
||||
|
||||
/** Demonstrate ghosted drag images. Unfortunately, Swing drag support hides
|
||||
* the hooks we need to move the drag image around, so we don't use it and
|
||||
* roll our own.
|
||||
*/
|
||||
public class GhostedDragImageDemo {
|
||||
|
||||
public static class ImageSelection implements Transferable, ClipboardOwner {
|
||||
public static final DataFlavor IMAGE_FLAVOR = DataFlavor.imageFlavor;
|
||||
private static final DataFlavor[] FLAVORS = { IMAGE_FLAVOR };
|
||||
|
||||
private Image image;
|
||||
public ImageSelection(Image image) {
|
||||
this.image = image;
|
||||
}
|
||||
public void lostOwnership(Clipboard clipboard, Transferable transferable) {
|
||||
// don't care
|
||||
}
|
||||
public Object getTransferData(DataFlavor flavor) {
|
||||
return isDataFlavorSupported(flavor) ? image : null;
|
||||
}
|
||||
public DataFlavor[] getTransferDataFlavors() { return FLAVORS; }
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||
return flavor.equals(IMAGE_FLAVOR);
|
||||
}
|
||||
}
|
||||
|
||||
public static class DragLabel extends JLabel {
|
||||
private boolean dragging;
|
||||
public DragLabel(Icon icon) {
|
||||
super(icon);
|
||||
new DragHandler(this, DnDConstants.ACTION_COPY_OR_MOVE) {
|
||||
protected Icon getDragIcon(DragGestureEvent e, Point imageOffset) {
|
||||
dragging = true;
|
||||
return getIcon();
|
||||
}
|
||||
public void dragDropEnd(DragSourceDropEvent e) {
|
||||
super.dragDropEnd(e);
|
||||
if (e.getDropSuccess() && getDropAction(e) == MOVE) {
|
||||
if (dragging) {
|
||||
setIcon(null);
|
||||
dragging = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
protected Transferable getTransferable(DragGestureEvent e) {
|
||||
ImageIcon icon = (ImageIcon)getIcon();
|
||||
if (icon != null) {
|
||||
return new ImageSelection(icon.getImage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
};
|
||||
DataFlavor[] flavors = new DataFlavor[] { DataFlavor.imageFlavor };
|
||||
new DropHandler(this, DnDConstants.ACTION_COPY_OR_MOVE, flavors) {
|
||||
protected void drop(DropTargetDropEvent e, int action) throws UnsupportedFlavorException, IOException {
|
||||
final Image image = (Image)e.getTransferable().getTransferData(DataFlavor.imageFlavor);
|
||||
dragging = false;
|
||||
setIcon(new ImageIcon(image));
|
||||
}
|
||||
};
|
||||
}
|
||||
public void setIcon(Icon icon) {
|
||||
super.setIcon(icon);
|
||||
if (icon == null) {
|
||||
setText("Empty");
|
||||
}
|
||||
else {
|
||||
setText(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
System.setProperty("sun.java2d.noddraw", "true");
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
JFrame f1 = new JFrame("Drag this");
|
||||
JFrame f2 = new JFrame("Over here");
|
||||
URL url = GhostedDragImageDemo.class.getResource("toucan.png");
|
||||
if (url == null)
|
||||
throw new RuntimeException("Icon not found");
|
||||
Icon icon = new ImageIcon(url);
|
||||
f1.getContentPane().add(new DragLabel(icon));
|
||||
JLabel label2 = new DragLabel(icon);
|
||||
f2.getContentPane().add(label2);
|
||||
f1.setLocation(100, 100);
|
||||
f1.pack();
|
||||
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
f2.setLocation(300, 100);
|
||||
f2.pack();
|
||||
label2.setIcon(null);
|
||||
f2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
f2.setVisible(true);
|
||||
f1.setVisible(true);
|
||||
}
|
||||
catch(Throwable t){
|
||||
t.printStackTrace();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Arquivo binário não exibido.
|
Depois Largura: | Altura: | Tamanho: 28 KiB |
@@ -0,0 +1,13 @@
|
||||
<html>
|
||||
<head>
|
||||
<!--
|
||||
Copyright (c) 2007 Timothy Wall
|
||||
-->
|
||||
</head>
|
||||
<body bgcolor="white">
|
||||
|
||||
<!-- One sentence summary -->
|
||||
Cross-platform ghosted drag image implementation with demo application.
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" output="build.eclipse/contrib-test-classes" path="test"/>
|
||||
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/jna"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
|
||||
<classpathentry kind="lib" path="/jna/dist/jna.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ntservice</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,60 @@
|
||||
Copyright (c) 2007 Thomas Boerkel, All Rights Reserved
|
||||
|
||||
Disclaimer:
|
||||
===========
|
||||
This code is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This code is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
|
||||
Description:
|
||||
============
|
||||
|
||||
Accounts.java:
|
||||
--------------
|
||||
Static methods for getting information about Win32 accounts (users
|
||||
and groups).
|
||||
- list all domain users
|
||||
- list all domain groups
|
||||
- list all local or domain groups where a user belongs to
|
||||
- get account by SID
|
||||
- get SID of account
|
||||
- get domain controller name
|
||||
- get domain name
|
||||
|
||||
Registry.java:
|
||||
--------------
|
||||
Static methods for reading and manipulating the Windows Registry.
|
||||
Only String and DWORD values supported, but could be easily
|
||||
extended.
|
||||
- create key
|
||||
- delete key
|
||||
- delete value
|
||||
- read value
|
||||
- get all sub keys of a key
|
||||
- get all values of a key
|
||||
- set value
|
||||
- check existence of value
|
||||
|
||||
Win32Service.java:
|
||||
------------------
|
||||
Abstract class to wrap a Win32 service. Derive from this class
|
||||
to build your own service. Supports only one type of service and
|
||||
startup, but could be easily extended.
|
||||
- install service
|
||||
- uninstall service
|
||||
- start service
|
||||
- stop service
|
||||
- callback for service start request (onStart), should spawn a thread
|
||||
- callback for service stop request (onStop)
|
||||
|
||||
TestService.java:
|
||||
-----------------
|
||||
Very simple example of an implementation of Win32Service.java.
|
||||
Does nothing but starting and stopping (no "useful" work).
|
||||
@@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- You may freely edit this file. See commented blocks below for -->
|
||||
<!-- some examples of how to customize the build. -->
|
||||
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
||||
<project name="JnaContrib" default="default" basedir=".">
|
||||
<description>Builds, tests, and runs the project JnaContrib.</description>
|
||||
<import file="nbproject/build-impl.xml"/>
|
||||
<!--
|
||||
|
||||
There exist several targets which are by default empty and which can be
|
||||
used for execution of your tasks. These targets are usually executed
|
||||
before and after some main targets. They are:
|
||||
|
||||
-pre-init: called before initialization of project properties
|
||||
-post-init: called after initialization of project properties
|
||||
-pre-compile: called before javac compilation
|
||||
-post-compile: called after javac compilation
|
||||
-pre-compile-single: called before javac compilation of single file
|
||||
-post-compile-single: called after javac compilation of single file
|
||||
-pre-compile-test: called before javac compilation of JUnit tests
|
||||
-post-compile-test: called after javac compilation of JUnit tests
|
||||
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||
-pre-jar: called before JAR building
|
||||
-post-jar: called after JAR building
|
||||
-post-clean: called after cleaning build products
|
||||
|
||||
(Targets beginning with '-' are not intended to be called on their own.)
|
||||
|
||||
Example of inserting an obfuscator after compilation could look like this:
|
||||
|
||||
<target name="-post-compile">
|
||||
<obfuscate>
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
</obfuscate>
|
||||
</target>
|
||||
|
||||
For list of available properties check the imported
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
|
||||
Another way to customize the build is by overriding existing main targets.
|
||||
The targets of interest are:
|
||||
|
||||
-init-macrodef-javac: defines macro for javac compilation
|
||||
-init-macrodef-junit: defines macro for junit execution
|
||||
-init-macrodef-debug: defines macro for class debugging
|
||||
-init-macrodef-java: defines macro for class execution
|
||||
-do-jar-with-manifest: JAR building (if you are using a manifest)
|
||||
-do-jar-without-manifest: JAR building (if you are not using a manifest)
|
||||
run: execution of project
|
||||
-javadoc-build: Javadoc generation
|
||||
test-report: JUnit report generation
|
||||
|
||||
An example of overriding the target for project execution could look like this:
|
||||
|
||||
<target name="run" depends="JnaContrib-impl.jar">
|
||||
<exec dir="bin" executable="launcher.exe">
|
||||
<arg file="${dist.jar}"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
Notice that the overridden target depends on the jar target and not only on
|
||||
the compile target as the regular run target does. Again, for a list of available
|
||||
properties which you can use, check the target you are overriding in the
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
-->
|
||||
</project>
|
||||
@@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
X-COMMENT: Main-Class will be added automatically by build
|
||||
|
||||
@@ -0,0 +1,541 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
*** GENERATED FROM project.xml - DO NOT EDIT ***
|
||||
*** EDIT ../build.xml INSTEAD ***
|
||||
|
||||
For the purpose of easier reading the script
|
||||
is divided into following sections:
|
||||
|
||||
- initialization
|
||||
- compilation
|
||||
- jar
|
||||
- execution
|
||||
- debugging
|
||||
- javadoc
|
||||
- junit compilation
|
||||
- junit execution
|
||||
- junit debugging
|
||||
- applet
|
||||
- cleanup
|
||||
|
||||
-->
|
||||
<project name="ntservice-impl" default="default" basedir=".." xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:j2seproject2="http://www.netbeans.org/ns/j2se-project/2" xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:jaxws="http://www.netbeans.org/ns/jax-ws/1">
|
||||
<target name="default" depends="test,jar,javadoc" description="Build and test whole project."/>
|
||||
<!--
|
||||
======================
|
||||
INITIALIZATION SECTION
|
||||
======================
|
||||
-->
|
||||
<target name="-pre-init">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-init-private" depends="-pre-init">
|
||||
<property file="nbproject/private/private.properties"/>
|
||||
</target>
|
||||
<target name="-init-user" depends="-pre-init,-init-private">
|
||||
<property file="${user.properties.file}"/>
|
||||
<!-- The two properties below are usually overridden -->
|
||||
<!-- by the active platform. Just a fallback. -->
|
||||
<property name="default.javac.source" value="1.4"/>
|
||||
<property name="default.javac.target" value="1.4"/>
|
||||
</target>
|
||||
<target name="-init-project" depends="-pre-init,-init-private,-init-user">
|
||||
<property file="nbproject/project.properties"/>
|
||||
</target>
|
||||
<target name="-do-init" depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property">
|
||||
<available file="${manifest.file}" property="manifest.available"/>
|
||||
<condition property="manifest.available+main.class">
|
||||
<and>
|
||||
<isset property="manifest.available"/>
|
||||
<isset property="main.class"/>
|
||||
<not>
|
||||
<equals arg1="${main.class}" arg2="" trim="true"/>
|
||||
</not>
|
||||
</and>
|
||||
</condition>
|
||||
<condition property="manifest.available+main.class+mkdist.available">
|
||||
<and>
|
||||
<istrue value="${manifest.available+main.class}"/>
|
||||
<isset property="libs.CopyLibs.classpath"/>
|
||||
</and>
|
||||
</condition>
|
||||
<condition property="have.tests">
|
||||
<or>
|
||||
<available file="${test.src.dir}"/>
|
||||
</or>
|
||||
</condition>
|
||||
<condition property="have.sources">
|
||||
<or>
|
||||
<available file="${src.dir}"/>
|
||||
</or>
|
||||
</condition>
|
||||
<condition property="netbeans.home+have.tests">
|
||||
<and>
|
||||
<isset property="netbeans.home"/>
|
||||
<isset property="have.tests"/>
|
||||
</and>
|
||||
</condition>
|
||||
<condition property="no.javadoc.preview">
|
||||
<isfalse value="${javadoc.preview}"/>
|
||||
</condition>
|
||||
<property name="run.jvmargs" value=""/>
|
||||
<property name="javac.compilerargs" value=""/>
|
||||
<property name="work.dir" value="${basedir}"/>
|
||||
<condition property="no.deps">
|
||||
<and>
|
||||
<istrue value="${no.dependencies}"/>
|
||||
</and>
|
||||
</condition>
|
||||
<property name="javac.debug" value="true"/>
|
||||
<property name="javadoc.preview" value="true"/>
|
||||
</target>
|
||||
<target name="-post-init">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-init-check" depends="-pre-init,-init-private,-init-user,-init-project,-do-init">
|
||||
<fail unless="src.dir">Must set src.dir</fail>
|
||||
<fail unless="test.src.dir">Must set test.src.dir</fail>
|
||||
<fail unless="build.dir">Must set build.dir</fail>
|
||||
<fail unless="dist.dir">Must set dist.dir</fail>
|
||||
<fail unless="build.classes.dir">Must set build.classes.dir</fail>
|
||||
<fail unless="dist.javadoc.dir">Must set dist.javadoc.dir</fail>
|
||||
<fail unless="build.test.classes.dir">Must set build.test.classes.dir</fail>
|
||||
<fail unless="build.test.results.dir">Must set build.test.results.dir</fail>
|
||||
<fail unless="build.classes.excludes">Must set build.classes.excludes</fail>
|
||||
<fail unless="dist.jar">Must set dist.jar</fail>
|
||||
</target>
|
||||
<target name="-init-macrodef-property">
|
||||
<macrodef name="property" uri="http://www.netbeans.org/ns/j2se-project/1">
|
||||
<attribute name="name"/>
|
||||
<attribute name="value"/>
|
||||
<sequential>
|
||||
<property name="@{name}" value="${@{value}}"/>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-macrodef-javac">
|
||||
<macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute name="srcdir" default="${src.dir}"/>
|
||||
<attribute name="destdir" default="${build.classes.dir}"/>
|
||||
<attribute name="classpath" default="${javac.classpath}"/>
|
||||
<attribute name="debug" default="${javac.debug}"/>
|
||||
<element name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<javac srcdir="@{srcdir}" destdir="@{destdir}" debug="@{debug}" deprecation="${javac.deprecation}" source="${javac.source}" target="${javac.target}" includeantruntime="false">
|
||||
<classpath>
|
||||
<path path="@{classpath}"/>
|
||||
</classpath>
|
||||
<compilerarg line="${javac.compilerargs}"/>
|
||||
<customize/>
|
||||
</javac>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-macrodef-junit">
|
||||
<macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute name="includes" default="**/*Test.java"/>
|
||||
<sequential>
|
||||
<junit showoutput="true" fork="true" dir="${basedir}" failureproperty="tests.failed" errorproperty="tests.failed">
|
||||
<batchtest todir="${build.test.results.dir}">
|
||||
<fileset dir="${test.src.dir}" includes="@{includes}"/>
|
||||
</batchtest>
|
||||
<classpath>
|
||||
<path path="${run.test.classpath}"/>
|
||||
</classpath>
|
||||
<syspropertyset>
|
||||
<propertyref prefix="test-sys-prop."/>
|
||||
<mapper type="glob" from="test-sys-prop.*" to="*"/>
|
||||
</syspropertyset>
|
||||
<formatter type="brief" usefile="false"/>
|
||||
<formatter type="xml"/>
|
||||
<jvmarg line="${run.jvmargs}"/>
|
||||
</junit>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-macrodef-nbjpda">
|
||||
<macrodef name="nbjpdastart" uri="http://www.netbeans.org/ns/j2se-project/1">
|
||||
<attribute name="name" default="${main.class}"/>
|
||||
<attribute name="classpath" default="${debug.classpath}"/>
|
||||
<attribute name="stopclassname" default=""/>
|
||||
<sequential>
|
||||
<nbjpdastart transport="dt_socket" addressproperty="jpda.address" name="@{name}" stopclassname="@{stopclassname}">
|
||||
<classpath>
|
||||
<path path="@{classpath}"/>
|
||||
</classpath>
|
||||
</nbjpdastart>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
<macrodef name="nbjpdareload" uri="http://www.netbeans.org/ns/j2se-project/1">
|
||||
<attribute name="dir" default="${build.classes.dir}"/>
|
||||
<sequential>
|
||||
<nbjpdareload>
|
||||
<fileset includes="${fix.includes}*.class" dir="@{dir}"/>
|
||||
</nbjpdareload>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-macrodef-debug">
|
||||
<macrodef name="debug" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute name="classname" default="${main.class}"/>
|
||||
<attribute name="classpath" default="${debug.classpath}"/>
|
||||
<element name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<java fork="true" classname="@{classname}" dir="${work.dir}">
|
||||
<jvmarg value="-Xdebug"/>
|
||||
<jvmarg value="-Xnoagent"/>
|
||||
<jvmarg value="-Djava.compiler=none"/>
|
||||
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/>
|
||||
<jvmarg line="${run.jvmargs}"/>
|
||||
<classpath>
|
||||
<path path="@{classpath}"/>
|
||||
</classpath>
|
||||
<syspropertyset>
|
||||
<propertyref prefix="run-sys-prop."/>
|
||||
<mapper type="glob" from="run-sys-prop.*" to="*"/>
|
||||
</syspropertyset>
|
||||
<customize/>
|
||||
</java>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-macrodef-java">
|
||||
<macrodef name="java" uri="http://www.netbeans.org/ns/j2se-project/1">
|
||||
<attribute name="classname" default="${main.class}"/>
|
||||
<element name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<java fork="true" classname="@{classname}" dir="${work.dir}">
|
||||
<jvmarg line="${run.jvmargs}"/>
|
||||
<classpath>
|
||||
<path path="${run.classpath}"/>
|
||||
</classpath>
|
||||
<syspropertyset>
|
||||
<propertyref prefix="run-sys-prop."/>
|
||||
<mapper type="glob" from="run-sys-prop.*" to="*"/>
|
||||
</syspropertyset>
|
||||
<customize/>
|
||||
</java>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-presetdef-jar">
|
||||
<presetdef name="jar" uri="http://www.netbeans.org/ns/j2se-project/1">
|
||||
<jar jarfile="${dist.jar}" compress="${jar.compress}">
|
||||
<j2seproject1:fileset dir="${build.classes.dir}"/>
|
||||
</jar>
|
||||
</presetdef>
|
||||
</target>
|
||||
<target name="init" depends="-pre-init,-init-private,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac,-init-macrodef-junit,-init-macrodef-nbjpda,-init-macrodef-debug,-init-macrodef-java,-init-presetdef-jar"/>
|
||||
<!--
|
||||
===================
|
||||
COMPILATION SECTION
|
||||
===================
|
||||
-->
|
||||
<target name="deps-jar" depends="init" unless="no.deps"/>
|
||||
<target name="-pre-pre-compile" depends="init,deps-jar">
|
||||
<mkdir dir="${build.classes.dir}"/>
|
||||
</target>
|
||||
<target name="-pre-compile">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-do-compile" depends="init,deps-jar,-pre-pre-compile,-pre-compile" if="have.sources">
|
||||
<j2seproject3:javac/>
|
||||
<copy todir="${build.classes.dir}">
|
||||
<fileset dir="${src.dir}" excludes="${build.classes.excludes}"/>
|
||||
</copy>
|
||||
</target>
|
||||
<target name="-post-compile">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="compile" depends="init,deps-jar,-pre-pre-compile,-pre-compile,-do-compile,-post-compile" description="Compile project."/>
|
||||
<target name="-pre-compile-single">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-do-compile-single" depends="init,deps-jar,-pre-pre-compile">
|
||||
<fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
|
||||
<j2seproject3:javac>
|
||||
<customize>
|
||||
<patternset includes="${javac.includes}"/>
|
||||
</customize>
|
||||
</j2seproject3:javac>
|
||||
</target>
|
||||
<target name="-post-compile-single">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="compile-single" depends="init,deps-jar,-pre-pre-compile,-pre-compile-single,-do-compile-single,-post-compile-single"/>
|
||||
<!--
|
||||
====================
|
||||
JAR BUILDING SECTION
|
||||
====================
|
||||
-->
|
||||
<target name="-pre-pre-jar" depends="init">
|
||||
<dirname property="dist.jar.dir" file="${dist.jar}"/>
|
||||
<mkdir dir="${dist.jar.dir}"/>
|
||||
</target>
|
||||
<target name="-pre-jar">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-do-jar-without-manifest" depends="init,compile,-pre-pre-jar,-pre-jar" unless="manifest.available">
|
||||
<j2seproject1:jar/>
|
||||
</target>
|
||||
<target name="-do-jar-with-manifest" depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available" unless="manifest.available+main.class">
|
||||
<j2seproject1:jar manifest="${manifest.file}"/>
|
||||
</target>
|
||||
<target name="-do-jar-with-mainclass" depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available+main.class" unless="manifest.available+main.class+mkdist.available">
|
||||
<j2seproject1:jar manifest="${manifest.file}">
|
||||
<j2seproject1:manifest>
|
||||
<j2seproject1:attribute name="Main-Class" value="${main.class}"/>
|
||||
</j2seproject1:manifest>
|
||||
</j2seproject1:jar>
|
||||
<echo>To run this application from the command line without Ant, try:</echo>
|
||||
<property name="build.classes.dir.resolved" location="${build.classes.dir}"/>
|
||||
<property name="dist.jar.resolved" location="${dist.jar}"/>
|
||||
<pathconvert property="run.classpath.with.dist.jar">
|
||||
<path path="${run.classpath}"/>
|
||||
<map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
|
||||
</pathconvert>
|
||||
<echo>java -cp "${run.classpath.with.dist.jar}" ${main.class}</echo>
|
||||
</target>
|
||||
<target name="-do-jar-with-libraries" depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available+main.class+mkdist.available">
|
||||
<property name="build.classes.dir.resolved" location="${build.classes.dir}"/>
|
||||
<pathconvert property="run.classpath.without.build.classes.dir">
|
||||
<path path="${run.classpath}"/>
|
||||
<map from="${build.classes.dir.resolved}" to=""/>
|
||||
</pathconvert>
|
||||
<pathconvert property="jar.classpath" pathsep=" ">
|
||||
<path path="${run.classpath.without.build.classes.dir}"/>
|
||||
<chainedmapper>
|
||||
<flattenmapper/>
|
||||
<globmapper from="*" to="lib/*"/>
|
||||
</chainedmapper>
|
||||
</pathconvert>
|
||||
<taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" name="copylibs" classpath="${libs.CopyLibs.classpath}"/>
|
||||
<copylibs manifest="${manifest.file}" runtimeclasspath="${run.classpath.without.build.classes.dir}" jarfile="${dist.jar}" compress="${jar.compress}">
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="${main.class}"/>
|
||||
<attribute name="Class-Path" value="${jar.classpath}"/>
|
||||
</manifest>
|
||||
</copylibs>
|
||||
<echo>To run this application from the command line without Ant, try:</echo>
|
||||
<property name="dist.jar.resolved" location="${dist.jar}"/>
|
||||
<echo>java -jar "${dist.jar.resolved}"</echo>
|
||||
</target>
|
||||
<target name="-post-jar">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="jar" depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries,-post-jar" description="Build JAR."/>
|
||||
<!--
|
||||
=================
|
||||
EXECUTION SECTION
|
||||
=================
|
||||
-->
|
||||
<target name="run" depends="init,compile" description="Run a main class.">
|
||||
<j2seproject1:java>
|
||||
<customize>
|
||||
<arg line="${application.args}"/>
|
||||
</customize>
|
||||
</j2seproject1:java>
|
||||
</target>
|
||||
<target name="run-single" depends="init,compile-single">
|
||||
<fail unless="run.class">Must select one file in the IDE or set run.class</fail>
|
||||
<j2seproject1:java classname="${run.class}"/>
|
||||
</target>
|
||||
<!--
|
||||
=================
|
||||
DEBUGGING SECTION
|
||||
=================
|
||||
-->
|
||||
<target name="-debug-start-debugger" if="netbeans.home" depends="init">
|
||||
<j2seproject1:nbjpdastart name="${debug.class}"/>
|
||||
</target>
|
||||
<target name="-debug-start-debuggee" depends="init,compile">
|
||||
<j2seproject3:debug>
|
||||
<customize>
|
||||
<arg line="${application.args}"/>
|
||||
</customize>
|
||||
</j2seproject3:debug>
|
||||
</target>
|
||||
<target name="debug" if="netbeans.home" depends="init,compile,-debug-start-debugger,-debug-start-debuggee" description="Debug project in IDE."/>
|
||||
<target name="-debug-start-debugger-stepinto" if="netbeans.home" depends="init">
|
||||
<j2seproject1:nbjpdastart stopclassname="${main.class}"/>
|
||||
</target>
|
||||
<target name="debug-stepinto" if="netbeans.home" depends="init,compile,-debug-start-debugger-stepinto,-debug-start-debuggee"/>
|
||||
<target name="-debug-start-debuggee-single" if="netbeans.home" depends="init,compile-single">
|
||||
<fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
|
||||
<j2seproject3:debug classname="${debug.class}"/>
|
||||
</target>
|
||||
<target name="debug-single" if="netbeans.home" depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-single"/>
|
||||
<target name="-pre-debug-fix" depends="init">
|
||||
<fail unless="fix.includes">Must set fix.includes</fail>
|
||||
<property name="javac.includes" value="${fix.includes}.java"/>
|
||||
</target>
|
||||
<target name="-do-debug-fix" if="netbeans.home" depends="init,-pre-debug-fix,compile-single">
|
||||
<j2seproject1:nbjpdareload/>
|
||||
</target>
|
||||
<target name="debug-fix" if="netbeans.home" depends="init,-pre-debug-fix,-do-debug-fix"/>
|
||||
<!--
|
||||
===============
|
||||
JAVADOC SECTION
|
||||
===============
|
||||
-->
|
||||
<target name="-javadoc-build" depends="init">
|
||||
<mkdir dir="${dist.javadoc.dir}"/>
|
||||
<javadoc destdir="${dist.javadoc.dir}" source="${javac.source}" notree="${javadoc.notree}" use="${javadoc.use}" nonavbar="${javadoc.nonavbar}" noindex="${javadoc.noindex}" splitindex="${javadoc.splitindex}" author="${javadoc.author}" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}" private="${javadoc.private}" additionalparam="${javadoc.additionalparam}" failonerror="true" useexternalfile="true">
|
||||
<classpath>
|
||||
<path path="${javac.classpath}"/>
|
||||
</classpath>
|
||||
<sourcepath>
|
||||
<pathelement location="${src.dir}"/>
|
||||
</sourcepath>
|
||||
<packageset dir="${src.dir}" includes="*/**"/>
|
||||
<fileset dir="${src.dir}" includes="*.java"/>
|
||||
</javadoc>
|
||||
</target>
|
||||
<target name="-javadoc-browse" if="netbeans.home" unless="no.javadoc.preview" depends="init,-javadoc-build">
|
||||
<nbbrowse file="${dist.javadoc.dir}/index.html"/>
|
||||
</target>
|
||||
<target name="javadoc" depends="init,-javadoc-build,-javadoc-browse" description="Build Javadoc."/>
|
||||
<!--
|
||||
=========================
|
||||
JUNIT COMPILATION SECTION
|
||||
=========================
|
||||
-->
|
||||
<target name="-pre-pre-compile-test" if="have.tests" depends="init,compile">
|
||||
<mkdir dir="${build.test.classes.dir}"/>
|
||||
</target>
|
||||
<target name="-pre-compile-test">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-do-compile-test" if="have.tests" depends="init,compile,-pre-pre-compile-test,-pre-compile-test">
|
||||
<j2seproject3:javac srcdir="${test.src.dir}" destdir="${build.test.classes.dir}" debug="true" classpath="${javac.test.classpath}"/>
|
||||
<copy todir="${build.test.classes.dir}">
|
||||
<fileset dir="${test.src.dir}" excludes="**/*.java"/>
|
||||
</copy>
|
||||
</target>
|
||||
<target name="-post-compile-test">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="compile-test" depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-do-compile-test,-post-compile-test"/>
|
||||
<target name="-pre-compile-test-single">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-do-compile-test-single" if="have.tests" depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single">
|
||||
<fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
|
||||
<j2seproject3:javac srcdir="${test.src.dir}" destdir="${build.test.classes.dir}" debug="true" classpath="${javac.test.classpath}">
|
||||
<customize>
|
||||
<patternset includes="${javac.includes}"/>
|
||||
</customize>
|
||||
</j2seproject3:javac>
|
||||
<copy todir="${build.test.classes.dir}">
|
||||
<fileset dir="${test.src.dir}" excludes="**/*.java"/>
|
||||
</copy>
|
||||
</target>
|
||||
<target name="-post-compile-test-single">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="compile-test-single" depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single,-do-compile-test-single,-post-compile-test-single"/>
|
||||
<!--
|
||||
=======================
|
||||
JUNIT EXECUTION SECTION
|
||||
=======================
|
||||
-->
|
||||
<target name="-pre-test-run" if="have.tests" depends="init">
|
||||
<mkdir dir="${build.test.results.dir}"/>
|
||||
</target>
|
||||
<target name="-do-test-run" if="have.tests" depends="init,compile-test,-pre-test-run">
|
||||
<j2seproject3:junit/>
|
||||
</target>
|
||||
<target name="-post-test-run" if="have.tests" depends="init,compile-test,-pre-test-run,-do-test-run">
|
||||
<fail if="tests.failed">Some tests failed; see details above.</fail>
|
||||
</target>
|
||||
<target name="test-report" if="have.tests" depends="init"/>
|
||||
<target name="-test-browse" if="netbeans.home+have.tests" depends="init"/>
|
||||
<target name="test" depends="init,compile-test,-pre-test-run,-do-test-run,test-report,-post-test-run,-test-browse" description="Run unit tests."/>
|
||||
<target name="-pre-test-run-single" if="have.tests" depends="init">
|
||||
<mkdir dir="${build.test.results.dir}"/>
|
||||
</target>
|
||||
<target name="-do-test-run-single" if="have.tests" depends="init,compile-test-single,-pre-test-run-single">
|
||||
<fail unless="test.includes">Must select some files in the IDE or set test.includes</fail>
|
||||
<j2seproject3:junit includes="${test.includes}"/>
|
||||
</target>
|
||||
<target name="-post-test-run-single" if="have.tests" depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single">
|
||||
<fail if="tests.failed">Some tests failed; see details above.</fail>
|
||||
</target>
|
||||
<target name="test-single" depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single,-post-test-run-single" description="Run single unit test."/>
|
||||
<!--
|
||||
=======================
|
||||
JUNIT DEBUGGING SECTION
|
||||
=======================
|
||||
-->
|
||||
<target name="-debug-start-debuggee-test" if="have.tests" depends="init,compile-test">
|
||||
<fail unless="test.class">Must select one file in the IDE or set test.class</fail>
|
||||
<j2seproject3:debug classname="junit.textui.TestRunner" classpath="${debug.test.classpath}">
|
||||
<customize>
|
||||
<arg line="${test.class}"/>
|
||||
</customize>
|
||||
</j2seproject3:debug>
|
||||
</target>
|
||||
<target name="-debug-start-debugger-test" if="netbeans.home+have.tests" depends="init,compile-test">
|
||||
<j2seproject1:nbjpdastart name="${test.class}" classpath="${debug.test.classpath}"/>
|
||||
</target>
|
||||
<target name="debug-test" depends="init,compile-test,-debug-start-debugger-test,-debug-start-debuggee-test"/>
|
||||
<target name="-do-debug-fix-test" if="netbeans.home" depends="init,-pre-debug-fix,compile-test-single">
|
||||
<j2seproject1:nbjpdareload dir="${build.test.classes.dir}"/>
|
||||
</target>
|
||||
<target name="debug-fix-test" if="netbeans.home" depends="init,-pre-debug-fix,-do-debug-fix-test"/>
|
||||
<!--
|
||||
=========================
|
||||
APPLET EXECUTION SECTION
|
||||
=========================
|
||||
-->
|
||||
<target name="run-applet" depends="init,compile-single">
|
||||
<fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
|
||||
<j2seproject1:java classname="sun.applet.AppletViewer">
|
||||
<customize>
|
||||
<arg value="${applet.url}"/>
|
||||
</customize>
|
||||
</j2seproject1:java>
|
||||
</target>
|
||||
<!--
|
||||
=========================
|
||||
APPLET DEBUGGING SECTION
|
||||
=========================
|
||||
-->
|
||||
<target name="-debug-start-debuggee-applet" if="netbeans.home" depends="init,compile-single">
|
||||
<fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
|
||||
<j2seproject3:debug classname="sun.applet.AppletViewer">
|
||||
<customize>
|
||||
<arg value="${applet.url}"/>
|
||||
</customize>
|
||||
</j2seproject3:debug>
|
||||
</target>
|
||||
<target name="debug-applet" if="netbeans.home" depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-applet"/>
|
||||
<!--
|
||||
===============
|
||||
CLEANUP SECTION
|
||||
===============
|
||||
-->
|
||||
<target name="deps-clean" depends="init" unless="no.deps"/>
|
||||
<target name="-do-clean" depends="init">
|
||||
<delete dir="${build.dir}"/>
|
||||
<delete dir="${dist.dir}"/>
|
||||
</target>
|
||||
<target name="-post-clean">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="clean" depends="init,deps-clean,-do-clean,-post-clean" description="Clean build products."/>
|
||||
</project>
|
||||
@@ -0,0 +1,8 @@
|
||||
build.xml.data.CRC32=94714fd7
|
||||
build.xml.script.CRC32=64128189
|
||||
build.xml.stylesheet.CRC32=240b97a2
|
||||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||
nbproject/build-impl.xml.data.CRC32=94714fd7
|
||||
nbproject/build-impl.xml.script.CRC32=9d2a0176
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=65d7ca21
|
||||
@@ -0,0 +1,59 @@
|
||||
application.args=
|
||||
build.classes.dir=${build.dir}/classes
|
||||
build.classes.excludes=**/*.java,**/*.form
|
||||
# This directory is removed when the project is cleaned:
|
||||
build.dir=build
|
||||
build.generated.dir=${build.dir}/generated
|
||||
# Only compile against the classpath explicitly listed here:
|
||||
build.sysclasspath=ignore
|
||||
build.test.classes.dir=${build.dir}/test/classes
|
||||
build.test.results.dir=${build.dir}/test/results
|
||||
debug.classpath=\
|
||||
${run.classpath}
|
||||
debug.test.classpath=\
|
||||
${run.test.classpath}
|
||||
# This directory is removed when the project is cleaned:
|
||||
dist.dir=dist
|
||||
dist.jar=${dist.dir}/contrib-ntservice.jar
|
||||
dist.javadoc.dir=${dist.dir}/javadoc
|
||||
file.reference.jna.jar=../../../build/jna.jar
|
||||
libs.junit.classpath=../../../lib/junit.jar
|
||||
jar.compress=false
|
||||
javac.classpath=\
|
||||
${file.reference.jna.jar};
|
||||
# Space-separated list of extra javac options
|
||||
javac.compilerargs=
|
||||
javac.deprecation=false
|
||||
javac.source=1.6
|
||||
javac.target=1.6
|
||||
javac.test.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}:\
|
||||
${libs.junit.classpath}
|
||||
javadoc.additionalparam=
|
||||
javadoc.author=false
|
||||
javadoc.encoding=
|
||||
javadoc.noindex=false
|
||||
javadoc.nonavbar=false
|
||||
javadoc.notree=false
|
||||
javadoc.private=false
|
||||
javadoc.splitindex=true
|
||||
javadoc.use=true
|
||||
javadoc.version=false
|
||||
javadoc.windowtitle=
|
||||
main.class=
|
||||
manifest.file=manifest.mf
|
||||
meta.inf.dir=${src.dir}/META-INF
|
||||
platform.active=default_platform
|
||||
run.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
# Space-separated list of JVM arguments used when running the project
|
||||
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
|
||||
# or test-sys-prop.name=value to set system properties for unit tests):
|
||||
run.jvmargs=
|
||||
run.test.classpath=\
|
||||
${javac.test.classpath}:\
|
||||
${build.test.classes.dir}
|
||||
src.dir=src
|
||||
test.src.dir=test
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.java.j2seproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>ntservice</name>
|
||||
<minimum-ant-version>1.6.5</minimum-ant-version>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
<test-roots>
|
||||
<root id="test.src.dir"/>
|
||||
</test-roots>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
||||
@@ -0,0 +1,335 @@
|
||||
/*
|
||||
* Advapi32.java
|
||||
*
|
||||
* Created on 6. August 2007, 11:24
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package jnacontrib.jna;
|
||||
|
||||
import com.sun.jna.*;
|
||||
import com.sun.jna.ptr.*;
|
||||
import com.sun.jna.win32.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface Advapi32 extends StdCallLibrary {
|
||||
Advapi32 INSTANCE = (Advapi32) Native.loadLibrary("Advapi32", Advapi32.class, Options.UNICODE_OPTIONS);
|
||||
|
||||
/*
|
||||
BOOL WINAPI LookupAccountName(
|
||||
LPCTSTR lpSystemName,
|
||||
LPCTSTR lpAccountName,
|
||||
PSID Sid,
|
||||
LPDWORD cbSid,
|
||||
LPTSTR ReferencedDomainName,
|
||||
LPDWORD cchReferencedDomainName,
|
||||
PSID_NAME_USE peUse
|
||||
);*/
|
||||
public boolean LookupAccountName(String lpSystemName, String lpAccountName,
|
||||
byte[] Sid, IntByReference cbSid, char[] ReferencedDomainName,
|
||||
IntByReference cchReferencedDomainName, PointerByReference peUse);
|
||||
|
||||
/*
|
||||
BOOL WINAPI LookupAccountSid(
|
||||
LPCTSTR lpSystemName,
|
||||
PSID lpSid,
|
||||
LPTSTR lpName,
|
||||
LPDWORD cchName,
|
||||
LPTSTR lpReferencedDomainName,
|
||||
LPDWORD cchReferencedDomainName,
|
||||
PSID_NAME_USE peUse
|
||||
);*/
|
||||
public boolean LookupAccountSid(String lpSystemName, byte[] Sid,
|
||||
char[] lpName, IntByReference cchName, char[] ReferencedDomainName,
|
||||
IntByReference cchReferencedDomainName, PointerByReference peUse);
|
||||
|
||||
/*
|
||||
BOOL ConvertSidToStringSid(
|
||||
PSID Sid,
|
||||
LPTSTR* StringSid
|
||||
);*/
|
||||
public boolean ConvertSidToStringSid(byte[] Sid, PointerByReference StringSid);
|
||||
|
||||
/*
|
||||
BOOL WINAPI ConvertStringSidToSid(
|
||||
LPCTSTR StringSid,
|
||||
PSID* Sid
|
||||
);*/
|
||||
public boolean ConvertStringSidToSid(String StringSid, PointerByReference Sid);
|
||||
|
||||
/*
|
||||
SC_HANDLE WINAPI OpenSCManager(
|
||||
LPCTSTR lpMachineName,
|
||||
LPCTSTR lpDatabaseName,
|
||||
DWORD dwDesiredAccess
|
||||
);*/
|
||||
public Pointer OpenSCManager(String lpMachineName, WString lpDatabaseName, int dwDesiredAccess);
|
||||
|
||||
/*
|
||||
BOOL WINAPI CloseServiceHandle(
|
||||
SC_HANDLE hSCObject
|
||||
);*/
|
||||
public boolean CloseServiceHandle(Pointer hSCObject);
|
||||
|
||||
/*
|
||||
SC_HANDLE WINAPI OpenService(
|
||||
SC_HANDLE hSCManager,
|
||||
LPCTSTR lpServiceName,
|
||||
DWORD dwDesiredAccess
|
||||
);*/
|
||||
public Pointer OpenService(Pointer hSCManager, String lpServiceName, int dwDesiredAccess);
|
||||
|
||||
/*
|
||||
BOOL WINAPI StartService(
|
||||
SC_HANDLE hService,
|
||||
DWORD dwNumServiceArgs,
|
||||
LPCTSTR* lpServiceArgVectors
|
||||
);*/
|
||||
public boolean StartService(Pointer hService, int dwNumServiceArgs, char[] lpServiceArgVectors);
|
||||
|
||||
/*
|
||||
BOOL WINAPI ControlService(
|
||||
SC_HANDLE hService,
|
||||
DWORD dwControl,
|
||||
LPSERVICE_STATUS lpServiceStatus
|
||||
);*/
|
||||
public boolean ControlService(Pointer hService, int dwControl, SERVICE_STATUS lpServiceStatus);
|
||||
|
||||
/*
|
||||
BOOL WINAPI StartServiceCtrlDispatcher(
|
||||
const SERVICE_TABLE_ENTRY* lpServiceTable
|
||||
);*/
|
||||
public boolean StartServiceCtrlDispatcher(Structure[] lpServiceTable);
|
||||
|
||||
/*
|
||||
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandler(
|
||||
LPCTSTR lpServiceName,
|
||||
LPHANDLER_FUNCTION lpHandlerProc
|
||||
);*/
|
||||
public Pointer RegisterServiceCtrlHandler(String lpServiceName, Handler lpHandlerProc);
|
||||
|
||||
/*
|
||||
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerEx(
|
||||
LPCTSTR lpServiceName,
|
||||
LPHANDLER_FUNCTION_EX lpHandlerProc,
|
||||
LPVOID lpContext
|
||||
);*/
|
||||
public Pointer RegisterServiceCtrlHandlerEx(String lpServiceName, HandlerEx lpHandlerProc, Pointer lpContext);
|
||||
|
||||
/*
|
||||
BOOL WINAPI SetServiceStatus(
|
||||
SERVICE_STATUS_HANDLE hServiceStatus,
|
||||
LPSERVICE_STATUS lpServiceStatus
|
||||
);*/
|
||||
public boolean SetServiceStatus(Pointer hServiceStatus, SERVICE_STATUS lpServiceStatus);
|
||||
|
||||
/*
|
||||
SC_HANDLE WINAPI CreateService(
|
||||
SC_HANDLE hSCManager,
|
||||
LPCTSTR lpServiceName,
|
||||
LPCTSTR lpDisplayName,
|
||||
DWORD dwDesiredAccess,
|
||||
DWORD dwServiceType,
|
||||
DWORD dwStartType,
|
||||
DWORD dwErrorControl,
|
||||
LPCTSTR lpBinaryPathName,
|
||||
LPCTSTR lpLoadOrderGroup,
|
||||
LPDWORD lpdwTagId,
|
||||
LPCTSTR lpDependencies,
|
||||
LPCTSTR lpServiceStartName,
|
||||
LPCTSTR lpPassword
|
||||
);*/
|
||||
public Pointer CreateService(Pointer hSCManager, String lpServiceName, String lpDisplayName,
|
||||
int dwDesiredAccess, int dwServiceType, int dwStartType, int dwErrorControl,
|
||||
String lpBinaryPathName, String lpLoadOrderGroup, IntByReference lpdwTagId,
|
||||
String lpDependencies, String lpServiceStartName, String lpPassword);
|
||||
|
||||
/*
|
||||
BOOL WINAPI DeleteService(
|
||||
SC_HANDLE hService
|
||||
);*/
|
||||
public boolean DeleteService(Pointer hService);
|
||||
|
||||
/*
|
||||
BOOL WINAPI ChangeServiceConfig2(
|
||||
SC_HANDLE hService,
|
||||
DWORD dwInfoLevel,
|
||||
LPVOID lpInfo
|
||||
);*/
|
||||
public boolean ChangeServiceConfig2(Pointer hService, int dwInfoLevel, ChangeServiceConfig2Info lpInfo);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegOpenKeyEx(
|
||||
HKEY hKey,
|
||||
LPCTSTR lpSubKey,
|
||||
DWORD ulOptions,
|
||||
REGSAM samDesired,
|
||||
PHKEY phkResult
|
||||
);*/
|
||||
public int RegOpenKeyEx(int hKey, String lpSubKey, int ulOptions, int samDesired, IntByReference phkResult);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegQueryValueEx(
|
||||
HKEY hKey,
|
||||
LPCTSTR lpValueName,
|
||||
LPDWORD lpReserved,
|
||||
LPDWORD lpType,
|
||||
LPBYTE lpData,
|
||||
LPDWORD lpcbData
|
||||
);*/
|
||||
public int RegQueryValueEx(int hKey, String lpValueName, IntByReference lpReserved, IntByReference lpType, byte[] lpData, IntByReference lpcbData);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegCloseKey(
|
||||
HKEY hKey
|
||||
);*/
|
||||
public int RegCloseKey(int hKey);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegDeleteValue(
|
||||
HKEY hKey,
|
||||
LPCTSTR lpValueName
|
||||
);*/
|
||||
public int RegDeleteValue(int hKey, String lpValueName);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegSetValueEx(
|
||||
HKEY hKey,
|
||||
LPCTSTR lpValueName,
|
||||
DWORD Reserved,
|
||||
DWORD dwType,
|
||||
const BYTE* lpData,
|
||||
DWORD cbData
|
||||
);*/
|
||||
public int RegSetValueEx(int hKey, String lpValueName, int Reserved, int dwType, byte[] lpData, int cbData);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegCreateKeyEx(
|
||||
HKEY hKey,
|
||||
LPCTSTR lpSubKey,
|
||||
DWORD Reserved,
|
||||
LPTSTR lpClass,
|
||||
DWORD dwOptions,
|
||||
REGSAM samDesired,
|
||||
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
|
||||
PHKEY phkResult,
|
||||
LPDWORD lpdwDisposition
|
||||
);*/
|
||||
public int RegCreateKeyEx(int hKey, String lpSubKey, int Reserved, String lpClass, int dwOptions,
|
||||
int samDesired, WINBASE.SECURITY_ATTRIBUTES lpSecurityAttributes, IntByReference phkResult,
|
||||
IntByReference lpdwDisposition);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegDeleteKey(
|
||||
HKEY hKey,
|
||||
LPCTSTR lpSubKey
|
||||
);*/
|
||||
public int RegDeleteKey(int hKey, String name);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegEnumKeyEx(
|
||||
HKEY hKey,
|
||||
DWORD dwIndex,
|
||||
LPTSTR lpName,
|
||||
LPDWORD lpcName,
|
||||
LPDWORD lpReserved,
|
||||
LPTSTR lpClass,
|
||||
LPDWORD lpcClass,
|
||||
PFILETIME lpftLastWriteTime
|
||||
);*/
|
||||
public int RegEnumKeyEx(int hKey, int dwIndex, char[] lpName, IntByReference lpcName, IntByReference reserved,
|
||||
char[] lpClass, IntByReference lpcClass, WINBASE.FILETIME lpftLastWriteTime);
|
||||
|
||||
/*
|
||||
LONG WINAPI RegEnumValue(
|
||||
HKEY hKey,
|
||||
DWORD dwIndex,
|
||||
LPTSTR lpValueName,
|
||||
LPDWORD lpcchValueName,
|
||||
LPDWORD lpReserved,
|
||||
LPDWORD lpType,
|
||||
LPBYTE lpData,
|
||||
LPDWORD lpcbData
|
||||
);*/
|
||||
public int RegEnumValue(int hKey, int dwIndex, char[] lpValueName, IntByReference lpcchValueName, IntByReference reserved,
|
||||
IntByReference lpType, byte[] lpData, IntByReference lpcbData);
|
||||
|
||||
interface SERVICE_MAIN_FUNCTION extends StdCallCallback {
|
||||
/*
|
||||
VOID WINAPI ServiceMain(
|
||||
DWORD dwArgc,
|
||||
LPTSTR* lpszArgv
|
||||
);*/
|
||||
public void callback(int dwArgc, Pointer lpszArgv);
|
||||
}
|
||||
|
||||
interface Handler extends StdCallCallback {
|
||||
/*
|
||||
VOID WINAPI Handler(
|
||||
DWORD fdwControl
|
||||
);*/
|
||||
public void callback(int fdwControl);
|
||||
}
|
||||
|
||||
interface HandlerEx extends StdCallCallback {
|
||||
/*
|
||||
DWORD WINAPI HandlerEx(
|
||||
DWORD dwControl,
|
||||
DWORD dwEventType,
|
||||
LPVOID lpEventData,
|
||||
LPVOID lpContext
|
||||
);*/
|
||||
public int callback(int dwControl, int dwEventType, Pointer lpEventData, Pointer lpContext);
|
||||
}
|
||||
|
||||
/*
|
||||
typedef struct _SERVICE_STATUS {
|
||||
DWORD dwServiceType;
|
||||
DWORD dwCurrentState;
|
||||
DWORD dwControlsAccepted;
|
||||
DWORD dwWin32ExitCode;
|
||||
DWORD dwServiceSpecificExitCode;
|
||||
DWORD dwCheckPoint;
|
||||
DWORD dwWaitHint;
|
||||
} SERVICE_STATUS,
|
||||
*LPSERVICE_STATUS;*/
|
||||
public static class SERVICE_STATUS extends Structure {
|
||||
public int dwServiceType;
|
||||
public int dwCurrentState;
|
||||
public int dwControlsAccepted;
|
||||
public int dwWin32ExitCode;
|
||||
public int dwServiceSpecificExitCode;
|
||||
public int dwCheckPoint;
|
||||
public int dwWaitHint;
|
||||
}
|
||||
|
||||
/*
|
||||
typedef struct _SERVICE_TABLE_ENTRY {
|
||||
LPTSTR lpServiceName;
|
||||
LPSERVICE_MAIN_FUNCTION lpServiceProc;
|
||||
} SERVICE_TABLE_ENTRY,
|
||||
*LPSERVICE_TABLE_ENTRY;*/
|
||||
public static class SERVICE_TABLE_ENTRY extends Structure {
|
||||
public String lpServiceName;
|
||||
public SERVICE_MAIN_FUNCTION lpServiceProc;
|
||||
}
|
||||
|
||||
public static class ChangeServiceConfig2Info extends Structure {
|
||||
}
|
||||
|
||||
/*
|
||||
typedef struct _SERVICE_DESCRIPTION {
|
||||
LPTSTR lpDescription;
|
||||
} SERVICE_DESCRIPTION,
|
||||
*LPSERVICE_DESCRIPTION;*/
|
||||
public static class SERVICE_DESCRIPTION extends ChangeServiceConfig2Info {
|
||||
public String lpDescription;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Kernel32b.java
|
||||
*
|
||||
* Created on 6. August 2007, 14:43
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package jnacontrib.jna;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface Kernel32b extends StdCallLibrary {
|
||||
Kernel32b INSTANCE = (Kernel32b) Native.loadLibrary("Kernel32", Kernel32b.class, Options.UNICODE_OPTIONS);
|
||||
|
||||
/*
|
||||
HLOCAL WINAPI LocalFree(
|
||||
HLOCAL hMem
|
||||
);*/
|
||||
public Pointer LocalFree(Pointer hMem);
|
||||
/*
|
||||
|
||||
DWORD WINAPI GetLastError(void);*/
|
||||
public int GetLastError();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* LMACCESS.java
|
||||
*
|
||||
* Created on 7. August 2007, 12:42
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package jnacontrib.jna;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface LMACCESS {
|
||||
public final static int FILTER_NORMAL_ACCOUNT = 2;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* LMCONS.java
|
||||
*
|
||||
* Created on 7. August 2007, 08:46
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package jnacontrib.jna;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface LMCONS {
|
||||
public final static int MAX_PREFERRED_LENGTH = -1;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* LMERR.java
|
||||
*
|
||||
* Created on 7. August 2007, 08:22
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package jnacontrib.jna;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface LMERR {
|
||||
public final static int NERR_Success = 0;
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
/*
|
||||
* Netapi32.java
|
||||
*
|
||||
* Created on 2. August 2007, 13:12
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package jnacontrib.jna;
|
||||
|
||||
import com.sun.jna.*;
|
||||
import com.sun.jna.ptr.*;
|
||||
import com.sun.jna.win32.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface Netapi32 extends StdCallLibrary {
|
||||
Netapi32 INSTANCE = (Netapi32) Native.loadLibrary("Netapi32", Netapi32.class, Options.UNICODE_OPTIONS);
|
||||
/*
|
||||
NET_API_STATUS NetGetDCName(
|
||||
LPCWSTR servername,
|
||||
LPCWSTR domainname,
|
||||
LPBYTE* bufptr
|
||||
);*/
|
||||
public int NetGetDCName(String serverName, String domainName, PointerByReference bufptr);
|
||||
|
||||
/*
|
||||
DWORD DsGetDcName(
|
||||
LPCTSTR ComputerName,
|
||||
LPCTSTR DomainName,
|
||||
GUID* DomainGuid,
|
||||
LPCTSTR SiteName,
|
||||
ULONG Flags,
|
||||
PDOMAIN_CONTROLLER_INFO* DomainControllerInfo
|
||||
);*/
|
||||
public int DsGetDcName(String ComputerName, String DomainName, ByReference DomainGuid,
|
||||
String SiteName, int Flags, PointerByReference DomainControllerInfo);
|
||||
|
||||
/*
|
||||
NET_API_STATUS NetUserGetGroups(
|
||||
LPCWSTR servername,
|
||||
LPCWSTR username,
|
||||
DWORD level,
|
||||
LPBYTE* bufptr,
|
||||
DWORD prefmaxlen,
|
||||
LPDWORD entriesread,
|
||||
LPDWORD totalentries
|
||||
);*/
|
||||
public int NetUserGetGroups(String servername, String username, int level,
|
||||
PointerByReference bufptr, int prefmaxlen,
|
||||
IntByReference entriesread, IntByReference totalentries);
|
||||
|
||||
/*
|
||||
NET_API_STATUS NetUserGetLocalGroups(
|
||||
LPCWSTR servername,
|
||||
LPCWSTR username,
|
||||
DWORD level,
|
||||
DWORD flags,
|
||||
LPBYTE* bufptr,
|
||||
DWORD prefmaxlen,
|
||||
LPDWORD entriesread,
|
||||
LPDWORD totalentries
|
||||
);*/
|
||||
public int NetUserGetLocalGroups(String servername, String username, int level,
|
||||
int flags, PointerByReference bufptr, int prefmaxlen,
|
||||
IntByReference entriesread, IntByReference totalentries);
|
||||
|
||||
/*
|
||||
NET_API_STATUS NetGroupEnum(
|
||||
LPCWSTR servername,
|
||||
DWORD level,
|
||||
LPBYTE* bufptr,
|
||||
DWORD prefmaxlen,
|
||||
LPDWORD entriesread,
|
||||
LPDWORD totalentries,
|
||||
PDWORD_PTR resume_handle
|
||||
);*/
|
||||
public int NetGroupEnum(String servername, int level, PointerByReference bufptr,
|
||||
int prefmaxlen, IntByReference entriesread, IntByReference totalentries,
|
||||
IntByReference resume_handle);
|
||||
|
||||
/*
|
||||
NET_API_STATUS NetUserEnum(
|
||||
LPCWSTR servername,
|
||||
DWORD level,
|
||||
DWORD filter,
|
||||
LPBYTE* bufptr,
|
||||
DWORD prefmaxlen,
|
||||
LPDWORD entriesread,
|
||||
LPDWORD totalentries,
|
||||
LPDWORD resume_handle
|
||||
);*/
|
||||
public int NetUserEnum(String servername, int level, int filter, PointerByReference bufptr,
|
||||
int prefmaxlen, IntByReference entriesread, IntByReference totalentries,
|
||||
IntByReference resume_handle);
|
||||
|
||||
/*
|
||||
NET_API_STATUS NetApiBufferFree(
|
||||
LPVOID Buffer
|
||||
);*/
|
||||
public int NetApiBufferFree(Pointer Buffer);
|
||||
|
||||
/*
|
||||
typedef struct _GUID {
|
||||
DWORD Data1;
|
||||
WORD Data2;
|
||||
WORD Data3;
|
||||
BYTE Data4[8];
|
||||
} GUID;
|
||||
*/
|
||||
public static class GUID extends Structure {
|
||||
public GUID() {
|
||||
super();
|
||||
}
|
||||
|
||||
public GUID(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
public int Data1;
|
||||
public short Data2;
|
||||
public short Data3;
|
||||
public byte[] Data4 = new byte[8];
|
||||
}
|
||||
|
||||
/*
|
||||
typedef struct _DOMAIN_CONTROLLER_INFO {
|
||||
LPTSTR DomainControllerName;
|
||||
LPTSTR DomainControllerAddress;
|
||||
ULONG DomainControllerAddressType;
|
||||
GUID DomainGuid;
|
||||
LPTSTR DomainName;
|
||||
LPTSTR DnsForestName;
|
||||
ULONG Flags;
|
||||
LPTSTR DcSiteName;
|
||||
LPTSTR ClientSiteName;
|
||||
} DOMAIN_CONTROLLER_INFO,
|
||||
*/
|
||||
public static class DOMAIN_CONTROLLER_INFO extends Structure {
|
||||
public DOMAIN_CONTROLLER_INFO(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
public String DomainControllerName;
|
||||
public String DomainControllerAddress;
|
||||
public int DomainControllerAddressType;
|
||||
public GUID DomainGuid;
|
||||
public String DomainName;
|
||||
public String DnsForestName;
|
||||
public int Flags;
|
||||
public String DcSiteName;
|
||||
public String ClientSiteName;
|
||||
}
|
||||
|
||||
/*
|
||||
typedef struct _GROUP_USERS_INFO_0 {
|
||||
LPWSTR grui0_name;
|
||||
} GROUP_USERS_INFO_0,
|
||||
*PGROUP_USERS_INFO_0,
|
||||
*LPGROUP_USERS_INFO_0;
|
||||
*/
|
||||
public static class GROUP_USERS_INFO_0 extends Structure {
|
||||
public GROUP_USERS_INFO_0() {
|
||||
super();
|
||||
}
|
||||
|
||||
public GROUP_USERS_INFO_0(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
public String grui0_name;
|
||||
}
|
||||
|
||||
/*
|
||||
typedef struct _LOCALGROUP_USERS_INFO_0 {
|
||||
LPWSTR lgrui0_name;
|
||||
} LOCALGROUP_USERS_INFO_0,
|
||||
*PLOCALGROUP_USERS_INFO_0,
|
||||
*LPLOCALGROUP_USERS_INFO_0;
|
||||
*/
|
||||
public static class LOCALGROUP_USERS_INFO_0 extends Structure {
|
||||
public LOCALGROUP_USERS_INFO_0() {
|
||||
super();
|
||||
}
|
||||
|
||||
public LOCALGROUP_USERS_INFO_0(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
public String lgrui0_name;
|
||||
}
|
||||
|
||||
/*
|
||||
typedef struct _GROUP_INFO_0 {
|
||||
LPWSTR grpi0_name;
|
||||
} GROUP_INFO_0,
|
||||
*PGROUP_INFO_0,
|
||||
*LPGROUP_INFO_0;
|
||||
*/
|
||||
public static class GROUP_INFO_0 extends Structure {
|
||||
public GROUP_INFO_0() {
|
||||
super();
|
||||
}
|
||||
|
||||
public GROUP_INFO_0(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
public String grpi0_name;
|
||||
}
|
||||
|
||||
/*
|
||||
typedef struct _USER_INFO_0 {
|
||||
LPWSTR usri0_name;
|
||||
} USER_INFO_0,
|
||||
*PUSER_INFO_0,
|
||||
*LPUSER_INFO_0;*/
|
||||
public static class USER_INFO_0 extends Structure {
|
||||
public USER_INFO_0() {
|
||||
super();
|
||||
}
|
||||
|
||||
public USER_INFO_0(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
public String usri0_name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Options.java
|
||||
*
|
||||
* Created on 8. August 2007, 17:07
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package jnacontrib.jna;
|
||||
|
||||
import static com.sun.jna.Library.*;
|
||||
import com.sun.jna.TypeMapper;
|
||||
import com.sun.jna.win32.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface Options {
|
||||
Map<String, Object> UNICODE_OPTIONS = new HashMap<String, Object>() {
|
||||
{
|
||||
put(OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE);
|
||||
put(OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* WINBASE.java
|
||||
*
|
||||
* Created on 5. September 2007, 11:24
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package jnacontrib.jna;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface WINBASE {
|
||||
/*
|
||||
typedef struct _SECURITY_ATTRIBUTES {
|
||||
DWORD nLength;
|
||||
LPVOID lpSecurityDescriptor;
|
||||
BOOL bInheritHandle;
|
||||
} SECURITY_ATTRIBUTES,
|
||||
*PSECURITY_ATTRIBUTES,
|
||||
*LPSECURITY_ATTRIBUTES;*/
|
||||
public static class SECURITY_ATTRIBUTES extends Structure {
|
||||
public int nLength;
|
||||
public Pointer lpSecurityDescriptor;
|
||||
public boolean bInheritHandle;
|
||||
}
|
||||
|
||||
/*
|
||||
typedef struct _FILETIME {
|
||||
DWORD dwLowDateTime;
|
||||
DWORD dwHighDateTime;
|
||||
} FILETIME, *PFILETIME, *LPFILETIME;*/
|
||||
public static class FILETIME extends Structure {
|
||||
public int dwLowDateTime;
|
||||
public int dwHighDateTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* WINERROR.java
|
||||
*
|
||||
* Created on 7. August 2007, 08:09
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package jnacontrib.jna;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface WINERROR {
|
||||
public final static int ERROR_SUCCESS = 0;
|
||||
public final static int NO_ERROR = 0;
|
||||
public final static int ERROR_FILE_NOT_FOUND = 2;
|
||||
public final static int ERROR_MORE_DATA = 234;
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* WINNT.java
|
||||
*
|
||||
* Created on 8. August 2007, 13:41
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package jnacontrib.jna;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface WINNT {
|
||||
public final static int DELETE = 0x00010000;
|
||||
public final static int READ_CONTROL = 0x00020000;
|
||||
public final static int WRITE_DAC = 0x00040000;
|
||||
public final static int WRITE_OWNER = 0x00080000;
|
||||
public final static int SYNCHRONIZE = 0x00100000;
|
||||
|
||||
public final static int STANDARD_RIGHTS_REQUIRED = 0x000F0000;
|
||||
|
||||
public final static int STANDARD_RIGHTS_READ = READ_CONTROL;
|
||||
public final static int STANDARD_RIGHTS_WRITE = READ_CONTROL;
|
||||
public final static int STANDARD_RIGHTS_EXECUTE = READ_CONTROL;
|
||||
|
||||
public final static int STANDARD_RIGHTS_ALL = 0x001F0000;
|
||||
|
||||
public final static int SPECIFIC_RIGHTS_ALL = 0x0000FFFF;
|
||||
|
||||
public final static int GENERIC_EXECUTE = 0x20000000;
|
||||
|
||||
public final static int SERVICE_WIN32_OWN_PROCESS = 0x00000010;
|
||||
|
||||
public final static int KEY_QUERY_VALUE = 0x0001;
|
||||
public final static int KEY_SET_VALUE = 0x0002;
|
||||
public final static int KEY_CREATE_SUB_KEY = 0x0004;
|
||||
public final static int KEY_ENUMERATE_SUB_KEYS = 0x0008;
|
||||
public final static int KEY_NOTIFY = 0x0010;
|
||||
public final static int KEY_CREATE_LINK = 0x0020;
|
||||
|
||||
public final static int KEY_READ = ((STANDARD_RIGHTS_READ | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY) & (~SYNCHRONIZE));
|
||||
public final static int KEY_WRITE = ((STANDARD_RIGHTS_WRITE | KEY_SET_VALUE | KEY_CREATE_SUB_KEY) & (~SYNCHRONIZE));
|
||||
|
||||
public final static int REG_NONE = 0; // No value type
|
||||
public final static int REG_SZ = 1; // Unicode nul terminated string
|
||||
public final static int REG_EXPAND_SZ = 2; // Unicode nul terminated string
|
||||
// (with environment variable references)
|
||||
public final static int REG_BINARY = 3; // Free form binary
|
||||
public final static int REG_DWORD = 4; // 32-bit number
|
||||
public final static int REG_DWORD_LITTLE_ENDIAN = 4; // 32-bit number (same as REG_DWORD)
|
||||
public final static int REG_DWORD_BIG_ENDIAN = 5; // 32-bit number
|
||||
public final static int REG_LINK = 6; // Symbolic Link (unicode)
|
||||
public final static int REG_MULTI_SZ = 7; // Multiple Unicode strings
|
||||
public final static int REG_RESOURCE_LIST = 8; // Resource list in the resource map
|
||||
public final static int REG_FULL_RESOURCE_DESCRIPTOR = 9; // Resource list in the hardware description
|
||||
public final static int REG_RESOURCE_REQUIREMENTS_LIST = 10;
|
||||
|
||||
public final static int REG_OPTION_RESERVED = 0x00000000; // Parameter is reserved
|
||||
public final static int REG_OPTION_NON_VOLATILE = 0x00000000; // Key is preserved
|
||||
// when system is rebooted
|
||||
public final static int REG_OPTION_VOLATILE = 0x00000001; // Key is not preserved
|
||||
// when system is rebooted
|
||||
public final static int REG_OPTION_CREATE_LINK = 0x00000002; // Created key is a
|
||||
// symbolic link
|
||||
public final static int REG_OPTION_BACKUP_RESTORE = 0x00000004; // open for backup or restore
|
||||
// special access rules
|
||||
// privilege required
|
||||
public final static int REG_OPTION_OPEN_LINK = 0x00000008; // Open symbolic link
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* WINREG.java
|
||||
*
|
||||
* Created on 17. August 2007, 14:32
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package jnacontrib.jna;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface WINREG {
|
||||
public final static int HKEY_CLASSES_ROOT = 0x80000000;
|
||||
public final static int HKEY_CURRENT_USER = 0x80000001;
|
||||
public final static int HKEY_LOCAL_MACHINE = 0x80000002;
|
||||
public final static int HKEY_USERS = 0x80000003;
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* WINSVC.java
|
||||
*
|
||||
* Created on 8. August 2007, 15:07
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package jnacontrib.jna;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary.StdCallCallback;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface WINSVC {
|
||||
public final static int SERVICE_CONTROL_STOP = 0x00000001;
|
||||
public final static int SERVICE_CONTROL_SHUTDOWN = 0x00000005;
|
||||
|
||||
public final static int SERVICE_STOPPED = 0x00000001;
|
||||
public final static int SERVICE_START_PENDING = 0x00000002;
|
||||
public final static int SERVICE_STOP_PENDING = 0x00000003;
|
||||
public final static int SERVICE_RUNNING = 0x00000004;
|
||||
public final static int SERVICE_CONTINUE_PENDING = 0x00000005;
|
||||
public final static int SERVICE_PAUSE_PENDING = 0x00000006;
|
||||
public final static int SERVICE_PAUSED = 0x00000007;
|
||||
|
||||
public final static int SERVICE_ACCEPT_STOP = 0x00000001;
|
||||
public final static int SERVICE_ACCEPT_PAUSE_CONTINUE = 0x00000002;
|
||||
public final static int SERVICE_ACCEPT_SHUTDOWN = 0x00000004;
|
||||
public final static int SERVICE_ACCEPT_PARAMCHANGE = 0x00000008;
|
||||
public final static int SERVICE_ACCEPT_NETBINDCHANGE = 0x00000010;
|
||||
|
||||
public final static int SC_MANAGER_CONNECT = 0x0001;
|
||||
public final static int SC_MANAGER_CREATE_SERVICE = 0x0002;
|
||||
public final static int SC_MANAGER_ENUMERATE_SERVICE = 0x0004;
|
||||
public final static int SC_MANAGER_LOCK = 0x0008;
|
||||
public final static int SC_MANAGER_QUERY_LOCK_STATUS = 0x0010;
|
||||
public final static int SC_MANAGER_MODIFY_BOOT_CONFIG = 0x0020;
|
||||
|
||||
public final static int SC_MANAGER_ALL_ACCESS = WINNT.STANDARD_RIGHTS_REQUIRED |
|
||||
SC_MANAGER_CONNECT |
|
||||
SC_MANAGER_CREATE_SERVICE |
|
||||
SC_MANAGER_ENUMERATE_SERVICE |
|
||||
SC_MANAGER_LOCK |
|
||||
SC_MANAGER_QUERY_LOCK_STATUS |
|
||||
SC_MANAGER_MODIFY_BOOT_CONFIG;
|
||||
|
||||
public final static int SERVICE_QUERY_CONFIG = 0x0001;
|
||||
public final static int SERVICE_CHANGE_CONFIG = 0x0002;
|
||||
public final static int SERVICE_QUERY_STATUS = 0x0004;
|
||||
public final static int SERVICE_ENUMERATE_DEPENDENTS = 0x0008;
|
||||
public final static int SERVICE_START = 0x0010;
|
||||
public final static int SERVICE_STOP = 0x0020;
|
||||
public final static int SERVICE_PAUSE_CONTINUE = 0x0040;
|
||||
public final static int SERVICE_INTERROGATE = 0x0080;
|
||||
public final static int SERVICE_USER_DEFINED_CONTROL = 0x0100;
|
||||
|
||||
public final static int SERVICE_ALL_ACCESS = WINNT.STANDARD_RIGHTS_REQUIRED |
|
||||
SERVICE_QUERY_CONFIG |
|
||||
SERVICE_CHANGE_CONFIG |
|
||||
SERVICE_QUERY_STATUS |
|
||||
SERVICE_ENUMERATE_DEPENDENTS |
|
||||
SERVICE_START |
|
||||
SERVICE_STOP |
|
||||
SERVICE_PAUSE_CONTINUE |
|
||||
SERVICE_INTERROGATE |
|
||||
SERVICE_USER_DEFINED_CONTROL;
|
||||
|
||||
public final static int SERVICE_CONFIG_DESCRIPTION = 1;
|
||||
public final static int SERVICE_CONFIG_FAILURE_ACTIONS = 2;
|
||||
|
||||
public final static int SERVICE_KERNEL_DRIVER = 0x00000001;
|
||||
public final static int SERVICE_FILE_SYSTEM_DRIVER = 0x00000002;
|
||||
public final static int SERVICE_ADAPTER = 0x00000004;
|
||||
public final static int SERVICE_RECOGNIZER_DRIVER = 0x00000008;
|
||||
|
||||
public final static int SERVICE_DRIVER = SERVICE_KERNEL_DRIVER |
|
||||
SERVICE_FILE_SYSTEM_DRIVER |
|
||||
SERVICE_RECOGNIZER_DRIVER;
|
||||
|
||||
public final static int SERVICE_WIN32_OWN_PROCESS = 0x00000010;
|
||||
public final static int SERVICE_WIN32_SHARE_PROCESS = 0x00000020;
|
||||
public final static int SERVICE_WIN32 = SERVICE_WIN32_OWN_PROCESS | SERVICE_WIN32_SHARE_PROCESS;
|
||||
|
||||
public final static int SERVICE_INTERACTIVE_PROCESS = 0x00000100;
|
||||
|
||||
public final static int SERVICE_TYPE_ALL = SERVICE_WIN32 |
|
||||
SERVICE_ADAPTER |
|
||||
SERVICE_DRIVER |
|
||||
SERVICE_INTERACTIVE_PROCESS;
|
||||
|
||||
public final static int SERVICE_BOOT_START = 0x00000000;
|
||||
public final static int SERVICE_SYSTEM_START = 0x00000001;
|
||||
public final static int SERVICE_AUTO_START = 0x00000002;
|
||||
public final static int SERVICE_DEMAND_START = 0x00000003;
|
||||
public final static int SERVICE_DISABLED = 0x00000004;
|
||||
|
||||
public final static int SERVICE_ERROR_IGNORE = 0x00000000;
|
||||
public final static int SERVICE_ERROR_NORMAL = 0x00000001;
|
||||
public final static int SERVICE_ERROR_SEVERE = 0x00000002;
|
||||
public final static int SERVICE_ERROR_CRITICAL = 0x00000003;
|
||||
}
|
||||
@@ -0,0 +1,431 @@
|
||||
/*
|
||||
* Accounts.java
|
||||
*
|
||||
* Created on 7. August 2007, 07:58
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package jnacontrib.win32;
|
||||
|
||||
import jnacontrib.jna.*;
|
||||
import com.sun.jna.*;
|
||||
import com.sun.jna.ptr.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public class Accounts {
|
||||
private static Object userInfoLock = new Object();
|
||||
private static Object groupInfoLock = new Object();
|
||||
|
||||
/** Creates a new instance of Accounts */
|
||||
private Accounts() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing.
|
||||
* @param args arguments
|
||||
* @throws java.lang.Exception on error
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.out.println("FullDomainName: " + getFullDomainName());
|
||||
System.out.println("DomainControllerName: " + getDomainControllerName());
|
||||
System.out.println("UserDomainGroups: " + getUserDomainGroups("administrator"));
|
||||
System.out.println("UserLocalGroups: " + getUserLocalGroups(null, "administrator"));
|
||||
System.out.println("AllDomainGroups: " + getAllDomainGroups());
|
||||
System.out.println("AllDomainUsers: " + getAllDomainUsers());
|
||||
System.out.println("AccountSidString: " + getAccountSidString("administrator"));
|
||||
System.out.println("AccountNameBySid: " + getAccountName(getAccountSid("administrator")));
|
||||
System.out.println("AccountNameBySidString: " + getAccountName(getAccountSidString("administrator")));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name of the domain.
|
||||
*
|
||||
* @return name
|
||||
*/
|
||||
public static String getFullDomainName() {
|
||||
Netapi32.DOMAIN_CONTROLLER_INFO dci;
|
||||
String domain = null;
|
||||
|
||||
dci = getDomainControllerInfo();
|
||||
|
||||
if(dci != null) {
|
||||
domain = dci.DomainName;
|
||||
}
|
||||
return(domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the domain controller.
|
||||
*
|
||||
* @return name
|
||||
*/
|
||||
public static String getDomainControllerName() {
|
||||
Netapi32.DOMAIN_CONTROLLER_INFO dci;
|
||||
String domainController = null;
|
||||
|
||||
dci = getDomainControllerInfo();
|
||||
|
||||
if(dci != null) {
|
||||
domainController = dci.DomainControllerName;
|
||||
}
|
||||
return(domainController);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get info about the domain controller.
|
||||
*
|
||||
* @return info
|
||||
*/
|
||||
private static Netapi32.DOMAIN_CONTROLLER_INFO getDomainControllerInfo() {
|
||||
Netapi32 netapi32;
|
||||
PointerByReference pDci;
|
||||
Netapi32.DOMAIN_CONTROLLER_INFO dci = null;
|
||||
|
||||
netapi32 = Netapi32.INSTANCE;
|
||||
pDci = new PointerByReference();
|
||||
|
||||
if(netapi32.DsGetDcName(null, null, null, null, 0, pDci) == WINERROR.ERROR_SUCCESS) {
|
||||
dci = new Netapi32.DOMAIN_CONTROLLER_INFO(pDci.getValue());
|
||||
netapi32.NetApiBufferFree(pDci.getValue());
|
||||
}
|
||||
return(dci);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the domain groups where a user belongs to.
|
||||
*
|
||||
* @param userName user
|
||||
* @return TreeSet of group names
|
||||
*/
|
||||
public static TreeSet<String> getUserDomainGroups(String userName) {
|
||||
Netapi32 netapi32;
|
||||
PointerByReference buf;
|
||||
IntByReference entriesread;
|
||||
IntByReference totalentries;
|
||||
Netapi32.GROUP_USERS_INFO_0 group;
|
||||
Structure[] groups;
|
||||
TreeSet<String> domainGroups;
|
||||
int i;
|
||||
|
||||
domainGroups = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
|
||||
netapi32 = Netapi32.INSTANCE;
|
||||
|
||||
buf = new PointerByReference();
|
||||
entriesread = new IntByReference();
|
||||
totalentries = new IntByReference();
|
||||
|
||||
if(netapi32.NetUserGetGroups(getDomainControllerName(), // servername
|
||||
userName, // username
|
||||
0, // level of user info in buffer
|
||||
buf, // user info buffer
|
||||
LMCONS.MAX_PREFERRED_LENGTH,
|
||||
entriesread, // read ( out )
|
||||
totalentries // total ( out )
|
||||
) == LMERR.NERR_Success) {
|
||||
group = new Netapi32.GROUP_USERS_INFO_0(buf.getValue());
|
||||
groups = group.toArray(entriesread.getValue());
|
||||
|
||||
for(i = 0; i < entriesread.getValue(); i++) {
|
||||
group = (Netapi32.GROUP_USERS_INFO_0)groups[i];
|
||||
domainGroups.add(group.grui0_name);
|
||||
}
|
||||
|
||||
if(entriesread.getValue() > 0) {
|
||||
netapi32.NetApiBufferFree(buf.getValue());
|
||||
}
|
||||
}
|
||||
return(domainGroups);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the local groups a user belongs to.
|
||||
*
|
||||
* @param serverName server name
|
||||
* @param userName user
|
||||
* @return TreeSetof group names
|
||||
*/
|
||||
public static TreeSet<String> getUserLocalGroups(String serverName, String userName) {
|
||||
Netapi32 netapi32;
|
||||
PointerByReference lbuf;
|
||||
IntByReference lentriesread;
|
||||
IntByReference ltotalentries;
|
||||
Netapi32.LOCALGROUP_USERS_INFO_0 lgroup;
|
||||
Structure[] lgroups;
|
||||
TreeSet<String> localGroups;
|
||||
int i;
|
||||
|
||||
localGroups = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
|
||||
netapi32 = Netapi32.INSTANCE;
|
||||
|
||||
lbuf = new PointerByReference();
|
||||
lentriesread = new IntByReference();
|
||||
ltotalentries = new IntByReference();
|
||||
if(netapi32.NetUserGetLocalGroups(null, // servername
|
||||
userName, // username
|
||||
0, // level of user info in buffer
|
||||
0, // flags
|
||||
lbuf, // user info buffer
|
||||
LMCONS.MAX_PREFERRED_LENGTH,
|
||||
lentriesread, // read ( out )
|
||||
ltotalentries // total ( out )
|
||||
) == LMERR.NERR_Success) {
|
||||
lgroup = new Netapi32.LOCALGROUP_USERS_INFO_0(lbuf.getValue());
|
||||
lgroups = lgroup.toArray(lentriesread.getValue());
|
||||
|
||||
for(i = 0; i < lentriesread.getValue(); i++) {
|
||||
lgroup = (Netapi32.LOCALGROUP_USERS_INFO_0)lgroups[i];
|
||||
localGroups.add(lgroup.lgrui0_name);
|
||||
}
|
||||
|
||||
if(lentriesread.getValue() > 0) {
|
||||
netapi32.NetApiBufferFree(lbuf.getValue());
|
||||
}
|
||||
}
|
||||
return(localGroups);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all domain groups.
|
||||
*
|
||||
* @return TreeSet of group names
|
||||
*/
|
||||
public static TreeSet<String> getAllDomainGroups() {
|
||||
Netapi32 netapi32;
|
||||
PointerByReference gbuf;
|
||||
IntByReference gentriesread;
|
||||
IntByReference gtotalentries;
|
||||
Netapi32.GROUP_INFO_0 ggroup;
|
||||
Structure[] ggroups;
|
||||
TreeSet<String> domainGroups;
|
||||
int i;
|
||||
|
||||
netapi32 = Netapi32.INSTANCE;
|
||||
domainGroups = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
|
||||
gbuf = new PointerByReference();
|
||||
gentriesread = new IntByReference();
|
||||
gtotalentries = new IntByReference();
|
||||
|
||||
if(netapi32.NetGroupEnum(getDomainControllerName(), // servername
|
||||
0, // level of user info in buffer
|
||||
gbuf, // user info buffer
|
||||
LMCONS.MAX_PREFERRED_LENGTH,
|
||||
gentriesread, // read ( out )
|
||||
gtotalentries, // total ( out )
|
||||
null // resume_handle
|
||||
) == LMERR.NERR_Success) {
|
||||
ggroup = new Netapi32.GROUP_INFO_0(gbuf.getValue());
|
||||
ggroups = ggroup.toArray(gentriesread.getValue());
|
||||
|
||||
for(i = 0; i < gentriesread.getValue(); i++) {
|
||||
ggroup = (Netapi32.GROUP_INFO_0)ggroups[i];
|
||||
domainGroups.add(ggroup.grpi0_name);
|
||||
}
|
||||
|
||||
if(gentriesread.getValue() > 0) {
|
||||
netapi32.NetApiBufferFree(gbuf.getValue());
|
||||
}
|
||||
}
|
||||
return(domainGroups);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all domain users.
|
||||
*
|
||||
* @return TreeSet of user names
|
||||
*/
|
||||
public static TreeSet<String> getAllDomainUsers() {
|
||||
Netapi32 netapi32;
|
||||
PointerByReference ubuf;
|
||||
IntByReference uentriesread;
|
||||
IntByReference utotalentries;
|
||||
Netapi32.USER_INFO_0 user;
|
||||
Structure[] users;
|
||||
TreeSet<String> domainUsers;
|
||||
int i;
|
||||
|
||||
netapi32 = Netapi32.INSTANCE;
|
||||
domainUsers = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
|
||||
ubuf = new PointerByReference();
|
||||
uentriesread = new IntByReference();
|
||||
utotalentries = new IntByReference();
|
||||
|
||||
if(netapi32.NetUserEnum(getDomainControllerName(), // servername
|
||||
0, // level of user info in buffer
|
||||
LMACCESS.FILTER_NORMAL_ACCOUNT, // filter
|
||||
ubuf, // user info buffer
|
||||
LMCONS.MAX_PREFERRED_LENGTH,
|
||||
uentriesread, // read ( out )
|
||||
utotalentries, // total ( out )
|
||||
null // resume_handle
|
||||
) == LMERR.NERR_Success) {
|
||||
user = new Netapi32.USER_INFO_0(ubuf.getValue());
|
||||
users = user.toArray(uentriesread.getValue());
|
||||
|
||||
for(i = 0; i < uentriesread.getValue(); i++) {
|
||||
user = (Netapi32.USER_INFO_0)users[i];
|
||||
domainUsers.add(user.usri0_name);
|
||||
}
|
||||
|
||||
if(uentriesread.getValue() > 0) {
|
||||
netapi32.NetApiBufferFree(ubuf.getValue());
|
||||
}
|
||||
}
|
||||
return(domainUsers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get SID of account.
|
||||
*
|
||||
* @param account account name
|
||||
* @return SID
|
||||
*/
|
||||
public static byte[] getAccountSid(String account) {
|
||||
Advapi32 advapi32;
|
||||
IntByReference cbSid;
|
||||
IntByReference cchReferencedDomainName;
|
||||
PointerByReference peUse;
|
||||
String sidString = null;
|
||||
byte[] sid;
|
||||
char[] referencedDomainName;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
|
||||
cbSid = new IntByReference(0);
|
||||
cchReferencedDomainName = new IntByReference(0);
|
||||
peUse = new PointerByReference();
|
||||
advapi32.LookupAccountName(null, account, null, cbSid,
|
||||
null, cchReferencedDomainName, peUse);
|
||||
sid = new byte[cbSid.getValue()];
|
||||
referencedDomainName = new char[cchReferencedDomainName.getValue()];
|
||||
|
||||
if(! advapi32.LookupAccountName(null, account, sid, cbSid,
|
||||
referencedDomainName, cchReferencedDomainName, peUse)) {
|
||||
sid = null;
|
||||
}
|
||||
return(sid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get account name of SID.
|
||||
*
|
||||
* @param sid SID
|
||||
* @return account name
|
||||
*/
|
||||
public static String getAccountName(byte[] sid) {
|
||||
Advapi32 advapi32;
|
||||
IntByReference cchName;
|
||||
IntByReference cchReferencedDomainName;
|
||||
PointerByReference peUse;
|
||||
String sidString = null;
|
||||
char[] lpName;
|
||||
char[] referencedDomainName;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
|
||||
cchName = new IntByReference(0);
|
||||
cchReferencedDomainName = new IntByReference(0);
|
||||
peUse = new PointerByReference();
|
||||
advapi32.LookupAccountSid(null, sid, null, cchName,
|
||||
null, cchReferencedDomainName, peUse);
|
||||
lpName = new char[cchName.getValue()];
|
||||
referencedDomainName = new char[cchReferencedDomainName.getValue()];
|
||||
|
||||
if(! advapi32.LookupAccountSid(null, sid, lpName, cchName,
|
||||
referencedDomainName, cchReferencedDomainName, peUse)) {
|
||||
lpName = null;
|
||||
}
|
||||
|
||||
if(lpName != null) {
|
||||
return(Native.toString(lpName));
|
||||
|
||||
} else {
|
||||
return(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get SID of account as String.
|
||||
*
|
||||
* @param account account name
|
||||
* @return SID
|
||||
*/
|
||||
public static String getAccountSidString(String account) {
|
||||
String sidString = null;
|
||||
byte[] sid;
|
||||
|
||||
sid = getAccountSid(account);
|
||||
|
||||
if(sid != null) {
|
||||
sidString = convertSidToString(sid);
|
||||
}
|
||||
return(sidString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get account of SID String.
|
||||
*
|
||||
* @param sidString SID
|
||||
* @return account name
|
||||
*/
|
||||
public static String getAccountName(String sidString) {
|
||||
String name = null;
|
||||
byte[] sid;
|
||||
|
||||
sid = convertStringToSid(sidString);
|
||||
|
||||
if(sid != null) {
|
||||
name = getAccountName(sid);
|
||||
}
|
||||
return(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a SID to String.
|
||||
*
|
||||
* @param sid SID
|
||||
* @return SID String
|
||||
*/
|
||||
public static String convertSidToString(byte[] sid) {
|
||||
Advapi32 advapi32;
|
||||
PointerByReference stringSid;
|
||||
String sidString = null;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
|
||||
stringSid = new PointerByReference();
|
||||
|
||||
if(advapi32.ConvertSidToStringSid(sid, stringSid)) {
|
||||
sidString = stringSid.getValue().getString(0, true);
|
||||
Kernel32b.INSTANCE.LocalFree(stringSid.getValue());
|
||||
}
|
||||
return(sidString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a SID String to SID.
|
||||
*
|
||||
* @param sidString SID String
|
||||
* @return SID
|
||||
*/
|
||||
public static byte[] convertStringToSid(String sidString) {
|
||||
Advapi32 advapi32;
|
||||
PointerByReference pSid;
|
||||
byte[] sid = null;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
|
||||
pSid = new PointerByReference();
|
||||
|
||||
if(advapi32.ConvertStringSidToSid(sidString, pSid)) {
|
||||
sid = pSid.getValue().getByteArray(0, 100);
|
||||
Kernel32b.INSTANCE.LocalFree(pSid.getValue());
|
||||
}
|
||||
return(sid);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,464 @@
|
||||
/*
|
||||
* Registry.java
|
||||
*
|
||||
* Created on 17. August 2007, 15:07
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package jnacontrib.win32;
|
||||
|
||||
import jnacontrib.jna.*;
|
||||
import com.sun.jna.ptr.ByteByReference;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* Methods for accessing the Windows Registry. Only String and DWORD values supported at the moment.
|
||||
*/
|
||||
public class Registry {
|
||||
public static enum REGISTRY_ROOT_KEY{CLASSES_ROOT, CURRENT_USER, LOCAL_MACHINE, USERS};
|
||||
private final static HashMap<REGISTRY_ROOT_KEY, Integer> rootKeyMap = new HashMap<REGISTRY_ROOT_KEY, Integer>();
|
||||
|
||||
static {
|
||||
rootKeyMap.put(REGISTRY_ROOT_KEY.CLASSES_ROOT, WINREG.HKEY_CLASSES_ROOT);
|
||||
rootKeyMap.put(REGISTRY_ROOT_KEY.CURRENT_USER, WINREG.HKEY_CURRENT_USER);
|
||||
rootKeyMap.put(REGISTRY_ROOT_KEY.LOCAL_MACHINE, WINREG.HKEY_LOCAL_MACHINE);
|
||||
rootKeyMap.put(REGISTRY_ROOT_KEY.USERS, WINREG.HKEY_USERS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Testing.
|
||||
*
|
||||
* @param args arguments
|
||||
* @throws java.lang.Exception on error
|
||||
*/
|
||||
public static void main(String[] args) throws Exception {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets one of the root keys.
|
||||
*
|
||||
* @param key key type
|
||||
* @return root key
|
||||
*/
|
||||
private static int getRegistryRootKey(REGISTRY_ROOT_KEY key) {
|
||||
Advapi32 advapi32;
|
||||
IntByReference pHandle;
|
||||
int handle = 0;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
pHandle = new IntByReference();
|
||||
|
||||
if(advapi32.RegOpenKeyEx(rootKeyMap.get(key), null, 0, 0, pHandle) == WINERROR.ERROR_SUCCESS) {
|
||||
handle = pHandle.getValue();
|
||||
}
|
||||
return(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a key.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param subKeyName name of the key
|
||||
* @param access access mode
|
||||
* @return handle to the key or 0
|
||||
*/
|
||||
private static int openKey(REGISTRY_ROOT_KEY rootKey, String subKeyName, int access) {
|
||||
Advapi32 advapi32;
|
||||
IntByReference pHandle;
|
||||
int rootKeyHandle;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
rootKeyHandle = getRegistryRootKey(rootKey);
|
||||
pHandle = new IntByReference();
|
||||
|
||||
if(advapi32.RegOpenKeyEx(rootKeyHandle, subKeyName, 0, access, pHandle) == WINERROR.ERROR_SUCCESS) {
|
||||
return(pHandle.getValue());
|
||||
|
||||
} else {
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Windows buffer to a Java String.
|
||||
*
|
||||
* @param buf buffer
|
||||
* @throws java.io.UnsupportedEncodingException on error
|
||||
* @return String
|
||||
*/
|
||||
private static String convertBufferToString(byte[] buf) throws UnsupportedEncodingException {
|
||||
return(new String(buf, 0, buf.length - 2, "UTF-16LE"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Windows buffer to an int.
|
||||
*
|
||||
* @param buf buffer
|
||||
* @return int
|
||||
*/
|
||||
private static int convertBufferToInt(byte[] buf) {
|
||||
return(((int)(buf[0] & 0xff)) + (((int)(buf[1] & 0xff)) << 8) + (((int)(buf[2] & 0xff)) << 16) + (((int)(buf[3] & 0xff)) << 24));
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a String value.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param subKeyName key name
|
||||
* @param name value name
|
||||
* @throws java.io.UnsupportedEncodingException on error
|
||||
* @return String or null
|
||||
*/
|
||||
public static String getStringValue(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name) throws UnsupportedEncodingException {
|
||||
Advapi32 advapi32;
|
||||
IntByReference pType, lpcbData;
|
||||
byte[] lpData = new byte[1];
|
||||
int handle = 0;
|
||||
String ret = null;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
pType = new IntByReference();
|
||||
lpcbData = new IntByReference();
|
||||
handle = openKey(rootKey, subKeyName, WINNT.KEY_READ);
|
||||
|
||||
if(handle != 0) {
|
||||
|
||||
if(advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) == WINERROR.ERROR_MORE_DATA) {
|
||||
lpData = new byte[lpcbData.getValue()];
|
||||
|
||||
if(advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) == WINERROR.ERROR_SUCCESS) {
|
||||
ret = convertBufferToString(lpData);
|
||||
}
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an int value.
|
||||
*
|
||||
*
|
||||
* @return int or 0
|
||||
* @param rootKey root key
|
||||
* @param subKeyName key name
|
||||
* @param name value name
|
||||
*/
|
||||
public static int getIntValue(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name) {
|
||||
Advapi32 advapi32;
|
||||
IntByReference pType, lpcbData;
|
||||
byte[] lpData = new byte[1];
|
||||
int handle = 0;
|
||||
int ret = 0;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
pType = new IntByReference();
|
||||
lpcbData = new IntByReference();
|
||||
handle = openKey(rootKey, subKeyName, WINNT.KEY_READ);
|
||||
|
||||
if(handle != 0) {
|
||||
|
||||
if(advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) == WINERROR.ERROR_MORE_DATA) {
|
||||
lpData = new byte[lpcbData.getValue()];
|
||||
|
||||
if(advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) == WINERROR.ERROR_SUCCESS) {
|
||||
ret = convertBufferToInt(lpData);
|
||||
}
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a value.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param subKeyName key name
|
||||
* @param name value name
|
||||
* @return true on success
|
||||
*/
|
||||
public static boolean deleteValue(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name) {
|
||||
Advapi32 advapi32;
|
||||
int handle;
|
||||
boolean ret = true;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
|
||||
handle = openKey(rootKey, subKeyName, WINNT.KEY_READ | WINNT.KEY_WRITE);
|
||||
|
||||
if(handle != 0) {
|
||||
if(advapi32.RegDeleteValue(handle, name) == WINERROR.ERROR_SUCCESS) {
|
||||
ret = true;
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a String value.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param subKeyName key name
|
||||
* @param name value name
|
||||
* @param value value
|
||||
* @throws java.io.UnsupportedEncodingException on error
|
||||
* @return true on success
|
||||
*/
|
||||
public static boolean setStringValue(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name, String value) throws UnsupportedEncodingException {
|
||||
Advapi32 advapi32;
|
||||
int handle;
|
||||
byte[] data;
|
||||
boolean ret = false;
|
||||
|
||||
data = Arrays.copyOf(value.getBytes("UTF-16LE"), value.length() * 2 + 2);
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
handle = openKey(rootKey, subKeyName, WINNT.KEY_READ | WINNT.KEY_WRITE);
|
||||
|
||||
if(handle != 0) {
|
||||
if(advapi32.RegSetValueEx(handle, name, 0, WINNT.REG_SZ, data, data.length) == WINERROR.ERROR_SUCCESS) {
|
||||
ret = true;
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an int value.
|
||||
*
|
||||
*
|
||||
* @return true on success
|
||||
* @param rootKey root key
|
||||
* @param subKeyName key name
|
||||
* @param name value name
|
||||
* @param value value
|
||||
*/
|
||||
public static boolean setIntValue(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name, int value) {
|
||||
Advapi32 advapi32;
|
||||
int handle;
|
||||
byte[] data;
|
||||
boolean ret = false;
|
||||
|
||||
data = new byte[4];
|
||||
data[0] = (byte)(value & 0xff);
|
||||
data[1] = (byte)((value >> 8) & 0xff);
|
||||
data[2] = (byte)((value >> 16) & 0xff);
|
||||
data[3] = (byte)((value >> 24) & 0xff);
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
handle = openKey(rootKey, subKeyName, WINNT.KEY_READ | WINNT.KEY_WRITE);
|
||||
|
||||
if(handle != 0) {
|
||||
|
||||
if(advapi32.RegSetValueEx(handle, name, 0, WINNT.REG_DWORD, data, data.length) == WINERROR.ERROR_SUCCESS) {
|
||||
ret = true;
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for existence of a value.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param subKeyName key name
|
||||
* @param name value name
|
||||
* @return true if exists
|
||||
*/
|
||||
public static boolean valueExists(REGISTRY_ROOT_KEY rootKey, String subKeyName, String name) {
|
||||
Advapi32 advapi32;
|
||||
IntByReference pType, lpcbData;
|
||||
byte[] lpData = new byte[1];
|
||||
int handle = 0;
|
||||
boolean ret = false;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
pType = new IntByReference();
|
||||
lpcbData = new IntByReference();
|
||||
handle = openKey(rootKey, subKeyName, WINNT.KEY_READ);
|
||||
|
||||
if(handle != 0) {
|
||||
|
||||
if(advapi32.RegQueryValueEx(handle, name, null, pType, lpData, lpcbData) != WINERROR.ERROR_FILE_NOT_FOUND) {
|
||||
ret = true;
|
||||
|
||||
} else {
|
||||
ret = false;
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new key.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param parent name of parent key
|
||||
* @param name key name
|
||||
* @return true on success
|
||||
*/
|
||||
public static boolean createKey(REGISTRY_ROOT_KEY rootKey, String parent, String name) {
|
||||
Advapi32 advapi32;
|
||||
IntByReference hkResult, dwDisposition;
|
||||
int handle = 0;
|
||||
boolean ret = false;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
hkResult = new IntByReference();
|
||||
dwDisposition = new IntByReference();
|
||||
handle = openKey(rootKey, parent, WINNT.KEY_READ);
|
||||
|
||||
if(handle != 0) {
|
||||
|
||||
if(advapi32.RegCreateKeyEx(handle, name, 0, null, WINNT.REG_OPTION_NON_VOLATILE, WINNT.KEY_READ, null,
|
||||
hkResult, dwDisposition) == WINERROR.ERROR_SUCCESS) {
|
||||
ret = true;
|
||||
advapi32.RegCloseKey(hkResult.getValue());
|
||||
|
||||
} else {
|
||||
ret = false;
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a key.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param parent name of parent key
|
||||
* @param name key name
|
||||
* @return true on success
|
||||
*/
|
||||
public static boolean deleteKey(REGISTRY_ROOT_KEY rootKey, String parent, String name) {
|
||||
Advapi32 advapi32;
|
||||
int handle = 0;
|
||||
boolean ret = false;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
handle = openKey(rootKey, parent, WINNT.KEY_READ);
|
||||
|
||||
if(handle != 0) {
|
||||
|
||||
if(advapi32.RegDeleteKey(handle, name) == WINERROR.ERROR_SUCCESS) {
|
||||
ret = true;
|
||||
|
||||
} else {
|
||||
ret = false;
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all sub keys of a key.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param parent key name
|
||||
* @return array with all sub key names
|
||||
*/
|
||||
public static String[] getSubKeys(REGISTRY_ROOT_KEY rootKey, String parent) {
|
||||
Advapi32 advapi32;
|
||||
int handle = 0, dwIndex;
|
||||
char[] lpName;
|
||||
IntByReference lpcName;
|
||||
WINBASE.FILETIME lpftLastWriteTime;
|
||||
TreeSet<String> subKeys = new TreeSet<String>();
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
handle = openKey(rootKey, parent, WINNT.KEY_READ);
|
||||
lpName = new char[256];
|
||||
lpcName = new IntByReference(256);
|
||||
lpftLastWriteTime = new WINBASE.FILETIME();
|
||||
|
||||
if(handle != 0) {
|
||||
dwIndex = 0;
|
||||
|
||||
while(advapi32.RegEnumKeyEx(handle, dwIndex, lpName, lpcName, null,
|
||||
null, null, lpftLastWriteTime) == WINERROR.ERROR_SUCCESS) {
|
||||
subKeys.add(new String(lpName, 0, lpcName.getValue()));
|
||||
lpcName.setValue(256);
|
||||
dwIndex++;
|
||||
}
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
|
||||
return(subKeys.toArray(new String[]{}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all values under a key.
|
||||
*
|
||||
* @param rootKey root key
|
||||
* @param key jey name
|
||||
* @throws java.io.UnsupportedEncodingException on error
|
||||
* @return TreeMap with name and value pairs
|
||||
*/
|
||||
public static TreeMap<String, Object> getValues(REGISTRY_ROOT_KEY rootKey, String key) throws UnsupportedEncodingException {
|
||||
Advapi32 advapi32;
|
||||
int handle = 0, dwIndex, result = 0;
|
||||
char[] lpValueName;
|
||||
byte[] lpData;
|
||||
IntByReference lpcchValueName, lpType, lpcbData;
|
||||
String name;
|
||||
TreeMap<String, Object> values = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
handle = openKey(rootKey, key, WINNT.KEY_READ);
|
||||
lpValueName = new char[16384];
|
||||
lpcchValueName = new IntByReference(16384);
|
||||
lpType = new IntByReference();
|
||||
lpData = new byte[1];
|
||||
lpcbData = new IntByReference();
|
||||
|
||||
if(handle != 0) {
|
||||
dwIndex = 0;
|
||||
|
||||
do {
|
||||
lpcbData.setValue(0);
|
||||
result = advapi32.RegEnumValue(handle, dwIndex, lpValueName, lpcchValueName, null,
|
||||
lpType, lpData, lpcbData);
|
||||
|
||||
if(result == WINERROR.ERROR_MORE_DATA) {
|
||||
lpData = new byte[lpcbData.getValue()];
|
||||
lpcchValueName = new IntByReference(16384);
|
||||
result = advapi32.RegEnumValue(handle, dwIndex, lpValueName, lpcchValueName, null,
|
||||
lpType, lpData, lpcbData);
|
||||
|
||||
if(result == WINERROR.ERROR_SUCCESS) {
|
||||
name = new String(lpValueName, 0, lpcchValueName.getValue());
|
||||
|
||||
switch(lpType.getValue()) {
|
||||
case WINNT.REG_SZ:
|
||||
values.put(name, convertBufferToString(lpData));
|
||||
break;
|
||||
case WINNT.REG_DWORD:
|
||||
values.put(name, convertBufferToInt(lpData));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
dwIndex++;
|
||||
} while(result == WINERROR.ERROR_SUCCESS);
|
||||
|
||||
advapi32.RegCloseKey(handle);
|
||||
}
|
||||
return(values);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* TestService.java
|
||||
*
|
||||
* Created on 12. September 2007, 12:49
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package jnacontrib.win32;
|
||||
|
||||
/**
|
||||
* TestService.
|
||||
*/
|
||||
public class TestService extends Win32Service {
|
||||
|
||||
/**
|
||||
* main.
|
||||
* @param args arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
TestService service = new TestService();
|
||||
|
||||
if(args.length == 1) {
|
||||
|
||||
if(args[0].equalsIgnoreCase("install")) {
|
||||
System.out.println(service.install("TestService DisplayName", "TestService Description",
|
||||
null, null, null));
|
||||
|
||||
} else if(args[0].equalsIgnoreCase("uninstall")) {
|
||||
System.out.println(service.uninstall());
|
||||
|
||||
} else {
|
||||
System.out.println("Arguments:");
|
||||
System.out.println("install = install service");
|
||||
System.out.println("uninstall = uninstall service");
|
||||
System.out.println("<none> = run service");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
} else {
|
||||
service.init();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of TestService.
|
||||
*/
|
||||
public TestService() {
|
||||
super("TestService");
|
||||
}
|
||||
|
||||
/**
|
||||
* Will be called on start.
|
||||
*/
|
||||
public void onStart() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Will be called on stop.
|
||||
*/
|
||||
public void onStop() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,311 @@
|
||||
/*
|
||||
* Win32Service.java
|
||||
*
|
||||
* Created on 12. September 2007, 12:05
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package jnacontrib.win32;
|
||||
|
||||
import jnacontrib.jna.*;
|
||||
import com.sun.jna.Pointer;
|
||||
|
||||
/**
|
||||
* Baseclass for a Win32 service.
|
||||
*/
|
||||
public abstract class Win32Service {
|
||||
protected String serviceName;
|
||||
private ServiceMain serviceMain;
|
||||
private ServiceControl serviceControl;
|
||||
private Pointer serviceStatusHandle;
|
||||
private Object waitObject = new Object();
|
||||
|
||||
/**
|
||||
* Creates a new instance of Win32Service.
|
||||
*
|
||||
* @param serviceName internal name of the service
|
||||
*/
|
||||
public Win32Service(String serviceName) {
|
||||
this.serviceName = serviceName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Install the service.
|
||||
*
|
||||
* @param displayName visible name
|
||||
* @param description description
|
||||
* @param dependencies array of other services to depend on or null
|
||||
* @param account service account or null for LocalSystem
|
||||
* @param password password for service account or null
|
||||
* @throws java.lang.Exception
|
||||
* @return true on success
|
||||
*/
|
||||
public boolean install(String displayName, String description, String[] dependencies, String account, String password) {
|
||||
return(install(displayName, description, dependencies, account, password, "java.exe -cp \"" +
|
||||
System.getProperty("java.class.path") + "\" -Xrs " + this.getClass().getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Install the service.
|
||||
*
|
||||
* @return true on success
|
||||
* @param displayName visible name
|
||||
* @param description description
|
||||
* @param dependencies array of other services to depend on or null
|
||||
* @param account service account or null for LocalSystem
|
||||
* @param password password for service account or null
|
||||
* @param command command line to start the service
|
||||
* @throws java.lang.Exception
|
||||
*/
|
||||
public boolean install(String displayName, String description, String[] dependencies, String account, String password, String command) {
|
||||
Advapi32 advapi32;
|
||||
Advapi32.SERVICE_DESCRIPTION desc;
|
||||
Pointer serviceManager, service;
|
||||
boolean success = false;
|
||||
String dep = "";
|
||||
|
||||
if(dependencies != null) {
|
||||
for(String s : dependencies) {
|
||||
dep += s + "\0";
|
||||
}
|
||||
}
|
||||
dep += "\0";
|
||||
|
||||
desc = new Advapi32.SERVICE_DESCRIPTION();
|
||||
desc.lpDescription = description;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
serviceManager = openServiceControlManager(null, WINSVC.SC_MANAGER_ALL_ACCESS);
|
||||
|
||||
if(serviceManager != null) {
|
||||
service = advapi32.CreateService(serviceManager, serviceName, displayName,
|
||||
WINSVC.SERVICE_ALL_ACCESS, WINSVC.SERVICE_WIN32_OWN_PROCESS, WINSVC.SERVICE_DEMAND_START,
|
||||
WINSVC.SERVICE_ERROR_NORMAL,
|
||||
command,
|
||||
null, null, dep, account, password);
|
||||
|
||||
if(service != null) {
|
||||
success = advapi32.ChangeServiceConfig2(service, WINSVC.SERVICE_CONFIG_DESCRIPTION, desc);
|
||||
advapi32.CloseServiceHandle(service);
|
||||
}
|
||||
advapi32.CloseServiceHandle(serviceManager);
|
||||
}
|
||||
return(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstall the service.
|
||||
*
|
||||
* @throws java.lang.Exception
|
||||
* @return true on success
|
||||
*/
|
||||
public boolean uninstall() {
|
||||
Advapi32 advapi32;
|
||||
Pointer serviceManager, service;
|
||||
boolean success = false;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
serviceManager = openServiceControlManager(null, WINSVC.SC_MANAGER_ALL_ACCESS);
|
||||
|
||||
if(serviceManager != null) {
|
||||
service = advapi32.OpenService(serviceManager, serviceName, WINSVC.SERVICE_ALL_ACCESS);
|
||||
|
||||
if(service != null) {
|
||||
success = advapi32.DeleteService(service);
|
||||
advapi32.CloseServiceHandle(service);
|
||||
}
|
||||
advapi32.CloseServiceHandle(serviceManager);
|
||||
}
|
||||
return(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask the ServiceControlManager to start the service.
|
||||
* @return true on success
|
||||
*/
|
||||
public boolean start() {
|
||||
Advapi32 advapi32;
|
||||
Pointer serviceManager, service;
|
||||
boolean success = false;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
|
||||
serviceManager = openServiceControlManager(null, WINNT.GENERIC_EXECUTE);
|
||||
|
||||
if(serviceManager != null) {
|
||||
service = advapi32.OpenService(serviceManager, serviceName, WINNT.GENERIC_EXECUTE);
|
||||
|
||||
if(service != null) {
|
||||
success = advapi32.StartService(service, 0, null);
|
||||
advapi32.CloseServiceHandle(service);
|
||||
}
|
||||
advapi32.CloseServiceHandle(serviceManager);
|
||||
}
|
||||
|
||||
return(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask the ServiceControlManager to stop the service.
|
||||
* @return true on success
|
||||
*/
|
||||
public boolean stop() throws Exception {
|
||||
Advapi32 advapi32;
|
||||
Pointer serviceManager, service;
|
||||
Advapi32.SERVICE_STATUS serviceStatus;
|
||||
boolean success = false;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
|
||||
serviceManager = openServiceControlManager(null, WINNT.GENERIC_EXECUTE);
|
||||
|
||||
if(serviceManager != null) {
|
||||
service = advapi32.OpenService(serviceManager, serviceName, WINNT.GENERIC_EXECUTE);
|
||||
|
||||
if(service != null) {
|
||||
serviceStatus = new Advapi32.SERVICE_STATUS();
|
||||
success = advapi32.ControlService(service, WINSVC.SERVICE_CONTROL_STOP, serviceStatus);
|
||||
advapi32.CloseServiceHandle(service);
|
||||
}
|
||||
advapi32.CloseServiceHandle(serviceManager);
|
||||
}
|
||||
|
||||
return(success);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the service, connect to the ServiceControlManager.
|
||||
*/
|
||||
public void init() {
|
||||
Advapi32 advapi32;
|
||||
Advapi32.SERVICE_TABLE_ENTRY[] entries = new Advapi32.SERVICE_TABLE_ENTRY[2];
|
||||
Advapi32.SERVICE_TABLE_ENTRY entry;
|
||||
|
||||
serviceMain = new ServiceMain();
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
entry = new Advapi32.SERVICE_TABLE_ENTRY();
|
||||
entry.lpServiceName = serviceName;
|
||||
entry.lpServiceProc = serviceMain;
|
||||
|
||||
advapi32.StartServiceCtrlDispatcher(entry.toArray(2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a handle to the ServiceControlManager.
|
||||
*
|
||||
* @param machine name of the machine or null for localhost
|
||||
* @param access access flags
|
||||
* @return handle to ServiceControlManager or null when failed
|
||||
*/
|
||||
private Pointer openServiceControlManager(String machine, int access) {
|
||||
Pointer handle = null;
|
||||
Advapi32 advapi32;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
handle = advapi32.OpenSCManager(machine, null, access);
|
||||
return(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Report service status to the ServiceControlManager.
|
||||
*
|
||||
* @param status status
|
||||
* @param win32ExitCode exit code
|
||||
* @param waitHint time to wait
|
||||
*/
|
||||
private void reportStatus(int status, int win32ExitCode, int waitHint) {
|
||||
Advapi32 advapi32;
|
||||
Advapi32.SERVICE_STATUS serviceStatus;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
serviceStatus = new Advapi32.SERVICE_STATUS();
|
||||
serviceStatus.dwServiceType = WINNT.SERVICE_WIN32_OWN_PROCESS;
|
||||
serviceStatus.dwControlsAccepted = WINSVC.SERVICE_ACCEPT_STOP | WINSVC.SERVICE_ACCEPT_SHUTDOWN;
|
||||
serviceStatus.dwWin32ExitCode = win32ExitCode;
|
||||
serviceStatus.dwWaitHint = waitHint;
|
||||
serviceStatus.dwCurrentState = status;
|
||||
|
||||
advapi32.SetServiceStatus(serviceStatusHandle, serviceStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when service is starting.
|
||||
*/
|
||||
public abstract void onStart();
|
||||
|
||||
/*
|
||||
* Called when service should stop.
|
||||
*/
|
||||
public abstract void onStop();
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of the service main function.
|
||||
*/
|
||||
private class ServiceMain implements Advapi32.SERVICE_MAIN_FUNCTION {
|
||||
|
||||
/**
|
||||
* Called when the service is starting.
|
||||
*
|
||||
* @param dwArgc number of arguments
|
||||
* @param lpszArgv pointer to arguments
|
||||
*/
|
||||
public void callback(int dwArgc, Pointer lpszArgv) {
|
||||
Advapi32 advapi32;
|
||||
|
||||
advapi32 = Advapi32.INSTANCE;
|
||||
|
||||
serviceControl = new ServiceControl();
|
||||
serviceStatusHandle = advapi32.RegisterServiceCtrlHandlerEx(serviceName, serviceControl, null);
|
||||
|
||||
reportStatus(WINSVC.SERVICE_START_PENDING, WINERROR.NO_ERROR, 3000);
|
||||
reportStatus(WINSVC.SERVICE_RUNNING, WINERROR.NO_ERROR, 0);
|
||||
|
||||
onStart();
|
||||
|
||||
try {
|
||||
synchronized(waitObject) {
|
||||
waitObject.wait();
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
}
|
||||
reportStatus(WINSVC.SERVICE_STOPPED, WINERROR.NO_ERROR, 0);
|
||||
|
||||
// Avoid returning from ServiceMain, which will cause a crash
|
||||
// See http://support.microsoft.com/kb/201349, which recommends
|
||||
// having init() wait for this thread.
|
||||
// Waiting on this thread in init() won't fix the crash, though.
|
||||
//System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implementation of the service control function.
|
||||
*/
|
||||
private class ServiceControl implements Advapi32.HandlerEx {
|
||||
|
||||
/**
|
||||
* Called when the service get a control code.
|
||||
*
|
||||
* @param dwControl
|
||||
* @param dwEventType
|
||||
* @param lpEventData
|
||||
* @param lpContext
|
||||
*/
|
||||
public int callback(int dwControl, int dwEventType, Pointer lpEventData, Pointer lpContext) {
|
||||
switch(dwControl) {
|
||||
case WINSVC.SERVICE_CONTROL_STOP:
|
||||
case WINSVC.SERVICE_CONTROL_SHUTDOWN:
|
||||
reportStatus(WINSVC.SERVICE_STOP_PENDING, WINERROR.NO_ERROR, 5000);
|
||||
onStop();
|
||||
synchronized(waitObject) {
|
||||
waitObject.notifyAll();
|
||||
}
|
||||
}
|
||||
return WINERROR.NO_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" output="build.eclipse/contrib-test-classes" path="test"/>
|
||||
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/jna"/>
|
||||
<classpathentry kind="lib" path="/jna/dist/jna.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>platform</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="platform" default="default" basedir=".">
|
||||
<description>Builds, tests, and runs the project platform.</description>
|
||||
<import file="nbproject/build-impl.xml"/>
|
||||
<!--
|
||||
|
||||
There exist several targets which are by default empty and which can be
|
||||
used for execution of your tasks. These targets are usually executed
|
||||
before and after some main targets. They are:
|
||||
|
||||
-pre-init: called before initialization of project properties
|
||||
-post-init: called after initialization of project properties
|
||||
-pre-compile: called before javac compilation
|
||||
-post-compile: called after javac compilation
|
||||
-pre-compile-single: called before javac compilation of single file
|
||||
-post-compile-single: called after javac compilation of single file
|
||||
-pre-compile-test: called before javac compilation of JUnit tests
|
||||
-post-compile-test: called after javac compilation of JUnit tests
|
||||
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||
-pre-jar: called before JAR building
|
||||
-post-jar: called after JAR building
|
||||
-post-clean: called after cleaning build products
|
||||
|
||||
(Targets beginning with '-' are not intended to be called on their own.)
|
||||
|
||||
Example of inserting an obfuscator after compilation could look like this:
|
||||
|
||||
<target name="-post-compile">
|
||||
<obfuscate>
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
</obfuscate>
|
||||
</target>
|
||||
|
||||
For list of available properties check the imported
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
|
||||
Another way to customize the build is by overriding existing main targets.
|
||||
The targets of interest are:
|
||||
|
||||
-init-macrodef-javac: defines macro for javac compilation
|
||||
-init-macrodef-junit: defines macro for junit execution
|
||||
-init-macrodef-debug: defines macro for class debugging
|
||||
-init-macrodef-java: defines macro for class execution
|
||||
-do-jar-with-manifest: JAR building (if you are using a manifest)
|
||||
-do-jar-without-manifest: JAR building (if you are not using a manifest)
|
||||
run: execution of project
|
||||
-javadoc-build: Javadoc generation
|
||||
test-report: JUnit report generation
|
||||
|
||||
An example of overriding the target for project execution could look like this:
|
||||
|
||||
<target name="run" depends="JnaContrib-impl.jar">
|
||||
<exec dir="bin" executable="launcher.exe">
|
||||
<arg file="${dist.jar}"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
Notice that the overridden target depends on the jar target and not only on
|
||||
the compile target as the regular run target does. Again, for a list of available
|
||||
properties which you can use, check the target you are overriding in the
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
-->
|
||||
<condition property="tests.platform" value="win32">
|
||||
<os family="windows"/>
|
||||
</condition>
|
||||
<target name="test" description="Run unit tests." if="tests.platform">
|
||||
<antcall target="test-win32" />
|
||||
</target>
|
||||
<target name="test-win32" depends="init,compile-test,-pre-test-run,-do-test-run,test-report,-post-test-run,-test-browse" />
|
||||
</project>
|
||||
@@ -0,0 +1,541 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
*** GENERATED FROM project.xml - DO NOT EDIT ***
|
||||
*** EDIT ../build.xml INSTEAD ***
|
||||
|
||||
For the purpose of easier reading the script
|
||||
is divided into following sections:
|
||||
|
||||
- initialization
|
||||
- compilation
|
||||
- jar
|
||||
- execution
|
||||
- debugging
|
||||
- javadoc
|
||||
- junit compilation
|
||||
- junit execution
|
||||
- junit debugging
|
||||
- applet
|
||||
- cleanup
|
||||
|
||||
-->
|
||||
<project name="platform-impl" default="default" basedir=".." xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:j2seproject2="http://www.netbeans.org/ns/j2se-project/2" xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:jaxws="http://www.netbeans.org/ns/jax-ws/1">
|
||||
<target name="default" depends="test,jar,javadoc" description="Build and test whole project."/>
|
||||
<!--
|
||||
======================
|
||||
INITIALIZATION SECTION
|
||||
======================
|
||||
-->
|
||||
<target name="-pre-init">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-init-private" depends="-pre-init">
|
||||
<property file="nbproject/private/private.properties"/>
|
||||
</target>
|
||||
<target name="-init-user" depends="-pre-init,-init-private">
|
||||
<property file="${user.properties.file}"/>
|
||||
<!-- The two properties below are usually overridden -->
|
||||
<!-- by the active platform. Just a fallback. -->
|
||||
<property name="default.javac.source" value="1.4"/>
|
||||
<property name="default.javac.target" value="1.4"/>
|
||||
</target>
|
||||
<target name="-init-project" depends="-pre-init,-init-private,-init-user">
|
||||
<property file="nbproject/project.properties"/>
|
||||
</target>
|
||||
<target name="-do-init" depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property">
|
||||
<available file="${manifest.file}" property="manifest.available"/>
|
||||
<condition property="manifest.available+main.class">
|
||||
<and>
|
||||
<isset property="manifest.available"/>
|
||||
<isset property="main.class"/>
|
||||
<not>
|
||||
<equals arg1="${main.class}" arg2="" trim="true"/>
|
||||
</not>
|
||||
</and>
|
||||
</condition>
|
||||
<condition property="manifest.available+main.class+mkdist.available">
|
||||
<and>
|
||||
<istrue value="${manifest.available+main.class}"/>
|
||||
<isset property="libs.CopyLibs.classpath"/>
|
||||
</and>
|
||||
</condition>
|
||||
<condition property="have.tests">
|
||||
<or>
|
||||
<available file="${test.src.dir}"/>
|
||||
</or>
|
||||
</condition>
|
||||
<condition property="have.sources">
|
||||
<or>
|
||||
<available file="${src.dir}"/>
|
||||
</or>
|
||||
</condition>
|
||||
<condition property="netbeans.home+have.tests">
|
||||
<and>
|
||||
<isset property="netbeans.home"/>
|
||||
<isset property="have.tests"/>
|
||||
</and>
|
||||
</condition>
|
||||
<condition property="no.javadoc.preview">
|
||||
<isfalse value="${javadoc.preview}"/>
|
||||
</condition>
|
||||
<property name="run.jvmargs" value=""/>
|
||||
<property name="javac.compilerargs" value=""/>
|
||||
<property name="work.dir" value="${basedir}"/>
|
||||
<condition property="no.deps">
|
||||
<and>
|
||||
<istrue value="${no.dependencies}"/>
|
||||
</and>
|
||||
</condition>
|
||||
<property name="javac.debug" value="true"/>
|
||||
<property name="javadoc.preview" value="true"/>
|
||||
</target>
|
||||
<target name="-post-init">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-init-check" depends="-pre-init,-init-private,-init-user,-init-project,-do-init">
|
||||
<fail unless="src.dir">Must set src.dir</fail>
|
||||
<fail unless="test.src.dir">Must set test.src.dir</fail>
|
||||
<fail unless="build.dir">Must set build.dir</fail>
|
||||
<fail unless="dist.dir">Must set dist.dir</fail>
|
||||
<fail unless="build.classes.dir">Must set build.classes.dir</fail>
|
||||
<fail unless="dist.javadoc.dir">Must set dist.javadoc.dir</fail>
|
||||
<fail unless="build.test.classes.dir">Must set build.test.classes.dir</fail>
|
||||
<fail unless="build.test.results.dir">Must set build.test.results.dir</fail>
|
||||
<fail unless="build.classes.excludes">Must set build.classes.excludes</fail>
|
||||
<fail unless="dist.jar">Must set dist.jar</fail>
|
||||
</target>
|
||||
<target name="-init-macrodef-property">
|
||||
<macrodef name="property" uri="http://www.netbeans.org/ns/j2se-project/1">
|
||||
<attribute name="name"/>
|
||||
<attribute name="value"/>
|
||||
<sequential>
|
||||
<property name="@{name}" value="${@{value}}"/>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-macrodef-javac">
|
||||
<macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute name="srcdir" default="${src.dir}"/>
|
||||
<attribute name="destdir" default="${build.classes.dir}"/>
|
||||
<attribute name="classpath" default="${javac.classpath}"/>
|
||||
<attribute name="debug" default="${javac.debug}"/>
|
||||
<element name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<javac srcdir="@{srcdir}" destdir="@{destdir}" debug="@{debug}" deprecation="${javac.deprecation}" source="${javac.source}" target="${javac.target}" includeantruntime="false">
|
||||
<classpath>
|
||||
<path path="@{classpath}"/>
|
||||
</classpath>
|
||||
<compilerarg line="${javac.compilerargs}"/>
|
||||
<customize/>
|
||||
</javac>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-macrodef-junit">
|
||||
<macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute name="includes" default="**/*Test.java"/>
|
||||
<sequential>
|
||||
<junit showoutput="true" fork="true" dir="${basedir}" failureproperty="tests.failed" errorproperty="tests.failed">
|
||||
<batchtest todir="${build.test.results.dir}">
|
||||
<fileset dir="${test.src.dir}" includes="@{includes}"/>
|
||||
</batchtest>
|
||||
<classpath>
|
||||
<path path="${run.test.classpath}"/>
|
||||
</classpath>
|
||||
<syspropertyset>
|
||||
<propertyref prefix="test-sys-prop."/>
|
||||
<mapper type="glob" from="test-sys-prop.*" to="*"/>
|
||||
</syspropertyset>
|
||||
<formatter type="brief" usefile="false"/>
|
||||
<formatter type="xml"/>
|
||||
<jvmarg line="${run.jvmargs}"/>
|
||||
</junit>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-macrodef-nbjpda">
|
||||
<macrodef name="nbjpdastart" uri="http://www.netbeans.org/ns/j2se-project/1">
|
||||
<attribute name="name" default="${main.class}"/>
|
||||
<attribute name="classpath" default="${debug.classpath}"/>
|
||||
<attribute name="stopclassname" default=""/>
|
||||
<sequential>
|
||||
<nbjpdastart transport="dt_socket" addressproperty="jpda.address" name="@{name}" stopclassname="@{stopclassname}">
|
||||
<classpath>
|
||||
<path path="@{classpath}"/>
|
||||
</classpath>
|
||||
</nbjpdastart>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
<macrodef name="nbjpdareload" uri="http://www.netbeans.org/ns/j2se-project/1">
|
||||
<attribute name="dir" default="${build.classes.dir}"/>
|
||||
<sequential>
|
||||
<nbjpdareload>
|
||||
<fileset includes="${fix.includes}*.class" dir="@{dir}"/>
|
||||
</nbjpdareload>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-macrodef-debug">
|
||||
<macrodef name="debug" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute name="classname" default="${main.class}"/>
|
||||
<attribute name="classpath" default="${debug.classpath}"/>
|
||||
<element name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<java fork="true" classname="@{classname}" dir="${work.dir}">
|
||||
<jvmarg value="-Xdebug"/>
|
||||
<jvmarg value="-Xnoagent"/>
|
||||
<jvmarg value="-Djava.compiler=none"/>
|
||||
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/>
|
||||
<jvmarg line="${run.jvmargs}"/>
|
||||
<classpath>
|
||||
<path path="@{classpath}"/>
|
||||
</classpath>
|
||||
<syspropertyset>
|
||||
<propertyref prefix="run-sys-prop."/>
|
||||
<mapper type="glob" from="run-sys-prop.*" to="*"/>
|
||||
</syspropertyset>
|
||||
<customize/>
|
||||
</java>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-macrodef-java">
|
||||
<macrodef name="java" uri="http://www.netbeans.org/ns/j2se-project/1">
|
||||
<attribute name="classname" default="${main.class}"/>
|
||||
<element name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<java fork="true" classname="@{classname}" dir="${work.dir}">
|
||||
<jvmarg line="${run.jvmargs}"/>
|
||||
<classpath>
|
||||
<path path="${run.classpath}"/>
|
||||
</classpath>
|
||||
<syspropertyset>
|
||||
<propertyref prefix="run-sys-prop."/>
|
||||
<mapper type="glob" from="run-sys-prop.*" to="*"/>
|
||||
</syspropertyset>
|
||||
<customize/>
|
||||
</java>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-presetdef-jar">
|
||||
<presetdef name="jar" uri="http://www.netbeans.org/ns/j2se-project/1">
|
||||
<jar jarfile="${dist.jar}" compress="${jar.compress}">
|
||||
<j2seproject1:fileset dir="${build.classes.dir}"/>
|
||||
</jar>
|
||||
</presetdef>
|
||||
</target>
|
||||
<target name="init" depends="-pre-init,-init-private,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac,-init-macrodef-junit,-init-macrodef-nbjpda,-init-macrodef-debug,-init-macrodef-java,-init-presetdef-jar"/>
|
||||
<!--
|
||||
===================
|
||||
COMPILATION SECTION
|
||||
===================
|
||||
-->
|
||||
<target name="deps-jar" depends="init" unless="no.deps"/>
|
||||
<target name="-pre-pre-compile" depends="init,deps-jar">
|
||||
<mkdir dir="${build.classes.dir}"/>
|
||||
</target>
|
||||
<target name="-pre-compile">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-do-compile" depends="init,deps-jar,-pre-pre-compile,-pre-compile" if="have.sources">
|
||||
<j2seproject3:javac/>
|
||||
<copy todir="${build.classes.dir}">
|
||||
<fileset dir="${src.dir}" excludes="${build.classes.excludes}"/>
|
||||
</copy>
|
||||
</target>
|
||||
<target name="-post-compile">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="compile" depends="init,deps-jar,-pre-pre-compile,-pre-compile,-do-compile,-post-compile" description="Compile project."/>
|
||||
<target name="-pre-compile-single">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-do-compile-single" depends="init,deps-jar,-pre-pre-compile">
|
||||
<fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
|
||||
<j2seproject3:javac>
|
||||
<customize>
|
||||
<patternset includes="${javac.includes}"/>
|
||||
</customize>
|
||||
</j2seproject3:javac>
|
||||
</target>
|
||||
<target name="-post-compile-single">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="compile-single" depends="init,deps-jar,-pre-pre-compile,-pre-compile-single,-do-compile-single,-post-compile-single"/>
|
||||
<!--
|
||||
====================
|
||||
JAR BUILDING SECTION
|
||||
====================
|
||||
-->
|
||||
<target name="-pre-pre-jar" depends="init">
|
||||
<dirname property="dist.jar.dir" file="${dist.jar}"/>
|
||||
<mkdir dir="${dist.jar.dir}"/>
|
||||
</target>
|
||||
<target name="-pre-jar">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-do-jar-without-manifest" depends="init,compile,-pre-pre-jar,-pre-jar" unless="manifest.available">
|
||||
<j2seproject1:jar/>
|
||||
</target>
|
||||
<target name="-do-jar-with-manifest" depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available" unless="manifest.available+main.class">
|
||||
<j2seproject1:jar manifest="${manifest.file}"/>
|
||||
</target>
|
||||
<target name="-do-jar-with-mainclass" depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available+main.class" unless="manifest.available+main.class+mkdist.available">
|
||||
<j2seproject1:jar manifest="${manifest.file}">
|
||||
<j2seproject1:manifest>
|
||||
<j2seproject1:attribute name="Main-Class" value="${main.class}"/>
|
||||
</j2seproject1:manifest>
|
||||
</j2seproject1:jar>
|
||||
<echo>To run this application from the command line without Ant, try:</echo>
|
||||
<property name="build.classes.dir.resolved" location="${build.classes.dir}"/>
|
||||
<property name="dist.jar.resolved" location="${dist.jar}"/>
|
||||
<pathconvert property="run.classpath.with.dist.jar">
|
||||
<path path="${run.classpath}"/>
|
||||
<map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
|
||||
</pathconvert>
|
||||
<echo>java -cp "${run.classpath.with.dist.jar}" ${main.class}</echo>
|
||||
</target>
|
||||
<target name="-do-jar-with-libraries" depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available+main.class+mkdist.available">
|
||||
<property name="build.classes.dir.resolved" location="${build.classes.dir}"/>
|
||||
<pathconvert property="run.classpath.without.build.classes.dir">
|
||||
<path path="${run.classpath}"/>
|
||||
<map from="${build.classes.dir.resolved}" to=""/>
|
||||
</pathconvert>
|
||||
<pathconvert property="jar.classpath" pathsep=" ">
|
||||
<path path="${run.classpath.without.build.classes.dir}"/>
|
||||
<chainedmapper>
|
||||
<flattenmapper/>
|
||||
<globmapper from="*" to="lib/*"/>
|
||||
</chainedmapper>
|
||||
</pathconvert>
|
||||
<taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" name="copylibs" classpath="${libs.CopyLibs.classpath}"/>
|
||||
<copylibs manifest="${manifest.file}" runtimeclasspath="${run.classpath.without.build.classes.dir}" jarfile="${dist.jar}" compress="${jar.compress}">
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="${main.class}"/>
|
||||
<attribute name="Class-Path" value="${jar.classpath}"/>
|
||||
</manifest>
|
||||
</copylibs>
|
||||
<echo>To run this application from the command line without Ant, try:</echo>
|
||||
<property name="dist.jar.resolved" location="${dist.jar}"/>
|
||||
<echo>java -jar "${dist.jar.resolved}"</echo>
|
||||
</target>
|
||||
<target name="-post-jar">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="jar" depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries,-post-jar" description="Build JAR."/>
|
||||
<!--
|
||||
=================
|
||||
EXECUTION SECTION
|
||||
=================
|
||||
-->
|
||||
<target name="run" depends="init,compile" description="Run a main class.">
|
||||
<j2seproject1:java>
|
||||
<customize>
|
||||
<arg line="${application.args}"/>
|
||||
</customize>
|
||||
</j2seproject1:java>
|
||||
</target>
|
||||
<target name="run-single" depends="init,compile-single">
|
||||
<fail unless="run.class">Must select one file in the IDE or set run.class</fail>
|
||||
<j2seproject1:java classname="${run.class}"/>
|
||||
</target>
|
||||
<!--
|
||||
=================
|
||||
DEBUGGING SECTION
|
||||
=================
|
||||
-->
|
||||
<target name="-debug-start-debugger" if="netbeans.home" depends="init">
|
||||
<j2seproject1:nbjpdastart name="${debug.class}"/>
|
||||
</target>
|
||||
<target name="-debug-start-debuggee" depends="init,compile">
|
||||
<j2seproject3:debug>
|
||||
<customize>
|
||||
<arg line="${application.args}"/>
|
||||
</customize>
|
||||
</j2seproject3:debug>
|
||||
</target>
|
||||
<target name="debug" if="netbeans.home" depends="init,compile,-debug-start-debugger,-debug-start-debuggee" description="Debug project in IDE."/>
|
||||
<target name="-debug-start-debugger-stepinto" if="netbeans.home" depends="init">
|
||||
<j2seproject1:nbjpdastart stopclassname="${main.class}"/>
|
||||
</target>
|
||||
<target name="debug-stepinto" if="netbeans.home" depends="init,compile,-debug-start-debugger-stepinto,-debug-start-debuggee"/>
|
||||
<target name="-debug-start-debuggee-single" if="netbeans.home" depends="init,compile-single">
|
||||
<fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
|
||||
<j2seproject3:debug classname="${debug.class}"/>
|
||||
</target>
|
||||
<target name="debug-single" if="netbeans.home" depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-single"/>
|
||||
<target name="-pre-debug-fix" depends="init">
|
||||
<fail unless="fix.includes">Must set fix.includes</fail>
|
||||
<property name="javac.includes" value="${fix.includes}.java"/>
|
||||
</target>
|
||||
<target name="-do-debug-fix" if="netbeans.home" depends="init,-pre-debug-fix,compile-single">
|
||||
<j2seproject1:nbjpdareload/>
|
||||
</target>
|
||||
<target name="debug-fix" if="netbeans.home" depends="init,-pre-debug-fix,-do-debug-fix"/>
|
||||
<!--
|
||||
===============
|
||||
JAVADOC SECTION
|
||||
===============
|
||||
-->
|
||||
<target name="-javadoc-build" depends="init">
|
||||
<mkdir dir="${dist.javadoc.dir}"/>
|
||||
<javadoc destdir="${dist.javadoc.dir}" source="${javac.source}" notree="${javadoc.notree}" use="${javadoc.use}" nonavbar="${javadoc.nonavbar}" noindex="${javadoc.noindex}" splitindex="${javadoc.splitindex}" author="${javadoc.author}" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}" private="${javadoc.private}" additionalparam="${javadoc.additionalparam}" failonerror="true" useexternalfile="true">
|
||||
<classpath>
|
||||
<path path="${javac.classpath}"/>
|
||||
</classpath>
|
||||
<sourcepath>
|
||||
<pathelement location="${src.dir}"/>
|
||||
</sourcepath>
|
||||
<packageset dir="${src.dir}" includes="*/**"/>
|
||||
<fileset dir="${src.dir}" includes="*.java"/>
|
||||
</javadoc>
|
||||
</target>
|
||||
<target name="-javadoc-browse" if="netbeans.home" unless="no.javadoc.preview" depends="init,-javadoc-build">
|
||||
<nbbrowse file="${dist.javadoc.dir}/index.html"/>
|
||||
</target>
|
||||
<target name="javadoc" depends="init,-javadoc-build,-javadoc-browse" description="Build Javadoc."/>
|
||||
<!--
|
||||
=========================
|
||||
JUNIT COMPILATION SECTION
|
||||
=========================
|
||||
-->
|
||||
<target name="-pre-pre-compile-test" if="have.tests" depends="init,compile">
|
||||
<mkdir dir="${build.test.classes.dir}"/>
|
||||
</target>
|
||||
<target name="-pre-compile-test">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-do-compile-test" if="have.tests" depends="init,compile,-pre-pre-compile-test,-pre-compile-test">
|
||||
<j2seproject3:javac srcdir="${test.src.dir}" destdir="${build.test.classes.dir}" debug="true" classpath="${javac.test.classpath}"/>
|
||||
<copy todir="${build.test.classes.dir}">
|
||||
<fileset dir="${test.src.dir}" excludes="**/*.java"/>
|
||||
</copy>
|
||||
</target>
|
||||
<target name="-post-compile-test">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="compile-test" depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-do-compile-test,-post-compile-test"/>
|
||||
<target name="-pre-compile-test-single">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-do-compile-test-single" if="have.tests" depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single">
|
||||
<fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
|
||||
<j2seproject3:javac srcdir="${test.src.dir}" destdir="${build.test.classes.dir}" debug="true" classpath="${javac.test.classpath}">
|
||||
<customize>
|
||||
<patternset includes="${javac.includes}"/>
|
||||
</customize>
|
||||
</j2seproject3:javac>
|
||||
<copy todir="${build.test.classes.dir}">
|
||||
<fileset dir="${test.src.dir}" excludes="**/*.java"/>
|
||||
</copy>
|
||||
</target>
|
||||
<target name="-post-compile-test-single">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="compile-test-single" depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single,-do-compile-test-single,-post-compile-test-single"/>
|
||||
<!--
|
||||
=======================
|
||||
JUNIT EXECUTION SECTION
|
||||
=======================
|
||||
-->
|
||||
<target name="-pre-test-run" if="have.tests" depends="init">
|
||||
<mkdir dir="${build.test.results.dir}"/>
|
||||
</target>
|
||||
<target name="-do-test-run" if="have.tests" depends="init,compile-test,-pre-test-run">
|
||||
<j2seproject3:junit/>
|
||||
</target>
|
||||
<target name="-post-test-run" if="have.tests" depends="init,compile-test,-pre-test-run,-do-test-run">
|
||||
<fail if="tests.failed">Some tests failed; see details above.</fail>
|
||||
</target>
|
||||
<target name="test-report" if="have.tests" depends="init"/>
|
||||
<target name="-test-browse" if="netbeans.home+have.tests" depends="init"/>
|
||||
<target name="test" depends="init,compile-test,-pre-test-run,-do-test-run,test-report,-post-test-run,-test-browse" description="Run unit tests."/>
|
||||
<target name="-pre-test-run-single" if="have.tests" depends="init">
|
||||
<mkdir dir="${build.test.results.dir}"/>
|
||||
</target>
|
||||
<target name="-do-test-run-single" if="have.tests" depends="init,compile-test-single,-pre-test-run-single">
|
||||
<fail unless="test.includes">Must select some files in the IDE or set test.includes</fail>
|
||||
<j2seproject3:junit includes="${test.includes}"/>
|
||||
</target>
|
||||
<target name="-post-test-run-single" if="have.tests" depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single">
|
||||
<fail if="tests.failed">Some tests failed; see details above.</fail>
|
||||
</target>
|
||||
<target name="test-single" depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single,-post-test-run-single" description="Run single unit test."/>
|
||||
<!--
|
||||
=======================
|
||||
JUNIT DEBUGGING SECTION
|
||||
=======================
|
||||
-->
|
||||
<target name="-debug-start-debuggee-test" if="have.tests" depends="init,compile-test">
|
||||
<fail unless="test.class">Must select one file in the IDE or set test.class</fail>
|
||||
<j2seproject3:debug classname="junit.textui.TestRunner" classpath="${debug.test.classpath}">
|
||||
<customize>
|
||||
<arg line="${test.class}"/>
|
||||
</customize>
|
||||
</j2seproject3:debug>
|
||||
</target>
|
||||
<target name="-debug-start-debugger-test" if="netbeans.home+have.tests" depends="init,compile-test">
|
||||
<j2seproject1:nbjpdastart name="${test.class}" classpath="${debug.test.classpath}"/>
|
||||
</target>
|
||||
<target name="debug-test" depends="init,compile-test,-debug-start-debugger-test,-debug-start-debuggee-test"/>
|
||||
<target name="-do-debug-fix-test" if="netbeans.home" depends="init,-pre-debug-fix,compile-test-single">
|
||||
<j2seproject1:nbjpdareload dir="${build.test.classes.dir}"/>
|
||||
</target>
|
||||
<target name="debug-fix-test" if="netbeans.home" depends="init,-pre-debug-fix,-do-debug-fix-test"/>
|
||||
<!--
|
||||
=========================
|
||||
APPLET EXECUTION SECTION
|
||||
=========================
|
||||
-->
|
||||
<target name="run-applet" depends="init,compile-single">
|
||||
<fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
|
||||
<j2seproject1:java classname="sun.applet.AppletViewer">
|
||||
<customize>
|
||||
<arg value="${applet.url}"/>
|
||||
</customize>
|
||||
</j2seproject1:java>
|
||||
</target>
|
||||
<!--
|
||||
=========================
|
||||
APPLET DEBUGGING SECTION
|
||||
=========================
|
||||
-->
|
||||
<target name="-debug-start-debuggee-applet" if="netbeans.home" depends="init,compile-single">
|
||||
<fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
|
||||
<j2seproject3:debug classname="sun.applet.AppletViewer">
|
||||
<customize>
|
||||
<arg value="${applet.url}"/>
|
||||
</customize>
|
||||
</j2seproject3:debug>
|
||||
</target>
|
||||
<target name="debug-applet" if="netbeans.home" depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-applet"/>
|
||||
<!--
|
||||
===============
|
||||
CLEANUP SECTION
|
||||
===============
|
||||
-->
|
||||
<target name="deps-clean" depends="init" unless="no.deps"/>
|
||||
<target name="-do-clean" depends="init">
|
||||
<delete dir="${build.dir}"/>
|
||||
<delete dir="${dist.dir}"/>
|
||||
</target>
|
||||
<target name="-post-clean">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="clean" depends="init,deps-clean,-do-clean,-post-clean" description="Clean build products."/>
|
||||
</project>
|
||||
@@ -0,0 +1,59 @@
|
||||
application.args=
|
||||
build.classes.dir=${build.dir}/classes
|
||||
build.classes.excludes=**/*.java
|
||||
# This directory is removed when the project is cleaned:
|
||||
build.dir=build
|
||||
build.generated.dir=${build.dir}/generated
|
||||
# Only compile against the classpath explicitly listed here:
|
||||
build.sysclasspath=ignore
|
||||
build.test.classes.dir=${build.dir}/test/classes
|
||||
build.test.results.dir=${build.dir}/test/results
|
||||
debug.classpath=\
|
||||
${run.classpath}
|
||||
debug.test.classpath=\
|
||||
${run.test.classpath}
|
||||
# This directory is removed when the project is cleaned:
|
||||
dist.dir=dist
|
||||
dist.jar=${dist.dir}/platform.jar
|
||||
dist.javadoc.dir=${dist.dir}/javadoc
|
||||
file.reference.jna.jar=../../../build/jna.jar
|
||||
libs.junit.classpath=../../../lib/junit.jar
|
||||
jar.compress=false
|
||||
javac.classpath=\
|
||||
${file.reference.jna.jar};
|
||||
# Space-separated list of extra javac options
|
||||
javac.compilerargs=
|
||||
javac.deprecation=false
|
||||
javac.source=1.5
|
||||
javac.target=1.5
|
||||
javac.test.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}:\
|
||||
${libs.junit.classpath}
|
||||
javadoc.additionalparam=
|
||||
javadoc.author=false
|
||||
javadoc.encoding=
|
||||
javadoc.noindex=false
|
||||
javadoc.nonavbar=false
|
||||
javadoc.notree=false
|
||||
javadoc.private=false
|
||||
javadoc.splitindex=true
|
||||
javadoc.use=true
|
||||
javadoc.version=false
|
||||
javadoc.windowtitle=
|
||||
main.class=
|
||||
manifest.file=manifest.mf
|
||||
meta.inf.dir=${src.dir}/META-INF
|
||||
platform.active=default_platform
|
||||
run.classpath=\
|
||||
${javac.classpath}:\
|
||||
${build.classes.dir}
|
||||
# Space-separated list of JVM arguments used when running the project
|
||||
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
|
||||
# or test-sys-prop.name=value to set system properties for unit tests):
|
||||
run.jvmargs=
|
||||
run.test.classpath=\
|
||||
${javac.test.classpath}:\
|
||||
${build.test.classes.dir}
|
||||
src.dir=src
|
||||
test.src.dir=test
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.java.j2seproject</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<name>platform</name>
|
||||
<minimum-ant-version>1.6.5</minimum-ant-version>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
<test-roots>
|
||||
<root id="test.src.dir"/>
|
||||
</test-roots>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
||||
@@ -0,0 +1,135 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* <p/>
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EventObject;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sun.jna.platform.win32.W32FileMonitor;
|
||||
|
||||
/** Provides notification of file system changes. Actual capabilities may
|
||||
* vary slightly by platform.
|
||||
* <p>
|
||||
* Watched files which are removed from the filesystem are no longer watched.
|
||||
* @author twall
|
||||
*/
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public abstract class FileMonitor {
|
||||
|
||||
public static final int FILE_CREATED = 0x1;
|
||||
public static final int FILE_DELETED = 0x2;
|
||||
public static final int FILE_MODIFIED = 0x4;
|
||||
public static final int FILE_ACCESSED = 0x8;
|
||||
public static final int FILE_NAME_CHANGED_OLD = 0x10;
|
||||
public static final int FILE_NAME_CHANGED_NEW = 0x20;
|
||||
public static final int FILE_RENAMED = FILE_NAME_CHANGED_OLD|FILE_NAME_CHANGED_NEW;
|
||||
public static final int FILE_SIZE_CHANGED = 0x40;
|
||||
public static final int FILE_ATTRIBUTES_CHANGED = 0x80;
|
||||
public static final int FILE_SECURITY_CHANGED = 0x100;
|
||||
public static final int FILE_ANY = 0x1FF;
|
||||
|
||||
public interface FileListener {
|
||||
public void fileChanged(FileEvent e);
|
||||
}
|
||||
|
||||
public class FileEvent extends EventObject {
|
||||
private final File file;
|
||||
private final int type;
|
||||
public FileEvent(File file, int type) {
|
||||
super(FileMonitor.this);
|
||||
this.file = file;
|
||||
this.type = type;
|
||||
}
|
||||
public File getFile() { return file; }
|
||||
public int getType() { return type; }
|
||||
public String toString() {
|
||||
return "FileEvent: " + file + ":" + type;
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<File, Integer> watched = new HashMap<File, Integer>();
|
||||
private List<FileListener> listeners = new ArrayList<FileListener>();
|
||||
|
||||
protected abstract void watch(File file, int mask, boolean recursive) throws IOException ;
|
||||
protected abstract void unwatch(File file);
|
||||
public abstract void dispose();
|
||||
|
||||
public void addWatch(File dir) throws IOException {
|
||||
addWatch(dir, FILE_ANY);
|
||||
}
|
||||
|
||||
public void addWatch(File dir, int mask) throws IOException {
|
||||
addWatch(dir, mask, dir.isDirectory());
|
||||
}
|
||||
|
||||
public void addWatch(File dir, int mask, boolean recursive) throws IOException {
|
||||
watched.put(dir, new Integer(mask));
|
||||
watch(dir, mask, recursive);
|
||||
}
|
||||
|
||||
public void removeWatch(File file) {
|
||||
if (watched.remove(file) != null) {
|
||||
unwatch(file);
|
||||
}
|
||||
}
|
||||
|
||||
protected void notify(FileEvent e) {
|
||||
for (FileListener listener : listeners) {
|
||||
listener.fileChanged(e);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void addFileListener(FileListener listener) {
|
||||
List<FileListener> list = new ArrayList<FileListener>(listeners);
|
||||
list.add(listener);
|
||||
listeners = list;
|
||||
}
|
||||
|
||||
public synchronized void removeFileListener(FileListener x) {
|
||||
List<FileListener> list = new ArrayList<FileListener>(listeners);
|
||||
list.remove(x);
|
||||
listeners = list;
|
||||
}
|
||||
|
||||
protected void finalize() {
|
||||
for (File watchedFile : watched.keySet()) {
|
||||
removeWatch(watchedFile);
|
||||
}
|
||||
|
||||
dispose();
|
||||
}
|
||||
|
||||
/** Canonical lazy loading of a singleton. */
|
||||
private static class Holder {
|
||||
public static final FileMonitor INSTANCE;
|
||||
static {
|
||||
String os = System.getProperty("os.name");
|
||||
if (os.startsWith("Windows")) {
|
||||
INSTANCE = new W32FileMonitor();
|
||||
}
|
||||
else {
|
||||
throw new Error("FileMonitor not implemented for " + os);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static FileMonitor getInstance() {
|
||||
return Holder.INSTANCE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* <p/>
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.platform.mac.MacFileUtils;
|
||||
import com.sun.jna.platform.win32.W32FileUtils;
|
||||
|
||||
/** Miscellaneous file utils not provided for by Java. */
|
||||
public abstract class FileUtils {
|
||||
|
||||
public boolean hasTrash() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Move the given file to the system trash, if one is available.
|
||||
Throws an exception on failure.
|
||||
*/
|
||||
public abstract void moveToTrash(File[] files) throws IOException;
|
||||
|
||||
/** Canonical lazy loading of a singleton. */
|
||||
private static class Holder {
|
||||
public static final FileUtils INSTANCE;
|
||||
static {
|
||||
String os = System.getProperty("os.name");
|
||||
if (os.startsWith("Windows")) {
|
||||
INSTANCE = new W32FileUtils();
|
||||
}
|
||||
else if (os.startsWith("Mac")){
|
||||
INSTANCE = new MacFileUtils();
|
||||
}
|
||||
else {
|
||||
INSTANCE = new DefaultFileUtils();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static FileUtils getInstance() {
|
||||
return Holder.INSTANCE;
|
||||
}
|
||||
|
||||
private static class DefaultFileUtils extends FileUtils {
|
||||
|
||||
private File getTrashDirectory() {
|
||||
// very simple implementation. should take care of renaming when
|
||||
// a file already exists, or any other platform-specific behavior
|
||||
File home = new File(System.getProperty("user.home"));
|
||||
File trash = new File(home, ".Trash");
|
||||
if (!trash.exists()) {
|
||||
trash = new File(home, "Trash");
|
||||
if (!trash.exists()) {
|
||||
File desktop = new File(home, "Desktop");
|
||||
if (desktop.exists()) {
|
||||
trash = new File(desktop, ".Trash");
|
||||
if (!trash.exists()) {
|
||||
trash = new File(desktop, "Trash");
|
||||
if (!trash.exists()) {
|
||||
trash = new File(System.getProperty("fileutils.trash", "Trash"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return trash;
|
||||
}
|
||||
|
||||
public boolean hasTrash() {
|
||||
return getTrashDirectory().exists();
|
||||
}
|
||||
|
||||
/** The default implementation attempts to move the file to
|
||||
* the desktop "Trash" folder.
|
||||
*/
|
||||
public void moveToTrash(File[] files) throws IOException {
|
||||
File trash = getTrashDirectory();
|
||||
if (!trash.exists()) {
|
||||
throw new IOException("No trash location found (define fileutils.trash to be the path to the trash)");
|
||||
}
|
||||
List<File> failed = new ArrayList<File>();
|
||||
for (int i=0;i < files.length;i++) {
|
||||
File src = files[i];
|
||||
File target = new File(trash, src.getName());
|
||||
if (!src.renameTo(target)) {
|
||||
failed.add(src);
|
||||
}
|
||||
}
|
||||
if (failed.size() > 0) {
|
||||
throw new IOException("The following files could not be trashed: " + failed);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform;
|
||||
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.HeadlessException;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import com.sun.jna.Platform;
|
||||
import com.sun.jna.platform.unix.X11;
|
||||
import com.sun.jna.platform.unix.X11.Display;
|
||||
import com.sun.jna.platform.win32.User32;
|
||||
|
||||
/** Provide access to the local keyboard state. Note that this is meaningless
|
||||
* on a headless system and some VNC setups.
|
||||
*
|
||||
* @author twall
|
||||
*/
|
||||
// TODO: key clicks
|
||||
// TODO: auto-repeat
|
||||
// TODO: keyboard bell
|
||||
// TODO: led state
|
||||
public class KeyboardUtils {
|
||||
static final NativeKeyboardUtils INSTANCE;
|
||||
static {
|
||||
if (GraphicsEnvironment.isHeadless()) {
|
||||
throw new HeadlessException("KeyboardUtils requires a keyboard");
|
||||
}
|
||||
if (Platform.isWindows()) {
|
||||
INSTANCE = new W32KeyboardUtils();
|
||||
}
|
||||
else if (Platform.isMac()) {
|
||||
INSTANCE = new MacKeyboardUtils();
|
||||
throw new UnsupportedOperationException("No support (yet) for "
|
||||
+ System.getProperty("os.name"));
|
||||
}
|
||||
else {
|
||||
INSTANCE = new X11KeyboardUtils();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isPressed(int keycode, int location) {
|
||||
return INSTANCE.isPressed(keycode, location);
|
||||
}
|
||||
public static boolean isPressed(int keycode) {
|
||||
return INSTANCE.isPressed(keycode);
|
||||
}
|
||||
|
||||
private static abstract class NativeKeyboardUtils {
|
||||
public abstract boolean isPressed(int keycode, int location);
|
||||
public boolean isPressed(int keycode) {
|
||||
return isPressed(keycode, KeyEvent.KEY_LOCATION_UNKNOWN);
|
||||
}
|
||||
}
|
||||
|
||||
private static class W32KeyboardUtils extends NativeKeyboardUtils {
|
||||
private int toNative(int code, int loc) {
|
||||
if ((code >= KeyEvent.VK_A && code <= KeyEvent.VK_Z)
|
||||
|| (code >= KeyEvent.VK_0 && code <= KeyEvent.VK_9)) {
|
||||
return code;
|
||||
}
|
||||
if (code == KeyEvent.VK_SHIFT) {
|
||||
if ((loc & KeyEvent.KEY_LOCATION_RIGHT) != 0) {
|
||||
return User32.VK_RSHIFT;
|
||||
}
|
||||
if ((loc & KeyEvent.KEY_LOCATION_LEFT) != 0) {
|
||||
return User32.VK_LSHIFT;
|
||||
}
|
||||
return User32.VK_SHIFT;
|
||||
}
|
||||
if (code == KeyEvent.VK_CONTROL) {
|
||||
if ((loc & KeyEvent.KEY_LOCATION_RIGHT) != 0) {
|
||||
return User32.VK_RCONTROL;
|
||||
}
|
||||
if ((loc & KeyEvent.KEY_LOCATION_LEFT) != 0) {
|
||||
return User32.VK_LCONTROL;
|
||||
}
|
||||
return User32.VK_CONTROL;
|
||||
}
|
||||
if (code == KeyEvent.VK_ALT) {
|
||||
if ((loc & KeyEvent.KEY_LOCATION_RIGHT) != 0) {
|
||||
return User32.VK_RMENU;
|
||||
}
|
||||
if ((loc & KeyEvent.KEY_LOCATION_LEFT) != 0) {
|
||||
return User32.VK_LMENU;
|
||||
}
|
||||
return User32.VK_MENU;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public boolean isPressed(int keycode, int location) {
|
||||
User32 lib = User32.INSTANCE;
|
||||
return (lib.GetAsyncKeyState(toNative(keycode, location)) & 0x8000) != 0;
|
||||
}
|
||||
}
|
||||
private static class MacKeyboardUtils extends NativeKeyboardUtils {
|
||||
public boolean isPressed(int keycode, int location) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private static class X11KeyboardUtils extends NativeKeyboardUtils {
|
||||
// TODO: fully map from X11 keycodes to java keycodes
|
||||
// this is a minimal implementation
|
||||
private int toKeySym(int code, int location) {
|
||||
if (code >= KeyEvent.VK_A && code <= KeyEvent.VK_Z)
|
||||
return X11.XK_a + (code - KeyEvent.VK_A);
|
||||
if (code >= KeyEvent.VK_0 && code <= KeyEvent.VK_9)
|
||||
return X11.XK_0 + (code - KeyEvent.VK_0);
|
||||
if (code == KeyEvent.VK_SHIFT) {
|
||||
if ((location & KeyEvent.KEY_LOCATION_RIGHT) != 0)
|
||||
return X11.XK_Shift_R;
|
||||
return X11.XK_Shift_L;
|
||||
}
|
||||
if (code == KeyEvent.VK_CONTROL) {
|
||||
if ((location & KeyEvent.KEY_LOCATION_RIGHT) != 0)
|
||||
return X11.XK_Control_R;
|
||||
return X11.XK_Control_L;
|
||||
}
|
||||
if (code == KeyEvent.VK_ALT) {
|
||||
if ((location & KeyEvent.KEY_LOCATION_RIGHT) != 0)
|
||||
return X11.XK_Alt_R;
|
||||
return X11.XK_Alt_L;
|
||||
}
|
||||
if (code == KeyEvent.VK_META) {
|
||||
if ((location & KeyEvent.KEY_LOCATION_RIGHT) != 0)
|
||||
return X11.XK_Meta_R;
|
||||
return X11.XK_Meta_L;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
public boolean isPressed(int keycode, int location) {
|
||||
X11 lib = X11.INSTANCE;
|
||||
Display dpy = lib.XOpenDisplay(null);
|
||||
if (dpy == null) {
|
||||
throw new Error("Can't open X Display");
|
||||
}
|
||||
try {
|
||||
byte[] keys = new byte[32];
|
||||
// Ignore the return value
|
||||
lib.XQueryKeymap(dpy, keys);
|
||||
int keysym = toKeySym(keycode, location);
|
||||
for (int code=5;code < 256;code++) {
|
||||
int idx = code / 8;
|
||||
int shift = code % 8;
|
||||
if ((keys[idx] & (1 << shift)) != 0) {
|
||||
int sym = lib.XKeycodeToKeysym(dpy, (byte)code, 0).intValue();
|
||||
if (sym == keysym)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
lib.XCloseDisplay(dpy);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,258 @@
|
||||
/* Copyright (c) 2007 Olivier Chafik, All Rights Reserved
|
||||
* Copyright (c) 2008 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.image.DataBuffer;
|
||||
import java.awt.image.DataBufferByte;
|
||||
import java.awt.image.DataBufferInt;
|
||||
import java.awt.image.MultiPixelPackedSampleModel;
|
||||
import java.awt.image.Raster;
|
||||
import java.awt.image.SampleModel;
|
||||
import java.awt.image.SinglePixelPackedSampleModel;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
/**
|
||||
* Methods that are useful to decompose a raster into a set of rectangles.
|
||||
* An occupied pixel has two possible meanings, depending on the raster :
|
||||
* <ul>
|
||||
* <li>if the raster has an alpha layer, occupied means with alpha not null</li>
|
||||
* <li>if the raster doesn't have any alpha layer, occupied means not completely black</li>
|
||||
* </ul>
|
||||
* @author Olivier Chafik
|
||||
*/
|
||||
public class RasterRangesUtils {
|
||||
/// Masks used to isolate the current column in a set of 8 binary columns packed in a byte
|
||||
private static final int[] subColMasks = new int[] {
|
||||
0x0080, 0x0040, 0x0020, 0x0010,
|
||||
0x0008, 0x0004, 0x0002, 0x0001
|
||||
};
|
||||
|
||||
private static final Comparator COMPARATOR = new Comparator() {
|
||||
public int compare(Object o1, Object o2) {
|
||||
return ((Rectangle)o1).x - ((Rectangle)o2).x;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Abstraction of a sink for ranges.
|
||||
*/
|
||||
public static interface RangesOutput {
|
||||
/**
|
||||
* Output a rectangular range.
|
||||
* @param x x coordinate of the top-left corner of the range
|
||||
* @param y y coordinate of the top-left corner of the range
|
||||
* @param w width of the range
|
||||
* @param h height of the range
|
||||
* @return true if the output succeeded, false otherwise
|
||||
*/
|
||||
boolean outputRange(int x, int y, int w, int h);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs ranges of occupied pixels.
|
||||
* In a raster that has an alpha layer, a pixel is occupied if its alpha value is not null.
|
||||
* In a raster without alpha layer, a pixel is occupied if it is not completely black.
|
||||
* @param raster image to be segmented in non black or non-transparent ranges
|
||||
* @param out destination of the non null ranges
|
||||
* @return true if the output succeeded, false otherwise
|
||||
*/
|
||||
public static boolean outputOccupiedRanges(Raster raster, RangesOutput out) {
|
||||
Rectangle bounds = raster.getBounds();
|
||||
SampleModel sampleModel = raster.getSampleModel();
|
||||
boolean hasAlpha = sampleModel.getNumBands() == 4;
|
||||
|
||||
// Try to use the underlying data array directly for a few common raster formats
|
||||
if (raster.getParent() == null && bounds.x == 0 && bounds.y == 0) {
|
||||
// No support for subraster (as obtained with Image.getSubimage(...))
|
||||
|
||||
DataBuffer data = raster.getDataBuffer();
|
||||
if (data.getNumBanks() == 1) {
|
||||
// There is always a single bank for all BufferedImage types, except maybe TYPE_CUSTOM
|
||||
|
||||
if (sampleModel instanceof MultiPixelPackedSampleModel) {
|
||||
MultiPixelPackedSampleModel packedSampleModel = (MultiPixelPackedSampleModel)sampleModel;
|
||||
if (packedSampleModel.getPixelBitStride() == 1) {
|
||||
// TYPE_BYTE_BINARY
|
||||
return outputOccupiedRangesOfBinaryPixels(((DataBufferByte)data).getData(), bounds.width, bounds.height, out);
|
||||
}
|
||||
} else if (sampleModel instanceof SinglePixelPackedSampleModel) {
|
||||
if (sampleModel.getDataType() == DataBuffer.TYPE_INT) {
|
||||
// TYPE_INT_ARGB, TYPE_INT_ARGB_PRE, TYPE_INT_BGR or TYPE_INT_RGB
|
||||
return outputOccupiedRanges(((DataBufferInt)data).getData(), bounds.width, bounds.height, hasAlpha ? 0xff000000 : 0xffffff, out);
|
||||
}
|
||||
// TODO could easily handle cases of TYPE_USHORT_GRAY and TYPE_BYTE_GRAY.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback behaviour : copy pixels of raster
|
||||
int[] pixels = raster.getPixels(0, 0, bounds.width, bounds.height, (int[])null);
|
||||
return outputOccupiedRanges(pixels, bounds.width, bounds.height, hasAlpha ? 0xff000000 : 0xffffff, out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the non-null values of a binary image as ranges of contiguous values.
|
||||
* @param binaryBits byte-packed binary bits of an image
|
||||
* @param w width of the image (in pixels)
|
||||
* @param h height of the image
|
||||
* @param out
|
||||
* @return true if the output succeeded, false otherwise
|
||||
*/
|
||||
public static boolean outputOccupiedRangesOfBinaryPixels(byte[] binaryBits, int w, int h, RangesOutput out) {
|
||||
Set rects = new HashSet();
|
||||
Set prevLine = Collections.EMPTY_SET;
|
||||
int scanlineBytes = binaryBits.length / h;
|
||||
for (int row = 0; row < h; row++) {
|
||||
Set curLine = new TreeSet(COMPARATOR);
|
||||
int rowOffsetBytes = row * scanlineBytes;
|
||||
int startCol = -1;
|
||||
// Look at each batch of 8 columns in this row
|
||||
for (int byteCol = 0; byteCol < scanlineBytes; byteCol++) {
|
||||
int firstByteCol = byteCol << 3;
|
||||
byte byteColBits = binaryBits[rowOffsetBytes + byteCol];
|
||||
if (byteColBits == 0) {
|
||||
// all 8 bits are zeroes
|
||||
if (startCol >= 0) {
|
||||
// end of current region
|
||||
curLine.add(new Rectangle(startCol, row, firstByteCol - startCol, 1));
|
||||
startCol = -1;
|
||||
}
|
||||
} else if (byteColBits == 0xff) {
|
||||
// all 8 bits are ones
|
||||
if (startCol < 0) {
|
||||
// start of new region
|
||||
startCol = firstByteCol;
|
||||
}
|
||||
} else {
|
||||
// mixed case : some bits are ones, others are zeroes
|
||||
for (int subCol = 0; subCol < 8; subCol++) {
|
||||
int col = firstByteCol | subCol;
|
||||
if ((byteColBits & subColMasks[subCol]) != 0) {
|
||||
if (startCol < 0) {
|
||||
// start of new region
|
||||
startCol = col;
|
||||
}
|
||||
} else {
|
||||
if (startCol >= 0) {
|
||||
// end of current region
|
||||
curLine.add(new Rectangle(startCol, row, col - startCol, 1));
|
||||
startCol = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (startCol >= 0) {
|
||||
// end of last region
|
||||
curLine.add(new Rectangle(startCol, row, w - startCol, 1));
|
||||
}
|
||||
Set unmerged = mergeRects(prevLine, curLine);
|
||||
rects.addAll(unmerged);
|
||||
prevLine = curLine;
|
||||
}
|
||||
// Add anything left over
|
||||
rects.addAll(prevLine);
|
||||
for (Iterator i=rects.iterator();i.hasNext();) {
|
||||
Rectangle r = (Rectangle)i.next();
|
||||
if (!out.outputRange(r.x, r.y, r.width, r.height)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the occupied values of an integer-pixels image as ranges of contiguous values.
|
||||
* A pixel is considered occupied if the bitwise AND of its integer value with the provided occupationMask is not null.
|
||||
* @param pixels integer values of the pixels of an image
|
||||
* @param w width of the image (in pixels)
|
||||
* @param h height of the image
|
||||
* @param occupationMask mask used to select which bits are used in a pixel to check its occupied status. 0xff000000 would only take the alpha layer into account, for instance.
|
||||
* @param out where to output all the contiguous ranges of non occupied pixels
|
||||
* @return true if the output succeeded, false otherwise
|
||||
*/
|
||||
public static boolean outputOccupiedRanges(int[] pixels, int w, int h, int occupationMask, RangesOutput out) {
|
||||
Set rects = new HashSet();
|
||||
Set prevLine = Collections.EMPTY_SET;
|
||||
for (int row = 0; row < h; row++) {
|
||||
Set curLine = new TreeSet(COMPARATOR);
|
||||
int idxOffset = row * w;
|
||||
int startCol = -1;
|
||||
|
||||
for (int col = 0; col < w; col++) {
|
||||
if ((pixels[idxOffset + col] & occupationMask) != 0) {
|
||||
if (startCol < 0) {
|
||||
startCol = col;
|
||||
}
|
||||
} else {
|
||||
if (startCol >= 0) {
|
||||
// end of current region
|
||||
curLine.add(new Rectangle(startCol, row, col-startCol, 1));
|
||||
startCol = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (startCol >= 0) {
|
||||
// end of last region of current row
|
||||
curLine.add(new Rectangle(startCol, row, w-startCol, 1));
|
||||
}
|
||||
Set unmerged = mergeRects(prevLine, curLine);
|
||||
rects.addAll(unmerged);
|
||||
prevLine = curLine;
|
||||
}
|
||||
// Add anything left over
|
||||
rects.addAll(prevLine);
|
||||
for (Iterator i=rects.iterator();i.hasNext();) {
|
||||
Rectangle r = (Rectangle)i.next();
|
||||
if (!out.outputRange(r.x, r.y, r.width, r.height)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static Set mergeRects(Set prev, Set current) {
|
||||
Set unmerged = new HashSet(prev);
|
||||
if (!prev.isEmpty() && !current.isEmpty()) {
|
||||
Rectangle[] pr = (Rectangle[])prev.toArray(new Rectangle[prev.size()]);
|
||||
Rectangle[] cr = (Rectangle[])current.toArray(new Rectangle[current.size()]);
|
||||
int ipr = 0;
|
||||
int icr = 0;
|
||||
while (ipr < pr.length && icr < cr.length) {
|
||||
while (cr[icr].x < pr[ipr].x) {
|
||||
if (++icr == cr.length) {
|
||||
return unmerged;
|
||||
}
|
||||
}
|
||||
if (cr[icr].x == pr[ipr].x && cr[icr].width == pr[ipr].width) {
|
||||
unmerged.remove(pr[ipr]);
|
||||
cr[icr].y = pr[ipr].y;
|
||||
cr[icr].height = pr[ipr].height + 1;
|
||||
++icr;
|
||||
}
|
||||
else {
|
||||
++ipr;
|
||||
}
|
||||
}
|
||||
}
|
||||
return unmerged;
|
||||
}
|
||||
|
||||
}
|
||||
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -0,0 +1,533 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* <p/>
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.dnd;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Component;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.Transparency;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.dnd.DnDConstants;
|
||||
import java.awt.dnd.DragGestureEvent;
|
||||
import java.awt.dnd.DragGestureListener;
|
||||
import java.awt.dnd.DragSource;
|
||||
import java.awt.dnd.DragSourceContext;
|
||||
import java.awt.dnd.DragSourceDragEvent;
|
||||
import java.awt.dnd.DragSourceDropEvent;
|
||||
import java.awt.dnd.DragSourceEvent;
|
||||
import java.awt.dnd.DragSourceListener;
|
||||
import java.awt.dnd.DragSourceMotionListener;
|
||||
import java.awt.dnd.DropTargetDragEvent;
|
||||
import java.awt.dnd.DropTargetDropEvent;
|
||||
import java.awt.dnd.DropTargetEvent;
|
||||
import java.awt.dnd.InvalidDnDOperationException;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JColorChooser;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.JTree;
|
||||
import javax.swing.text.JTextComponent;
|
||||
|
||||
/** Provides simplified drag handling for a component.
|
||||
* Usage:<br>
|
||||
* <pre><code>
|
||||
* int actions = DnDConstants.MOVE_OR_COPY;
|
||||
* Component component = ...;
|
||||
* DragHandler handler = new DragHandler(component, actions);
|
||||
* </code></pre>
|
||||
* <ul>
|
||||
* <li>Supports painting an arbitrary {@link Icon} with transparency to
|
||||
* represent the item being dragged (restricted to the {@link java.awt.Window}
|
||||
* of the drag source if the platform doesn't support drag images).
|
||||
* <li>Disallow starting a drag if the user requests an unsupported action.
|
||||
* <li>Adjusts the cursor on drags with no modifier for which the default action
|
||||
* is disallowed but where one or more non-default actions are allowed, e.g. a
|
||||
* drag (with no modifiers) to a target which supports "link" should change the
|
||||
* cursor to "link" (prior to 1.6, the JRE behavior is to display a
|
||||
* "not allowed" cursor, even though the action actually depends on how the
|
||||
* drop target responds).
|
||||
* <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4869264">
|
||||
* The bug</a> is fixed in java 1.6.
|
||||
* <li>Disallow drops to targets if the non-default (user-requested) action
|
||||
* is not supported by the target, e.g. the user requests a "copy" when the
|
||||
* target only supports "move". This is generally the responsibility of the
|
||||
* drop handler, which decides whether or not to accept a drag. The DragHandler
|
||||
* provides static modifier state information since the drop handler doesn't
|
||||
* have access to it.
|
||||
* </ul>
|
||||
* NOTE: Fundamentally, the active action is determined by the drop handler
|
||||
* in {@link DropTargetDragEvent#acceptDrag}, but often client code
|
||||
* simply relies on {@link DropTargetDragEvent#getDropAction}.
|
||||
*/
|
||||
//TODO: separate into the the following drag pieces:
|
||||
// * default cursor changing behavior fix (fixed in jre1.6) (global DSL)
|
||||
// * drag unselected item (fixed in 1.6, flag in 1.5.0.05+) bug not an issue w/DragHandler
|
||||
// * multi-selection drag workaround (if not using swing drag gesture recognizer)
|
||||
// proper multi-selection drag is provided for swing dnd as of 1.4
|
||||
// (use swing drag gesture recognizer if possible?) DSL+mouse listener
|
||||
//TODO: identify overlap with default Swing support + TransferHandler
|
||||
// * TransferHandler doesn't have drop location information (included in 1.6)
|
||||
// * SwingDropTarget allows listeners, so target highlighting is possible
|
||||
|
||||
//NOTE: acceptDrag(int) is simply indicates the drag is accepted; the action
|
||||
// value doesn't get propagated anywhere, it's certainly not communicated to
|
||||
// the drag source
|
||||
//MAYBE: should Transferable/Icon provision be a separate interface
|
||||
//(i.e. TransferHandler)? only if the rest of the drag handler is constant and
|
||||
// only the image needs to change (for standard components, e.g. tree cells,
|
||||
// table cells, etc.)
|
||||
|
||||
public abstract class DragHandler
|
||||
implements DragSourceListener, DragSourceMotionListener, DragGestureListener {
|
||||
|
||||
/** Default maximum size for ghosted images. */
|
||||
public static final Dimension MAX_GHOST_SIZE = new Dimension(250, 250);
|
||||
|
||||
/** Default transparency for ghosting. */
|
||||
public static final float DEFAULT_GHOST_ALPHA = 0.5f;
|
||||
|
||||
/** {@link #getModifiers} returns this value when the current
|
||||
* modifiers state is unknown.
|
||||
*/
|
||||
public static final int UNKNOWN_MODIFIERS = -1;
|
||||
|
||||
/** {@link #getTransferable} returns this value when
|
||||
* the current {@link Transferable} is unknown.
|
||||
*/
|
||||
public static final Transferable UNKNOWN_TRANSFERABLE = null;
|
||||
/** Convenience to reference {@link DnDConstants#ACTION_MOVE}. */
|
||||
protected static final int MOVE = DnDConstants.ACTION_MOVE;
|
||||
/** Convenience to reference {@link DnDConstants#ACTION_COPY}. */
|
||||
protected static final int COPY = DnDConstants.ACTION_COPY;
|
||||
/** Convenience to reference {@link DnDConstants#ACTION_LINK}. */
|
||||
protected static final int LINK = DnDConstants.ACTION_LINK;
|
||||
/** Convenience to reference {@link DnDConstants#ACTION_NONE}. */
|
||||
protected static final int NONE = DnDConstants.ACTION_NONE;
|
||||
|
||||
// TODO: w32 explorer: link=alt or ctrl+shift, copy=ctrl or shift
|
||||
// w32 others: copy=ctrl
|
||||
/** Modifier mask for a user-requested move. */
|
||||
static final int MOVE_MASK = InputEvent.SHIFT_DOWN_MASK;
|
||||
static final boolean OSX =
|
||||
System.getProperty("os.name").toLowerCase().indexOf("mac") != -1;
|
||||
/** Modifier mask for a user-requested copy. */
|
||||
static final int COPY_MASK =
|
||||
OSX ? InputEvent.ALT_DOWN_MASK : InputEvent.CTRL_DOWN_MASK;
|
||||
/** Modifier mask for a user-requested link. */
|
||||
static final int LINK_MASK =
|
||||
OSX ? InputEvent.ALT_DOWN_MASK|InputEvent.META_DOWN_MASK
|
||||
: InputEvent.CTRL_DOWN_MASK|InputEvent.SHIFT_DOWN_MASK;
|
||||
/** Modifier mask for any user-requested action. */
|
||||
static final int KEY_MASK =
|
||||
InputEvent.ALT_DOWN_MASK|InputEvent.META_DOWN_MASK
|
||||
|InputEvent.CTRL_DOWN_MASK|InputEvent.SHIFT_DOWN_MASK
|
||||
|InputEvent.ALT_GRAPH_DOWN_MASK;
|
||||
|
||||
private static int modifiers = UNKNOWN_MODIFIERS;
|
||||
private static Transferable transferable = UNKNOWN_TRANSFERABLE;
|
||||
|
||||
/** Used to communicate modifier state to {@link DropHandler}. Note that
|
||||
* this field will only be accurate when a {@link DragHandler} in
|
||||
* the same VM started the drag. Otherwise, {@link #UNKNOWN_MODIFIERS}
|
||||
* will be returned.
|
||||
*/
|
||||
static int getModifiers() {
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
/** Used to communicate the current {@link Transferable} during a drag,
|
||||
* if available. Work around absence of access to the data when dragging
|
||||
* pre-1.5.
|
||||
*/
|
||||
public static Transferable getTransferable(DropTargetEvent e) {
|
||||
if (e instanceof DropTargetDragEvent) {
|
||||
try {
|
||||
// getTransferable is available during drag only on 1.5+
|
||||
return (Transferable)
|
||||
e.getClass().getMethod("getTransferable", (Class[])null).invoke(e, (Object[])null);
|
||||
}
|
||||
catch(Exception ex) {
|
||||
// Method not available
|
||||
}
|
||||
}
|
||||
else if (e instanceof DropTargetDropEvent) {
|
||||
return ((DropTargetDropEvent)e).getTransferable();
|
||||
}
|
||||
return transferable;
|
||||
}
|
||||
|
||||
private int supportedActions;
|
||||
private boolean fixCursor = true;
|
||||
private Component dragSource;
|
||||
private GhostedDragImage ghost;
|
||||
private Point imageOffset;
|
||||
private Dimension maxGhostSize = MAX_GHOST_SIZE;
|
||||
private float ghostAlpha = DEFAULT_GHOST_ALPHA;
|
||||
|
||||
/** Enable drags from the given component, supporting the actions in
|
||||
* the given action mask.
|
||||
*/
|
||||
protected DragHandler(Component dragSource, int actions) {
|
||||
this.dragSource = dragSource;
|
||||
this.supportedActions = actions;
|
||||
try {
|
||||
String alpha = System.getProperty("DragHandler.alpha");
|
||||
if (alpha != null) {
|
||||
try {
|
||||
ghostAlpha = Float.parseFloat(alpha);
|
||||
}
|
||||
catch(NumberFormatException e) { }
|
||||
}
|
||||
String max = System.getProperty("DragHandler.maxDragImageSize");
|
||||
if (max != null) {
|
||||
String[] size = max.split("x");
|
||||
if (size.length == 2) {
|
||||
try {
|
||||
maxGhostSize = new Dimension(Integer.parseInt(size[0]),
|
||||
Integer.parseInt(size[1]));
|
||||
}
|
||||
catch(NumberFormatException e) { }
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(SecurityException e) { }
|
||||
// Avoid having more than one gesture recognizer active
|
||||
disableSwingDragSupport(dragSource);
|
||||
DragSource src = DragSource.getDefaultDragSource();
|
||||
src.createDefaultDragGestureRecognizer(dragSource, supportedActions, this);
|
||||
}
|
||||
|
||||
private void disableSwingDragSupport(Component comp) {
|
||||
if (comp instanceof JTree) {
|
||||
((JTree)comp).setDragEnabled(false);
|
||||
}
|
||||
else if (comp instanceof JList) {
|
||||
((JList)comp).setDragEnabled(false);
|
||||
}
|
||||
else if (comp instanceof JTable) {
|
||||
((JTable)comp).setDragEnabled(false);
|
||||
}
|
||||
else if (comp instanceof JTextComponent) {
|
||||
((JTextComponent)comp).setDragEnabled(false);
|
||||
}
|
||||
else if (comp instanceof JColorChooser) {
|
||||
((JColorChooser)comp).setDragEnabled(false);
|
||||
}
|
||||
else if (comp instanceof JFileChooser) {
|
||||
((JFileChooser)comp).setDragEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
/** Override to control whether a drag is started. The default
|
||||
* implementation disallows the drag if the user is applying modifiers
|
||||
* and the user-requested action is not supported.
|
||||
*/
|
||||
protected boolean canDrag(DragGestureEvent e) {
|
||||
int mods = e.getTriggerEvent().getModifiersEx() & KEY_MASK;
|
||||
if (mods == MOVE_MASK)
|
||||
return (supportedActions & MOVE) != 0;
|
||||
if (mods == COPY_MASK)
|
||||
return (supportedActions & COPY) != 0;
|
||||
if (mods == LINK_MASK)
|
||||
return (supportedActions & LINK) != 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Update the modifiers hint. */
|
||||
protected void setModifiers(int mods) {
|
||||
modifiers = mods;
|
||||
}
|
||||
/** Override to provide an appropriate {@link Transferable} representing
|
||||
* the data being dragged.
|
||||
*/
|
||||
protected abstract Transferable getTransferable(DragGestureEvent e);
|
||||
|
||||
/** Override this to provide a custom image. The {@link Icon}
|
||||
* returned by this method by default is <code>null</code>, which results
|
||||
* in no drag image.
|
||||
* @param srcOffset set this to be the offset from the drag source
|
||||
* component's upper left corner to the image's upper left corner.
|
||||
* For example, when dragging a row from a list, the offset would be the
|
||||
* row's bounding rectangle's (x,y) coordinate.<p>
|
||||
* The default value is (0,0), so if unchanged, the image is will
|
||||
* use the same origin as the drag source component.
|
||||
*/
|
||||
protected Icon getDragIcon(DragGestureEvent e, Point srcOffset) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Override to perform any decoration of the target at the start of a drag,
|
||||
* if desired.
|
||||
*/
|
||||
protected void dragStarted(DragGestureEvent e) { }
|
||||
|
||||
/** Called when a user drag gesture is recognized. This method is
|
||||
* responsible for initiating the drag operation.
|
||||
*/
|
||||
public void dragGestureRecognized(DragGestureEvent e) {
|
||||
if ((e.getDragAction() & supportedActions) != 0
|
||||
&& canDrag(e)) {
|
||||
setModifiers(e.getTriggerEvent().getModifiersEx() & KEY_MASK);
|
||||
Transferable transferable = getTransferable(e);
|
||||
if (transferable == null)
|
||||
return;
|
||||
try {
|
||||
Point srcOffset = new Point(0, 0);
|
||||
Icon icon = getDragIcon(e, srcOffset);
|
||||
Point origin = e.getDragOrigin();
|
||||
// offset of the image origin from the cursor
|
||||
imageOffset = new Point(srcOffset.x - origin.x,
|
||||
srcOffset.y - origin.y);
|
||||
Icon dragIcon = scaleDragIcon(icon, imageOffset);
|
||||
Cursor cursor = null;
|
||||
if (dragIcon != null && DragSource.isDragImageSupported()) {
|
||||
GraphicsConfiguration gc = e.getComponent().getGraphicsConfiguration();
|
||||
e.startDrag(cursor, createDragImage(gc, dragIcon),
|
||||
imageOffset, transferable, this);
|
||||
}
|
||||
else {
|
||||
if (dragIcon != null) {
|
||||
Point screen = dragSource.getLocationOnScreen();
|
||||
screen.translate(origin.x, origin.y);
|
||||
Point cursorOffset = new Point(-imageOffset.x, -imageOffset.y);
|
||||
ghost = new GhostedDragImage(dragSource, dragIcon,
|
||||
getImageLocation(screen), cursorOffset);
|
||||
ghost.setAlpha(ghostAlpha);
|
||||
}
|
||||
e.startDrag(cursor, transferable, this);
|
||||
}
|
||||
dragStarted(e);
|
||||
moved = false;
|
||||
e.getDragSource().addDragSourceMotionListener(this);
|
||||
DragHandler.transferable = transferable;
|
||||
}
|
||||
catch (InvalidDnDOperationException ex) {
|
||||
if (ghost != null) {
|
||||
ghost.dispose();
|
||||
ghost = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Reduce the size of the given drag icon, if appropriate. When using
|
||||
* a smaller drag icon, we also need to adjust the cursor offset within
|
||||
* the icon.
|
||||
*/
|
||||
protected Icon scaleDragIcon(Icon icon, Point imageOffset) {
|
||||
/*
|
||||
if (icon != null && maxGhostSize != null) {
|
||||
if (icon.getIconWidth() > maxGhostSize.width
|
||||
|| icon.getIconHeight() > maxGhostSize.height) {
|
||||
Icon scaled = new ScaledIcon(icon, maxGhostSize.width,
|
||||
maxGhostSize.height);
|
||||
double scale = (double)scaled.getIconWidth()/icon.getIconWidth();
|
||||
imageOffset.x *= scale;
|
||||
imageOffset.y *= scale;
|
||||
return scaled;
|
||||
}
|
||||
}*/
|
||||
return icon;
|
||||
}
|
||||
|
||||
/** Create an image from the given icon. The image is provided to the
|
||||
* native handler if drag images are supported natively.
|
||||
*/
|
||||
protected Image createDragImage(GraphicsConfiguration gc, Icon icon) {
|
||||
int w = icon.getIconWidth();
|
||||
int h = icon.getIconHeight();
|
||||
BufferedImage image = gc.createCompatibleImage(w, h, Transparency.TRANSLUCENT);
|
||||
Graphics2D g = (Graphics2D)image.getGraphics();
|
||||
g.setComposite(AlphaComposite.Clear);
|
||||
g.fillRect(0, 0, w, h);
|
||||
// Ignore pixels in the buffered image
|
||||
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC, ghostAlpha));
|
||||
icon.paintIcon(dragSource, g, 0, 0);
|
||||
g.dispose();
|
||||
return image;
|
||||
}
|
||||
|
||||
/** Reduce a multiply-set bit mask to a single bit. */
|
||||
private int reduce(int actions) {
|
||||
if ((actions & MOVE) != 0 && actions != MOVE) {
|
||||
return MOVE;
|
||||
}
|
||||
else if ((actions & COPY) != 0 && actions != COPY) {
|
||||
return COPY;
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
|
||||
protected Cursor getCursorForAction(int actualAction) {
|
||||
switch(actualAction) {
|
||||
case MOVE:
|
||||
return DragSource.DefaultMoveDrop;
|
||||
case COPY:
|
||||
return DragSource.DefaultCopyDrop;
|
||||
case LINK:
|
||||
return DragSource.DefaultLinkDrop;
|
||||
default:
|
||||
return DragSource.DefaultMoveNoDrop;
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the first available action supported by source and target. */
|
||||
protected int getAcceptableDropAction(int targetActions) {
|
||||
return reduce(supportedActions & targetActions);
|
||||
}
|
||||
|
||||
/** Get the currently requested drop action. */
|
||||
protected int getDropAction(DragSourceEvent ev) {
|
||||
if (ev instanceof DragSourceDragEvent) {
|
||||
DragSourceDragEvent e = (DragSourceDragEvent)ev;
|
||||
return e.getDropAction();
|
||||
}
|
||||
if (ev instanceof DragSourceDropEvent) {
|
||||
return ((DragSourceDropEvent)ev).getDropAction();
|
||||
}
|
||||
return NONE;
|
||||
}
|
||||
|
||||
/** Pick a different drop action if the target doesn't support the current
|
||||
* one and there are no modifiers.
|
||||
*/
|
||||
protected int adjustDropAction(DragSourceEvent ev) {
|
||||
int action = getDropAction(ev);
|
||||
if (ev instanceof DragSourceDragEvent) {
|
||||
DragSourceDragEvent e = (DragSourceDragEvent)ev;
|
||||
if (action == NONE) {
|
||||
int mods = e.getGestureModifiersEx() & KEY_MASK;
|
||||
if (mods == 0) {
|
||||
action = getAcceptableDropAction(e.getTargetActions());
|
||||
}
|
||||
}
|
||||
}
|
||||
return action;
|
||||
}
|
||||
|
||||
protected void updateCursor(DragSourceEvent ev) {
|
||||
if (!fixCursor)
|
||||
return;
|
||||
Cursor cursor = getCursorForAction(adjustDropAction(ev));
|
||||
ev.getDragSourceContext().setCursor(cursor);
|
||||
}
|
||||
|
||||
static String actionString(int action) {
|
||||
switch(action) {
|
||||
case MOVE: return "MOVE";
|
||||
case MOVE|COPY: return "MOVE|COPY";
|
||||
case MOVE|LINK: return "MOVE|LINK";
|
||||
case MOVE|COPY|LINK: return "MOVE|COPY|LINK";
|
||||
case COPY: return "COPY";
|
||||
case COPY|LINK: return "COPY|LINK";
|
||||
case LINK: return "LINK";
|
||||
default: return "NONE";
|
||||
}
|
||||
}
|
||||
private String lastAction;
|
||||
private void describe(String type, DragSourceEvent e) {
|
||||
if (false) {
|
||||
DragSourceContext ds = e.getDragSourceContext();
|
||||
String msg = "drag: " + type;
|
||||
if (e instanceof DragSourceDragEvent) {
|
||||
DragSourceDragEvent ev = (DragSourceDragEvent)e;
|
||||
msg += ": src=" + actionString(ds.getSourceActions())
|
||||
+ " usr=" + actionString(ev.getUserAction())
|
||||
+ " tgt=" + actionString(ev.getTargetActions())
|
||||
+ " act=" + actionString(ev.getDropAction())
|
||||
+ " mods=" + ev.getGestureModifiersEx();
|
||||
}
|
||||
else {
|
||||
msg += ": e=" + e;
|
||||
}
|
||||
if (!msg.equals(lastAction)) {
|
||||
System.out.println(lastAction = msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void dragDropEnd(DragSourceDropEvent e) {
|
||||
describe("end", e);
|
||||
setModifiers(UNKNOWN_MODIFIERS);
|
||||
transferable = UNKNOWN_TRANSFERABLE;
|
||||
if (ghost != null) {
|
||||
if (e.getDropSuccess()) {
|
||||
ghost.dispose();
|
||||
}
|
||||
else {
|
||||
ghost.returnToOrigin();
|
||||
}
|
||||
ghost = null;
|
||||
}
|
||||
DragSource src = e.getDragSourceContext().getDragSource();
|
||||
src.removeDragSourceMotionListener(this);
|
||||
moved = false;
|
||||
}
|
||||
|
||||
private Point getImageLocation(Point where) {
|
||||
where.translate(imageOffset.x, imageOffset.y);
|
||||
return where;
|
||||
}
|
||||
|
||||
public void dragEnter(DragSourceDragEvent e) {
|
||||
describe("enter", e);
|
||||
if (ghost != null) {
|
||||
ghost.move(getImageLocation(e.getLocation()));
|
||||
}
|
||||
updateCursor(e);
|
||||
}
|
||||
|
||||
// bug workaround; need to skip initial dragMouseMoved event,
|
||||
// which has reports "0" for the available target actions (1.4+?)
|
||||
// filed a bug for this
|
||||
private boolean moved;
|
||||
public void dragMouseMoved(DragSourceDragEvent e) {
|
||||
describe("move", e);
|
||||
if (ghost != null) {
|
||||
ghost.move(getImageLocation(e.getLocation()));
|
||||
}
|
||||
if (moved)
|
||||
updateCursor(e);
|
||||
moved = true;
|
||||
}
|
||||
|
||||
public void dragOver(DragSourceDragEvent e) {
|
||||
describe("over", e);
|
||||
if (ghost != null) {
|
||||
ghost.move(getImageLocation(e.getLocation()));
|
||||
}
|
||||
updateCursor(e);
|
||||
}
|
||||
|
||||
public void dragExit(DragSourceEvent e) {
|
||||
describe("exit", e);
|
||||
}
|
||||
|
||||
public void dropActionChanged(DragSourceDragEvent e) {
|
||||
describe("change", e);
|
||||
setModifiers(e.getGestureModifiersEx() & KEY_MASK);
|
||||
if (ghost != null) {
|
||||
ghost.move(getImageLocation(e.getLocation()));
|
||||
}
|
||||
updateCursor(e);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,393 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* <p/>
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.dnd;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Point;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.awt.dnd.DnDConstants;
|
||||
import java.awt.dnd.DropTarget;
|
||||
import java.awt.dnd.DropTargetContext;
|
||||
import java.awt.dnd.DropTargetDragEvent;
|
||||
import java.awt.dnd.DropTargetDropEvent;
|
||||
import java.awt.dnd.DropTargetEvent;
|
||||
import java.awt.dnd.DropTargetListener;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/** Provides simplified drop handling for a component.
|
||||
* Usage:<br>
|
||||
* <pre><code>
|
||||
* int actions = DnDConstants.MOVE_OR_COPY;
|
||||
* Component component = ...;
|
||||
* DropHandler handler = new DropHandler(component, actions);
|
||||
* </code></pre>
|
||||
* <p>
|
||||
* <ul>
|
||||
* <li>Accept drops where the action is the default (i.e. no modifiers) but
|
||||
* the intersection of source and target actions is <i>not</i> the default.
|
||||
* Doing so allows the source to adjust the cursor appropriately.
|
||||
* <li>Refuse drops where the user modifiers request an action that is not
|
||||
* supported (this works for all cases except when the drag source is not
|
||||
* a {@link DragHandler} and the user explicitly requests a MOVE operation;
|
||||
* this is indistinguishable from a drag with no modifiers unless we have
|
||||
* access to the key modifiers, which {@link DragHandler} provides).
|
||||
* <li>Drops may be refused based on data flavor, location, intended drop
|
||||
* action, or any combination of those, by overriding {@link #canDrop}.
|
||||
* <li>Custom decoration of the drop area may be performed in
|
||||
* {@link #paintDropTarget(DropTargetEvent, int, Point)} or by providing
|
||||
* a {@link DropTargetPainter}.
|
||||
* </ul>
|
||||
*
|
||||
* The method {@link #getDropAction(DropTargetEvent)} follows these steps to
|
||||
* determine the appropriate action (if any).
|
||||
* <ul>
|
||||
* <li>{@link #isSupported(DataFlavor[])} determines if there are any supported
|
||||
* flavors
|
||||
* <li>{@link #getDropActionsForFlavors(DataFlavor[])} reduces the supported
|
||||
* actions based on available flavors. For instance, a text field for file
|
||||
* paths might support {@link DnDConstants#ACTION_COPY_OR_MOVE} on a plain
|
||||
* string, but {@link DnDConstants#ACTION_LINK} might be the only action
|
||||
* supported on a file.
|
||||
* <li>{@link #getDropAction(DropTargetEvent, int, int, int)} relax the action
|
||||
* if it's the default, or restrict it for user requested actions.
|
||||
* <li>{@link #canDrop(DropTargetEvent, int, Point)} change the action based on
|
||||
* the location in the drop target component, or any other criteria.
|
||||
* </ul>
|
||||
*
|
||||
* Override {@link #drop(DropTargetDropEvent, int)} to handle the drop.
|
||||
* You should invoke {@link DropTargetDropEvent#dropComplete} as soon
|
||||
* as the {@link Transferable} data is obtained, to avoid making the DnD
|
||||
* operation look suspended.
|
||||
*
|
||||
* @see DragHandler
|
||||
* @author twall
|
||||
*/
|
||||
// NOTE: you could probably make one of these handlers serve several targets,
|
||||
// but for simplicity, keep the mapping 1-1-1 handler/droptarget/component
|
||||
// TODO: look into making use of the existing
|
||||
// Transferable.SwingDropTarget on JComponent instances instead of
|
||||
// creating a new DropTarget; we can add self as a listener; probably would
|
||||
// want to remove the default TransferHandler.DropHandler, which uses
|
||||
// the TransferHandler to drop
|
||||
public abstract class DropHandler implements DropTargetListener {
|
||||
|
||||
private int acceptedActions;
|
||||
private List acceptedFlavors;
|
||||
private DropTarget dropTarget;
|
||||
private boolean active = true;
|
||||
private DropTargetPainter painter;
|
||||
|
||||
/** Create a handler that allows the given set of actions. If using
|
||||
* this constructor, you will need to override {@link #isSupported} to
|
||||
* indicate which data flavors are allowed.
|
||||
*/
|
||||
public DropHandler(Component c, int acceptedActions) {
|
||||
this(c, acceptedActions, new DataFlavor[0]);
|
||||
}
|
||||
|
||||
/** Enable handling of drops, indicating what actions and flavors are
|
||||
* acceptable.
|
||||
* @param c The component to receive drops
|
||||
* @param acceptedActions Allowed actions for drops
|
||||
* @param acceptedFlavors Allowed data flavors for drops
|
||||
* @see #isSupported
|
||||
*/
|
||||
public DropHandler(final Component c, int acceptedActions, DataFlavor[] acceptedFlavors) {
|
||||
this(c, acceptedActions, acceptedFlavors, null);
|
||||
}
|
||||
|
||||
/** Enable handling of drops, indicating what actions and flavors are
|
||||
* acceptable, and providing a painter for drop target feedback.
|
||||
* @param c The component to receive drops
|
||||
* @param acceptedActions Allowed actions for drops
|
||||
* @param acceptedFlavors Allowed data flavors for drops
|
||||
* @param painter Painter to handle drop target feedback
|
||||
* @see #paintDropTarget
|
||||
*/
|
||||
public DropHandler(final Component c, int acceptedActions,
|
||||
DataFlavor[] acceptedFlavors, DropTargetPainter painter) {
|
||||
this.acceptedActions = acceptedActions;
|
||||
this.acceptedFlavors = Arrays.asList(acceptedFlavors);
|
||||
this.painter = painter;
|
||||
dropTarget = new DropTarget(c, acceptedActions, this, active);
|
||||
}
|
||||
|
||||
protected DropTarget getDropTarget() {
|
||||
return dropTarget;
|
||||
}
|
||||
|
||||
/** Whether this drop target is active. */
|
||||
public boolean isActive() { return active; }
|
||||
|
||||
/** Set whether this handler (and thus its drop target) will accept
|
||||
* any drops.
|
||||
*/
|
||||
public void setActive(boolean active) {
|
||||
this.active = active;
|
||||
if (dropTarget != null) {
|
||||
dropTarget.setActive(active);
|
||||
}
|
||||
}
|
||||
|
||||
/** Indicate the actions available for the given list of data flavors.
|
||||
* Override this method if the acceptable drop actions depend
|
||||
* on the currently available {@link DataFlavor}. The default returns
|
||||
* the accepted actions passed into the constructor.
|
||||
* @param dataFlavors currently available flavors
|
||||
* @see #getDropAction(DropTargetEvent, int, int, int)
|
||||
* @see #canDrop(DropTargetEvent, int, Point)
|
||||
*/
|
||||
protected int getDropActionsForFlavors(DataFlavor[] dataFlavors) {
|
||||
return acceptedActions;
|
||||
}
|
||||
|
||||
/** Calculate the effective action. The default implementation
|
||||
* checks whether any {@link DataFlavor}s are supported, and if so,
|
||||
* will change the current action from {@link DnDConstants#ACTION_NONE} to
|
||||
* something in common between the source and destination. Refuse
|
||||
* user-requested actions if they are not supported (rather than silently
|
||||
* accepting a non-user-requested action, which is the Java's DnD default
|
||||
* behavior). The drop action is forced to {@link DnDConstants#ACTION_NONE}
|
||||
* if there is no supported data flavor.<p>
|
||||
* @see #isSupported(DataFlavor[])
|
||||
* @see #getDropActionsForFlavors
|
||||
* @see #getDropAction(DropTargetEvent, int, int, int)
|
||||
* @see #canDrop(DropTargetEvent, int, Point)
|
||||
*/
|
||||
protected int getDropAction(DropTargetEvent e) {
|
||||
int currentAction = DragHandler.NONE;
|
||||
int sourceActions = DragHandler.NONE;
|
||||
Point location = null;
|
||||
DataFlavor[] flavors = new DataFlavor[0];
|
||||
if (e instanceof DropTargetDragEvent) {
|
||||
DropTargetDragEvent ev = (DropTargetDragEvent)e;
|
||||
currentAction = ev.getDropAction();
|
||||
sourceActions = ev.getSourceActions();
|
||||
flavors = ev.getCurrentDataFlavors();
|
||||
location = ev.getLocation();
|
||||
}
|
||||
else if (e instanceof DropTargetDropEvent) {
|
||||
DropTargetDropEvent ev = (DropTargetDropEvent)e;
|
||||
currentAction = ev.getDropAction();
|
||||
sourceActions = ev.getSourceActions();
|
||||
flavors = ev.getCurrentDataFlavors();
|
||||
location = ev.getLocation();
|
||||
}
|
||||
if (isSupported(flavors)) {
|
||||
int availableActions = getDropActionsForFlavors(flavors);
|
||||
currentAction = getDropAction(e, currentAction, sourceActions, availableActions);
|
||||
if (currentAction != DragHandler.NONE) {
|
||||
if (canDrop(e, currentAction, location)) {
|
||||
return currentAction;
|
||||
}
|
||||
}
|
||||
}
|
||||
return DragHandler.NONE;
|
||||
}
|
||||
|
||||
/* Adjust the drop action depending on whether the
|
||||
* current action is the default or a specific user-requested action.
|
||||
* The default implementation will change the current action from
|
||||
* {@link DnDConstants#ACTION_NONE} if there are actions in
|
||||
* common between the source and destination. It will refuse user-requested
|
||||
* actions if they are not supported (rather than silently accepting
|
||||
* a non-user-requested action, which is the behavior of Swing's default
|
||||
* drop handlers).<p>
|
||||
* You can override this method if you wish to adjust the action based
|
||||
* on the the drag location; if you wish to deny drops based on location,
|
||||
* override {@link #canDrop} instead. If you wish to adjust
|
||||
* the action based on the available data flavors, override
|
||||
* {@link #getDropActionsForFlavor} instead.
|
||||
* @see #getDropActionsForFlavor
|
||||
* @see #canDrop(DropTargetEvent, int, Point)
|
||||
*/
|
||||
protected int getDropAction(DropTargetEvent e, int currentAction,
|
||||
int sourceActions, int acceptedActions) {
|
||||
boolean modifiersActive = modifiersActive(currentAction);
|
||||
if ((currentAction & acceptedActions) == DragHandler.NONE
|
||||
&& !modifiersActive) {
|
||||
int action = acceptedActions & sourceActions;
|
||||
currentAction = action;
|
||||
}
|
||||
else if (modifiersActive) {
|
||||
int action = currentAction & acceptedActions & sourceActions;
|
||||
if (action != currentAction) {
|
||||
currentAction = action;
|
||||
}
|
||||
}
|
||||
return currentAction;
|
||||
}
|
||||
|
||||
/** Returns whether there are key modifiers active ,
|
||||
* or false if they can't be determined.
|
||||
* We use the DragHandler hint, if available, or fall back to whether
|
||||
* the drop action is other than the default (move).
|
||||
*/
|
||||
protected boolean modifiersActive(int dropAction) {
|
||||
int mods = DragHandler.getModifiers();
|
||||
if (mods == DragHandler.UNKNOWN_MODIFIERS) {
|
||||
if (dropAction == DragHandler.LINK
|
||||
|| dropAction == DragHandler.COPY) {
|
||||
return true;
|
||||
}
|
||||
// Can't (yet) distinguish between a forced and a default move
|
||||
// without help from DragHandler
|
||||
return false;
|
||||
}
|
||||
return mods != 0;
|
||||
}
|
||||
|
||||
private String lastAction;
|
||||
private void describe(String type, DropTargetEvent e) {
|
||||
if (false) {
|
||||
String msg = "drop: " + type;
|
||||
if (e instanceof DropTargetDragEvent) {
|
||||
DropTargetContext dtc = e.getDropTargetContext();
|
||||
DropTarget dt = dtc.getDropTarget();
|
||||
DropTargetDragEvent ev = (DropTargetDragEvent)e;
|
||||
msg += ": src=" + DragHandler.actionString(ev.getSourceActions())
|
||||
+ " tgt=" + DragHandler.actionString(dt.getDefaultActions())
|
||||
+ " act=" + DragHandler.actionString(ev.getDropAction());
|
||||
}
|
||||
else if (e instanceof DropTargetDropEvent) {
|
||||
DropTargetContext dtc = e.getDropTargetContext();
|
||||
DropTarget dt = dtc.getDropTarget();
|
||||
DropTargetDropEvent ev = (DropTargetDropEvent)e;
|
||||
msg += ": src=" + DragHandler.actionString(ev.getSourceActions())
|
||||
+ " tgt=" + DragHandler.actionString(dt.getDefaultActions())
|
||||
+ " act=" + DragHandler.actionString(ev.getDropAction());
|
||||
}
|
||||
if (!msg.equals(lastAction)) {
|
||||
System.out.println(lastAction = msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Accept or reject the drag represented by the given event. Returns
|
||||
* the action determined by {@link #getDropAction(DropTargetEvent)}.
|
||||
*/
|
||||
protected int acceptOrReject(DropTargetDragEvent e) {
|
||||
int action = getDropAction(e);
|
||||
if (action != DragHandler.NONE) {
|
||||
// NOTE: the action argument (as of 1.5+) is only passed
|
||||
// to the DropTargetContextPeer, *not* the drag source
|
||||
e.acceptDrag(action);
|
||||
}
|
||||
else {
|
||||
e.rejectDrag();
|
||||
}
|
||||
return action;
|
||||
}
|
||||
|
||||
public void dragEnter(DropTargetDragEvent e) {
|
||||
describe("enter(tgt)", e);
|
||||
int action = acceptOrReject(e);
|
||||
paintDropTarget(e, action, e.getLocation());
|
||||
}
|
||||
|
||||
public void dragOver(DropTargetDragEvent e) {
|
||||
describe("over(tgt)", e);
|
||||
int action = acceptOrReject(e);
|
||||
paintDropTarget(e, action, e.getLocation());
|
||||
}
|
||||
|
||||
public void dragExit(DropTargetEvent e) {
|
||||
describe("exit(tgt)", e);
|
||||
paintDropTarget(e, DragHandler.NONE, null);
|
||||
}
|
||||
|
||||
public void dropActionChanged(DropTargetDragEvent e) {
|
||||
describe("change(tgt)", e);
|
||||
int action = acceptOrReject(e);
|
||||
paintDropTarget(e, action, e.getLocation());
|
||||
}
|
||||
|
||||
/** Indicates the user has initiated a drop. The default performs all
|
||||
* standard drop validity checking and handling, then invokes
|
||||
* {@link #drop(DropTargetDropEvent,int)} if the drop looks acceptable.
|
||||
*/
|
||||
public void drop(DropTargetDropEvent e) {
|
||||
describe("drop(tgt)", e);
|
||||
int action = getDropAction(e);
|
||||
if (action != DragHandler.NONE) {
|
||||
e.acceptDrop(action);
|
||||
try {
|
||||
drop(e, action);
|
||||
// Just in case this hasn't been done yet
|
||||
e.dropComplete(true);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
e.dropComplete(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
e.rejectDrop();
|
||||
}
|
||||
paintDropTarget(e, DragHandler.NONE, e.getLocation());
|
||||
}
|
||||
|
||||
/** Return whether any of the flavors in the given list are accepted.
|
||||
* The list is compared against the accepted list provided in the
|
||||
* constructor.
|
||||
*/
|
||||
protected boolean isSupported(DataFlavor[] flavors) {
|
||||
Set set = new HashSet(Arrays.asList(flavors));
|
||||
set.retainAll(acceptedFlavors);
|
||||
return !set.isEmpty();
|
||||
}
|
||||
|
||||
/** Update the appearance of the target component. Normally the decoration
|
||||
* should be painted only if the event is an instance of
|
||||
* {@link DropTargetDragEvent} with an action that is not
|
||||
* {@link DragHandler#NONE}. Otherwise the decoration should be removed
|
||||
* or hidden.
|
||||
* <p>
|
||||
* For an easy way to highlight the drop target, consider using a single
|
||||
* instance of <code>AbstractComponentDecorator</code> and moving it
|
||||
* according to the intended drop location.
|
||||
* @param e The drop target event
|
||||
* @param action The action for the drop
|
||||
* @param location The intended drop location, or null if there is none
|
||||
*/
|
||||
protected void paintDropTarget(DropTargetEvent e, int action, Point location) {
|
||||
if (painter != null) {
|
||||
painter.paintDropTarget(e, action, location);
|
||||
}
|
||||
}
|
||||
|
||||
/** Indicate whether the given drop action is acceptable at the given
|
||||
* location. This method is the last check performed by
|
||||
* {@link #getDropAction(DropTargetEvent)}.
|
||||
* You may override this method to refuse drops on certain areas
|
||||
* within the drop target component. The default always returns true.
|
||||
*/
|
||||
protected boolean canDrop(DropTargetEvent e, int action, Point location) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Handle an incoming drop with the given action. The action passed in
|
||||
* might be different from {@link DropTargetDropEvent#getDropAction},
|
||||
* for instance, if there are no modifiers and the default action is not
|
||||
* supported. Calling {@link DropTargetDropEvent#dropComplete} is
|
||||
* recommended as soon as the {@link Transferable} data is obtained; this
|
||||
* allows the drag source to reset the cursor and any drag images which
|
||||
* may be in effect.
|
||||
*/
|
||||
protected abstract void drop(DropTargetDropEvent e, int action) throws UnsupportedFlavorException, IOException;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* <p/>
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.dnd;
|
||||
|
||||
import java.awt.Point;
|
||||
import java.awt.dnd.DropTargetEvent;
|
||||
|
||||
/** Provides a callback for {@link DropHandler} to customize drop target
|
||||
* feedback.
|
||||
* @author twall
|
||||
*/
|
||||
public interface DropTargetPainter {
|
||||
void paintDropTarget(DropTargetEvent e, int action, Point location);
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* <p/>
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.dnd;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Window;
|
||||
import java.awt.dnd.DragSource;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.geom.Area;
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.Timer;
|
||||
|
||||
import com.sun.jna.platform.WindowUtils;
|
||||
|
||||
/** Provide a ghosted drag image for use during drags where
|
||||
* {@link DragSource#isDragImageSupported} returns false.<p>
|
||||
* Its location in screen coordinates may be changed via {@link #move}.<p>
|
||||
* When the image is no longer needed, invoke {@link #dispose}, which
|
||||
* hides the graphic immediately, or {@link #returnToOrigin}, which
|
||||
* moves the image to its original location and then disposes it.
|
||||
*/
|
||||
public class GhostedDragImage {
|
||||
|
||||
private static final float DEFAULT_ALPHA = .5f;
|
||||
private Window dragImage;
|
||||
// Initial image position, relative to drag source
|
||||
private Point origin;
|
||||
|
||||
/** Create a ghosted drag image, using the given icon.
|
||||
* @param icon image to be drawn
|
||||
* @param initialScreenLoc initial screen location of the image
|
||||
*/
|
||||
public GhostedDragImage(Component dragSource, final Icon icon, Point initialScreenLoc,
|
||||
final Point cursorOffset) {
|
||||
Window parent = dragSource instanceof Window
|
||||
? (Window)dragSource : SwingUtilities.getWindowAncestor(dragSource);
|
||||
// FIXME ensure gc is compatible (X11)
|
||||
GraphicsConfiguration gc = parent.getGraphicsConfiguration();
|
||||
dragImage = new Window(JOptionPane.getRootFrame(), gc) {
|
||||
public void paint(Graphics g) {
|
||||
icon.paintIcon(this, g, 0, 0);
|
||||
}
|
||||
public Dimension getPreferredSize() {
|
||||
return new Dimension(icon.getIconWidth(), icon.getIconHeight());
|
||||
}
|
||||
public Dimension getMinimumSize() {
|
||||
return getPreferredSize();
|
||||
}
|
||||
public Dimension getMaximumSize() {
|
||||
return getPreferredSize();
|
||||
}
|
||||
};
|
||||
dragImage.setFocusableWindowState(false);
|
||||
dragImage.setName("###overrideRedirect###");
|
||||
Icon dragIcon = new Icon() {
|
||||
public int getIconHeight() {
|
||||
return icon.getIconHeight();
|
||||
}
|
||||
public int getIconWidth() {
|
||||
return icon.getIconWidth();
|
||||
}
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
g = g.create();
|
||||
Area area = new Area(new Rectangle(x, y, getIconWidth(), getIconHeight()));
|
||||
// X11 needs more of a window due to differences in event processing
|
||||
area.subtract(new Area(new Rectangle(x + cursorOffset.x-1, y + cursorOffset.y-1, 3, 3)));
|
||||
g.setClip(area);
|
||||
icon.paintIcon(c, g, x, y);
|
||||
g.dispose();
|
||||
}
|
||||
|
||||
};
|
||||
dragImage.pack();
|
||||
WindowUtils.setWindowMask(dragImage, dragIcon);
|
||||
WindowUtils.setWindowAlpha(dragImage, DEFAULT_ALPHA);
|
||||
move(initialScreenLoc);
|
||||
dragImage.setVisible(true);
|
||||
}
|
||||
|
||||
/** Set the transparency of the ghosted image. */
|
||||
public void setAlpha(float alpha) {
|
||||
WindowUtils.setWindowAlpha(dragImage, alpha);
|
||||
}
|
||||
|
||||
/** Make all ghosted images go away. */
|
||||
public void dispose() {
|
||||
dragImage.dispose();
|
||||
dragImage = null;
|
||||
}
|
||||
|
||||
/** Move the ghosted image to the requested location.
|
||||
* @param screenLocation Where to draw the image, in screen coordinates
|
||||
*/
|
||||
public void move(Point screenLocation) {
|
||||
if (origin == null) {
|
||||
origin = screenLocation;
|
||||
}
|
||||
dragImage.setLocation(screenLocation.x, screenLocation.y);
|
||||
}
|
||||
|
||||
private static final int SLIDE_INTERVAL = 1000/30;
|
||||
/** Animate the ghosted image returning to its origin. */
|
||||
public void returnToOrigin() {
|
||||
final Timer timer = new Timer(SLIDE_INTERVAL, null);
|
||||
timer.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Point location = dragImage.getLocationOnScreen();
|
||||
Point dst = new Point(origin);
|
||||
int dx = (dst.x - location.x)/2;
|
||||
int dy = (dst.y - location.y)/2;
|
||||
if (dx != 0 || dy != 0) {
|
||||
location.translate(dx, dy);
|
||||
move(location);
|
||||
}
|
||||
else {
|
||||
timer.stop();
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
});
|
||||
timer.setInitialDelay(0);
|
||||
timer.start();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.mac;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.platform.FileUtils;
|
||||
|
||||
public class MacFileUtils extends FileUtils {
|
||||
|
||||
public boolean hasTrash() { return true; }
|
||||
|
||||
public void moveToTrash(File[] files) throws IOException {
|
||||
// TODO: use native API for moving to trash (if any)
|
||||
File home = new File(System.getProperty("user.home"));
|
||||
File trash = new File(home, ".Trash");
|
||||
if (!trash.exists()) {
|
||||
throw new IOException("The Trash was not found in its expected location (" + trash + ")");
|
||||
}
|
||||
List failed = new ArrayList();
|
||||
for (int i=0;i < files.length;i++) {
|
||||
File src = files[i];
|
||||
File target = new File(trash, src.getName());
|
||||
if (!src.renameTo(target)) {
|
||||
failed.add(src);
|
||||
}
|
||||
}
|
||||
if (failed.size() > 0) {
|
||||
throw new IOException("The following files could not be trashed: " + failed);
|
||||
}
|
||||
}
|
||||
}
|
||||
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -0,0 +1,623 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.platform.win32.WinNT.PSID;
|
||||
import com.sun.jna.platform.win32.WinNT.PSIDByReference;
|
||||
import com.sun.jna.platform.win32.WinNT.SECURITY_ATTRIBUTES;
|
||||
import com.sun.jna.platform.win32.WinReg.HKEY;
|
||||
import com.sun.jna.platform.win32.WinReg.HKEYByReference;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/**
|
||||
* Advapi32.dll Interface.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface Advapi32 extends W32API {
|
||||
Advapi32 INSTANCE = (Advapi32) Native.loadLibrary("Advapi32",
|
||||
Advapi32.class, W32APIOptions.UNICODE_OPTIONS);
|
||||
|
||||
/**
|
||||
* Retrieves the name of the user associated with the current thread.
|
||||
* http://msdn.microsoft.com/en-us/library/ms724432(VS.85).aspx
|
||||
*
|
||||
* @param buffer
|
||||
* Buffer to receive the user's logon name.
|
||||
* @param len
|
||||
* On input, the size of the buffer, on output the number of
|
||||
* characters copied into the buffer, including the terminating
|
||||
* null character.
|
||||
* @return
|
||||
* True if succeeded.
|
||||
*/
|
||||
public boolean GetUserNameW(char[] buffer, IntByReference len);
|
||||
|
||||
/**
|
||||
* Accepts the name of a system and anaccount as input and retrieves a security
|
||||
* identifier (SID) for the account and the name of the domain on which the
|
||||
* account was found.
|
||||
* http://msdn.microsoft.com/en-us/library/aa379159(VS.85).aspx
|
||||
*
|
||||
* @param lpSystemName
|
||||
* Specifies the name of the system.
|
||||
* @param lpAccountName
|
||||
* Specifies the account name.
|
||||
* @param Sid
|
||||
* Receives the SID structure that corresponds to the account
|
||||
* name pointed to by the lpAccountName parameter.
|
||||
* @param cbSid
|
||||
* On input, this value specifies the size, in bytes, of the Sid
|
||||
* buffer. If the function fails because the buffer is too small
|
||||
* or if cbSid is zero, this variable receives the required
|
||||
* buffer size.
|
||||
* @param ReferencedDomainName
|
||||
* Receives the name of the domain where the account name is found.
|
||||
* @param cchReferencedDomainName
|
||||
* On input, this value specifies the size, in TCHARs, of the
|
||||
* ReferencedDomainName buffer. If the function fails because the
|
||||
* buffer is too small, this variable receives the required
|
||||
* buffer size, including the terminating null character.
|
||||
* @param peUse
|
||||
* SID_NAME_USE enumerated type that indicates the type of the
|
||||
* account when the function returns.
|
||||
* @return
|
||||
* True if the function was successful, False otherwise.
|
||||
*/
|
||||
public boolean LookupAccountName(String lpSystemName,
|
||||
String lpAccountName, PSID Sid, IntByReference cbSid,
|
||||
char[] ReferencedDomainName,
|
||||
IntByReference cchReferencedDomainName, PointerByReference peUse);
|
||||
|
||||
/**
|
||||
* Retrieves the name of the account for this SID and the name of the first domain
|
||||
* on which this SID is found.
|
||||
*
|
||||
* @param lpSystemName Specifies the target computer.
|
||||
* @param Sid The SID to look up.
|
||||
* @param lpName
|
||||
* Buffer that receives a null-terminated string that contains the
|
||||
* account name that corresponds to the lpSid parameter.
|
||||
* @param cchName
|
||||
* On input, specifies the size, in TCHARs, of the lpName buffer. If the function fails
|
||||
* because the buffer is too small or if cchName is zero, cchName receives the required
|
||||
* buffer size, including the terminating null character.
|
||||
* @param ReferencedDomainName
|
||||
* Pointer to a buffer that receives a null-terminated string that contains the name of
|
||||
* the domain where the account name was found.
|
||||
* @param cchReferencedDomainName
|
||||
* On input, specifies the size, in TCHARs, of the lpReferencedDomainName buffer. If the
|
||||
* function fails because the buffer is too small or if cchReferencedDomainName is zero,
|
||||
* cchReferencedDomainName receives the required buffer size, including the terminating
|
||||
* null character.
|
||||
* @param peUse
|
||||
* Pointer to a variable that receives a SID_NAME_USE value that indicates the type of
|
||||
* the account.
|
||||
* @return
|
||||
* If the function succeeds, the function returns nonzero.
|
||||
* If the function fails, it returns zero. To get extended error information, call
|
||||
* GetLastError.
|
||||
*/
|
||||
public boolean LookupAccountSid(String lpSystemName, PSID Sid,
|
||||
char[] lpName, IntByReference cchName, char[] ReferencedDomainName,
|
||||
IntByReference cchReferencedDomainName, PointerByReference peUse);
|
||||
|
||||
/**
|
||||
* Convert a security identifier (SID) to a string format suitable for display,
|
||||
* storage, or transmission.
|
||||
* http://msdn.microsoft.com/en-us/library/aa376399(VS.85).aspx
|
||||
*
|
||||
* @param Sid
|
||||
* The SID structure to be converted.
|
||||
* @param StringSid
|
||||
* Pointer to a variable that receives a pointer to a
|
||||
* null-terminated SID string. To free the returned buffer, call
|
||||
* the LocalFree function.
|
||||
* @return True if the function was successful, False otherwise.
|
||||
*/
|
||||
public boolean ConvertSidToStringSid(PSID Sid,
|
||||
PointerByReference StringSid);
|
||||
|
||||
/**
|
||||
* Convert a string-format security identifier (SID) into a valid, functional SID.
|
||||
* http://msdn.microsoft.com/en-us/library/aa376402(VS.85).aspx
|
||||
*
|
||||
* @param StringSid The string-format SID to convert.
|
||||
* @param Sid Receives a pointer to the converted SID.
|
||||
* @return True if the function was successful, False otherwise.
|
||||
*/
|
||||
public boolean ConvertStringSidToSid(String StringSid,
|
||||
PSIDByReference Sid);
|
||||
|
||||
/**
|
||||
* Returns the length, in bytes, of a valid security identifier (SID).
|
||||
* http://msdn.microsoft.com/en-us/library/aa446642(VS.85).aspx
|
||||
*
|
||||
* @param pSid A pointer to the SID structure whose length is returned.
|
||||
* @return Length of the SID.
|
||||
*/
|
||||
public int GetLengthSid(PSID pSid);
|
||||
|
||||
/**
|
||||
* The IsValidSid function validates a security identifier (SID) by verifying that
|
||||
* the revision number is within a known range, and that the number of subauthorities
|
||||
* is less than the maximum.
|
||||
* @param pSid
|
||||
* Pointer to the SID structure to validate. This parameter cannot be NULL.
|
||||
* @return
|
||||
* If the SID structure is valid, the return value is nonzero.
|
||||
* If the SID structure is not valid, the return value is zero. There is no extended
|
||||
* error information for this function; do not call GetLastError.
|
||||
*/
|
||||
public boolean IsValidSid(PSID pSid);
|
||||
|
||||
/**
|
||||
* The LogonUser function attempts to log a user on to the local computer. The local computer is
|
||||
* the computer from which LogonUser was called. You cannot use LogonUser to log on to a remote
|
||||
* computer. You specify the user with a user name and domain, and authenticate the user with a
|
||||
* plaintext password. If the function succeeds, you receive a handle to a token that represents
|
||||
* the logged-on user. You can then use this token handle to impersonate the specified user or,
|
||||
* in most cases, to create a process that runs in the context of the specified user.
|
||||
* @param lpszUsername
|
||||
* A pointer to a null-terminated string that specifies the name of the user. This is the name of
|
||||
* the user account to log on to. If you use the user principal name (UPN) format,
|
||||
* user@DNS_domain_name, the lpszDomain parameter must be NULL.
|
||||
* @param lpszDomain
|
||||
* A pointer to a null-terminated string that specifies the name of the domain or server whose
|
||||
* account database contains the lpszUsername account. If this parameter is NULL, the user name
|
||||
* must be specified in UPN format. If this parameter is ".", the function validates the account
|
||||
* using only the local account database.
|
||||
* @param lpszPassword
|
||||
* A pointer to a null-terminated string that specifies the plaintext password for the user
|
||||
* account specified by lpszUsername.
|
||||
* @param logonType
|
||||
* The type of logon operation to perform.
|
||||
* @param logonProvider
|
||||
* Specifies the logon provider.
|
||||
* @param phToken
|
||||
* A pointer to a handle variable that receives a handle to a token that represents the specified user.
|
||||
* @return
|
||||
* If the function succeeds, the function returns nonzero.
|
||||
* If the function fails, it returns zero. To get extended error information, call GetLastError.
|
||||
*/
|
||||
public boolean LogonUser(
|
||||
String lpszUsername,
|
||||
String lpszDomain,
|
||||
String lpszPassword,
|
||||
int logonType,
|
||||
int logonProvider,
|
||||
HANDLEByReference phToken);
|
||||
|
||||
/**
|
||||
* The OpenThreadToken function opens the access token associated with a thread.
|
||||
* @param ThreadHandle
|
||||
* Handle to the thread whose access token is opened.
|
||||
* @param DesiredAccess
|
||||
* Specifies an access mask that specifies the requested types of access to the access token.
|
||||
* These requested access types are reconciled against the token's discretionary access
|
||||
* control list (DACL) to determine which accesses are granted or denied.
|
||||
* @param OpenAsSelf
|
||||
* Indicates whether the access check is to be made against the security context of the
|
||||
* thread calling the OpenThreadToken function or against the security context of the
|
||||
* process for the calling thread.
|
||||
* @param TokenHandle
|
||||
* Pointer to a variable that receives the handle to the newly opened access token.
|
||||
* @return
|
||||
* If the function succeeds, the return value is nonzero.
|
||||
* If the function fails, the return value is zero. To get extended error information,
|
||||
* call GetLastError.
|
||||
*/
|
||||
public boolean OpenThreadToken(
|
||||
HANDLE ThreadHandle,
|
||||
int DesiredAccess,
|
||||
boolean OpenAsSelf,
|
||||
HANDLEByReference TokenHandle);
|
||||
|
||||
/**
|
||||
* The OpenProcessToken function opens the access token associated with a process.
|
||||
* @param ProcessHandle
|
||||
* Handle to the process whose access token is opened. The process must have the
|
||||
* PROCESS_QUERY_INFORMATION access permission.
|
||||
* @param DesiredAccess
|
||||
* Specifies an access mask that specifies the requested types of access to the access
|
||||
* token. These requested access types are compared with the discretionary access
|
||||
* control list (DACL) of the token to determine which accesses are granted or denied.
|
||||
* @param TokenHandle
|
||||
* Pointer to a handle that identifies the newly opened access token when the function returns.
|
||||
* @return
|
||||
* If the function succeeds, the return value is nonzero.
|
||||
* If the function fails, the return value is zero. To get extended error information,
|
||||
* call GetLastError.
|
||||
*/
|
||||
public boolean OpenProcessToken(
|
||||
HANDLE ProcessHandle,
|
||||
int DesiredAccess,
|
||||
HANDLEByReference TokenHandle);
|
||||
|
||||
/**
|
||||
* The DuplicateToken function creates a new access token that duplicates
|
||||
* one already in existence.
|
||||
*
|
||||
* @param ExistingTokenHandle
|
||||
* Handle to an access token opened with TOKEN_DUPLICATE access.
|
||||
* @param ImpersonationLevel
|
||||
* Specifies a SECURITY_IMPERSONATION_LEVEL enumerated type that supplies
|
||||
* the impersonation level of the new token.
|
||||
* @param DuplicateTokenHandle
|
||||
* Pointer to a variable that receives a handle to the duplicate token.
|
||||
* This handle has TOKEN_IMPERSONATE and TOKEN_QUERY access to the new token.
|
||||
* @return
|
||||
* If the function succeeds, the return value is nonzero.
|
||||
* If the function fails, the return value is zero. To get extended error information,
|
||||
* call GetLastError.
|
||||
*/
|
||||
public boolean DuplicateToken(
|
||||
HANDLE ExistingTokenHandle,
|
||||
int ImpersonationLevel,
|
||||
HANDLEByReference DuplicateTokenHandle);
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves a specified type of information about an access token.
|
||||
* The calling process must have appropriate access rights to obtain the information.
|
||||
|
||||
* @param tokenHandle
|
||||
* Handle to an access token from which information is retrieved. If TokenInformationClass
|
||||
* specifies TokenSource, the handle must have TOKEN_QUERY_SOURCE access. For all other
|
||||
* TokenInformationClass values, the handle must have TOKEN_QUERY access.
|
||||
* @param tokenInformationClass
|
||||
* Specifies a value from the TOKEN_INFORMATION_CLASS enumerated type to identify the type of
|
||||
* information the function retrieves.
|
||||
* @param tokenInformation
|
||||
* Pointer to a buffer the function fills with the requested information. The structure put
|
||||
* into this buffer depends upon the type of information specified by the TokenInformationClass
|
||||
* parameter.
|
||||
* @param tokenInformationLength
|
||||
* Specifies the size, in bytes, of the buffer pointed to by the TokenInformation parameter.
|
||||
* If TokenInformation is NULL, this parameter must be zero.
|
||||
* @param returnLength
|
||||
* Pointer to a variable that receives the number of bytes needed for the buffer pointed to by
|
||||
* the TokenInformation parameter. If this value is larger than the value specified in the
|
||||
* TokenInformationLength parameter, the function fails and stores no data in the buffer.
|
||||
* @return
|
||||
* If the function succeeds, the return value is nonzero.
|
||||
* If the function fails, the return value is zero. To get extended error information, call GetLastError.
|
||||
*/
|
||||
public boolean GetTokenInformation(
|
||||
HANDLE tokenHandle,
|
||||
int tokenInformationClass,
|
||||
Structure tokenInformation,
|
||||
int tokenInformationLength,
|
||||
IntByReference returnLength);
|
||||
|
||||
/**
|
||||
* The ImpersonateLoggedOnUser function lets the calling thread impersonate the
|
||||
* security context of a logged-on user. The user is represented by a token
|
||||
* handle.
|
||||
* @param hToken
|
||||
* Handle to a primary or impersonation access token that represents a logged-on
|
||||
* user. This can be a token handle returned by a call to LogonUser,
|
||||
* CreateRestrictedToken, DuplicateToken, DuplicateTokenEx, OpenProcessToken,
|
||||
* or OpenThreadToken functions. If hToken is a primary token, it must have
|
||||
* TOKEN_QUERY and TOKEN_DUPLICATE access. If hToken is an impersonation token,
|
||||
* it must have TOKEN_QUERY and TOKEN_IMPERSONATE access.
|
||||
* @return
|
||||
* If the function succeeds, the return value is nonzero.
|
||||
*/
|
||||
public boolean ImpersonateLoggedOnUser(
|
||||
HANDLE hToken);
|
||||
|
||||
/**
|
||||
* The RevertToSelf function terminates the impersonation of a client application.
|
||||
* @return If the function succeeds, the return value is nonzero.
|
||||
*/
|
||||
public boolean RevertToSelf();
|
||||
|
||||
|
||||
/**
|
||||
* The RegOpenKeyEx function opens the specified registry key.
|
||||
* Note that key names are not case sensitive.
|
||||
* @param hKey
|
||||
* Handle to an open key.
|
||||
* @param lpSubKey
|
||||
* Pointer to a null-terminated string containing the name of the subkey to open.
|
||||
* @param ulOptions
|
||||
* Reserved; must be zero.
|
||||
* @param samDesired
|
||||
* Access mask that specifies the desired access rights to the key. The function
|
||||
* fails if the security descriptor of the key does not permit the requested access
|
||||
* for the calling process.
|
||||
* @param phkResult
|
||||
* Pointer to a variable that receives a handle to the opened key. If the key is
|
||||
* not one of the predefined registry keys, call the RegCloseKey function after
|
||||
* you have finished using the handle.
|
||||
* @return
|
||||
* If the function succeeds, the return value is ERROR_SUCCESS.
|
||||
* If the function fails, the return value is a nonzero error code defined in Winerror.h.
|
||||
*/
|
||||
public int RegOpenKeyEx(HKEY hKey, String lpSubKey, int ulOptions, int samDesired,
|
||||
HKEYByReference phkResult);
|
||||
|
||||
/**
|
||||
* The RegQueryValueEx function retrieves the type and data for a specified value name
|
||||
* associated with an open registry key.
|
||||
* @param hKey
|
||||
* Handle to an open key. The key must have been opened with the
|
||||
* KEY_QUERY_VALUE access right.
|
||||
* @param lpValueName
|
||||
* Pointer to a null-terminated string containing the name of the value to query.
|
||||
* If lpValueName is NULL or an empty string, "", the function retrieves the type
|
||||
* and data for the key's unnamed or default value, if any.
|
||||
* @param lpReserved
|
||||
* Reserved; must be NULL.
|
||||
* @param lpType
|
||||
* Pointer to a variable that receives a code indicating the type of data stored
|
||||
* in the specified value.
|
||||
* @param lpData
|
||||
* Pointer to a buffer that receives the value's data. This parameter can be NULL
|
||||
* if the data is not required. If the data is a string, the function checks for
|
||||
* a terminating null character. If one is not found, the string is stored with a
|
||||
* null terminator if the buffer is large enough to accommodate the extra
|
||||
* character. Otherwise, the string is stored as is.
|
||||
* @param lpcbData
|
||||
* Pointer to a variable that specifies the size of the buffer pointed to by the
|
||||
* lpData parameter, in bytes. When the function returns, this variable contains
|
||||
* the size of the data copied to lpData. The lpcbData parameter can be NULL only
|
||||
* if lpData is NULL. If the data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ
|
||||
* type, this size includes any terminating null character or characters.
|
||||
* If the buffer specified by lpData parameter is not large enough to hold the
|
||||
* data, the function returns ERROR_MORE_DATA and stores the required buffer size
|
||||
* in the variable pointed to by lpcbData. In this case, the contents of the lpData
|
||||
* buffer are undefined. If lpData is NULL, and lpcbData is non-NULL, the function
|
||||
* returns ERROR_SUCCESS and stores the size of the data, in bytes, in the variable
|
||||
* pointed to by lpcbData. This enables an application to determine the best way
|
||||
* to allocate a buffer for the value's data.
|
||||
* @return
|
||||
* If the function succeeds, the return value is ERROR_SUCCESS.
|
||||
* If the function fails, the return value is a nonzero error code defined in Winerror.h.
|
||||
*/
|
||||
public int RegQueryValueEx(HKEY hKey, String lpValueName, int lpReserved,
|
||||
IntByReference lpType, char[] lpData, IntByReference lpcbData);
|
||||
|
||||
public int RegQueryValueEx(HKEY hKey, String lpValueName, int lpReserved,
|
||||
IntByReference lpType, byte[] lpData, IntByReference lpcbData);
|
||||
|
||||
public int RegQueryValueEx(HKEY hKey, String lpValueName, int lpReserved,
|
||||
IntByReference lpType, IntByReference lpData, IntByReference lpcbData);
|
||||
|
||||
/**
|
||||
* The RegCloseKey function releases a handle to the specified registry key.
|
||||
* @param hKey
|
||||
* Handle to the open key to be closed. The handle must have been opened by the
|
||||
* RegCreateKeyEx, RegOpenKeyEx, or RegConnectRegistry function.
|
||||
* @return
|
||||
* If the function succeeds, the return value is ERROR_SUCCESS. If the function
|
||||
* fails, the return value is a nonzero error code defined in Winerror.h.
|
||||
*/
|
||||
public int RegCloseKey(HKEY hKey);
|
||||
|
||||
/**
|
||||
* The RegDeleteValue function removes a named value from the specified registry
|
||||
* key. Note that value names are not case sensitive.
|
||||
* @param hKey
|
||||
* Handle to an open key. The key must have been opened with the KEY_SET_VALUE
|
||||
* access right.
|
||||
* @param lpValueName
|
||||
* Pointer to a null-terminated string that names the value to remove. If this
|
||||
* parameter is NULL or an empty string, the value set by the RegSetValue function
|
||||
* is removed.
|
||||
* @return
|
||||
* If the function succeeds, the return value is ERROR_SUCCESS. If the function
|
||||
* fails, the return value is a nonzero error code defined in Winerror.h.
|
||||
*/
|
||||
public int RegDeleteValue(HKEY hKey, String lpValueName);
|
||||
|
||||
/**
|
||||
* The RegSetValueEx function sets the data and type of a specified value under a
|
||||
* registry key.
|
||||
* @param hKey
|
||||
* Handle to an open key. The key must have been opened with the KEY_SET_VALUE
|
||||
* access right.
|
||||
* @param lpValueName
|
||||
* Pointer to a string containing the name of the value to set. If a value with
|
||||
* this name is not already present in the key, the function adds it to the key.
|
||||
* If lpValueName is NULL or an empty string, "", the function sets the type and
|
||||
* data for the key's unnamed or default value.
|
||||
* @param Reserved
|
||||
* Reserved; must be zero.
|
||||
* @param dwType
|
||||
* Type of data pointed to by the lpData parameter.
|
||||
* @param lpData
|
||||
* Pointer to a buffer containing the data to be stored with the specified value name.
|
||||
* @param cbData
|
||||
* Size of the information pointed to by the lpData parameter, in bytes. If the data
|
||||
* is of type REG_SZ, REG_EXPAND_SZ, or REG_MULTI_SZ, cbData must include the size of
|
||||
* the terminating null character or characters.
|
||||
* @return
|
||||
* If the function succeeds, the return value is ERROR_SUCCESS. If the function
|
||||
* fails, the return value is a nonzero error code defined in Winerror.h.
|
||||
*/
|
||||
public int RegSetValueEx(HKEY hKey, String lpValueName, int Reserved, int dwType,
|
||||
char[] lpData, int cbData);
|
||||
|
||||
public int RegSetValueEx(HKEY hKey, String lpValueName, int Reserved, int dwType,
|
||||
byte[] lpData, int cbData);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param hKey
|
||||
* @param lpSubKey
|
||||
* @param Reserved
|
||||
* @param lpClass
|
||||
* @param dwOptions
|
||||
* @param samDesired
|
||||
* @param lpSecurityAttributes
|
||||
* @param phkResult
|
||||
* @param lpdwDisposition
|
||||
* @return
|
||||
* If the function succeeds, the return value is ERROR_SUCCESS. If the function
|
||||
* fails, the return value is a nonzero error code defined in Winerror.h.
|
||||
*/
|
||||
public int RegCreateKeyEx(HKEY hKey, String lpSubKey, int Reserved, String lpClass,
|
||||
int dwOptions, int samDesired, SECURITY_ATTRIBUTES lpSecurityAttributes,
|
||||
HKEYByReference phkResult, IntByReference lpdwDisposition);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param hKey
|
||||
* @param name
|
||||
* @return
|
||||
* If the function succeeds, the return value is ERROR_SUCCESS. If the function
|
||||
* fails, the return value is a nonzero error code defined in Winerror.h.
|
||||
*/
|
||||
public int RegDeleteKey(HKEY hKey, String name);
|
||||
|
||||
/**
|
||||
* The RegEnumKeyEx function enumerates subkeys of the specified open registry key.
|
||||
* The function retrieves information about one subkey each time it is called.
|
||||
* @param hKey
|
||||
* Handle to an open key. The key must have been opened with the
|
||||
* KEY_ENUMERATE_SUB_KEYS access right.
|
||||
* @param dwIndex
|
||||
* Index of the subkey to retrieve. This parameter should be zero for the first
|
||||
* call to the RegEnumKeyEx function and then incremented for subsequent calls.
|
||||
* Because subkeys are not ordered, any new subkey will have an arbitrary index.
|
||||
* This means that the function may return subkeys in any order.
|
||||
* @param lpName
|
||||
* Pointer to a buffer that receives the name of the subkey, including the
|
||||
* terminating null character. The function copies only the name of the subkey,
|
||||
* not the full key hierarchy, to the buffer.
|
||||
* @param lpcName
|
||||
* Pointer to a variable that specifies the size of the buffer specified by the
|
||||
* lpName parameter, in TCHARs. This size should include the terminating null
|
||||
* character. When the function returns, the variable pointed to by lpcName
|
||||
* contains the number of characters stored in the buffer. The count returned
|
||||
* does not include the terminating null character.
|
||||
* @param reserved
|
||||
* Reserved; must be NULL.
|
||||
* @param lpClass
|
||||
* Pointer to a buffer that receives the null-terminated class string of the
|
||||
* enumerated subkey. This parameter can be NULL.
|
||||
* @param lpcClass
|
||||
* Pointer to a variable that specifies the size of the buffer specified by the
|
||||
* lpClass parameter, in TCHARs. The size should include the terminating null
|
||||
* character. When the function returns, lpcClass contains the number of
|
||||
* characters stored in the buffer. The count returned does not include the
|
||||
* terminating null character. This parameter can be NULL only if lpClass is NULL.
|
||||
* @param lpftLastWriteTime
|
||||
* Pointer to a variable that receives the time at which the enumerated subkey
|
||||
* was last written.
|
||||
* @return
|
||||
* If the function succeeds, the return value is ERROR_SUCCESS. If the function
|
||||
* fails, the return value is a nonzero error code defined in Winerror.h.
|
||||
*/
|
||||
public int RegEnumKeyEx(HKEY hKey, int dwIndex, char[] lpName, IntByReference lpcName,
|
||||
IntByReference reserved, char[] lpClass, IntByReference lpcClass,
|
||||
WinBase.FILETIME lpftLastWriteTime);
|
||||
|
||||
/**
|
||||
* The RegEnumValue function enumerates the values for the specified open registry
|
||||
* key. The function copies one indexed value name and data block for the key each
|
||||
* time it is called.
|
||||
* @param hKey
|
||||
* Handle to an open key. The key must have been opened with the KEY_QUERY_VALUE
|
||||
* access right.
|
||||
* @param dwIndex
|
||||
* Index of the value to be retrieved. This parameter should be zero for the first
|
||||
* call to the RegEnumValue function and then be incremented for subsequent calls.
|
||||
* Because values are not ordered, any new value will have an arbitrary index.
|
||||
* This means that the function may return values in any order.
|
||||
* @param lpValueName
|
||||
* Pointer to a buffer that receives the name of the value, including the
|
||||
* terminating null character.
|
||||
* @param lpcchValueName
|
||||
* Pointer to a variable that specifies the size of the buffer pointed to by the
|
||||
* lpValueName parameter, in TCHARs. This size should include the terminating null
|
||||
* character. When the function returns, the variable pointed to by lpcValueName
|
||||
* contains the number of characters stored in the buffer. The count returned
|
||||
* does not include the terminating null character.
|
||||
* @param reserved
|
||||
* Reserved; must be NULL.
|
||||
* @param lpType
|
||||
* Pointer to a variable that receives a code indicating the type of data stored
|
||||
* in the specified value.
|
||||
* @param lpData
|
||||
* Pointer to a buffer that receives the data for the value entry. This parameter
|
||||
* can be NULL if the data is not required.
|
||||
* @param lpcbData
|
||||
* Pointer to a variable that specifies the size of the buffer pointed to by the
|
||||
* lpData parameter, in bytes.
|
||||
* @return
|
||||
* If the function succeeds, the return value is ERROR_SUCCESS. If the function
|
||||
* fails, the return value is a nonzero error code defined in Winerror.h.
|
||||
*/
|
||||
public int RegEnumValue(HKEY hKey, int dwIndex, char[] lpValueName,
|
||||
IntByReference lpcchValueName, IntByReference reserved,
|
||||
IntByReference lpType, byte[] lpData, IntByReference lpcbData);
|
||||
|
||||
/**
|
||||
* The RegQueryInfoKey function retrieves information about the specified
|
||||
* registry key.
|
||||
* @param hKey
|
||||
* A handle to an open key. The key must have been opened with the
|
||||
* KEY_QUERY_VALUE access right.
|
||||
* @param lpClass
|
||||
* A pointer to a buffer that receives the null-terminated class
|
||||
* string of the key. This parameter can be ignored. This parameter can be NULL.
|
||||
* @param lpcClass
|
||||
* A pointer to a variable that specifies the size of the buffer pointed to by
|
||||
* the lpClass parameter, in characters.
|
||||
* @param lpReserved
|
||||
* Reserved; must be NULL.
|
||||
* @param lpcSubKeys
|
||||
* A pointer to a variable that receives the number of subkeys that are contained by the specified key.
|
||||
* This parameter can be NULL.
|
||||
* @param lpcMaxSubKeyLen
|
||||
* A pointer to a variable that receives the size of the key's subkey with the
|
||||
* longest name, in characters, not including the terminating null character.
|
||||
* This parameter can be NULL.
|
||||
* @param lpcMaxClassLen
|
||||
* A pointer to a variable that receives the size of the longest string that
|
||||
* specifies a subkey class, in characters. The count returned does not include
|
||||
* the terminating null character. This parameter can be NULL.
|
||||
* @param lpcValues
|
||||
* A pointer to a variable that receives the number of values that are associated
|
||||
* with the key. This parameter can be NULL.
|
||||
* @param lpcMaxValueNameLen
|
||||
* A pointer to a variable that receives the size of the key's longest value name,
|
||||
* in characters. The size does not include the terminating null character. This
|
||||
* parameter can be NULL.
|
||||
* @param lpcMaxValueLen
|
||||
* A pointer to a variable that receives the size of the longest data component
|
||||
* among the key's values, in bytes. This parameter can be NULL.
|
||||
* @param lpcbSecurityDescriptor
|
||||
* A pointer to a variable that receives the size of the key's security descriptor,
|
||||
* in bytes. This parameter can be NULL.
|
||||
* @param lpftLastWriteTime
|
||||
* A pointer to a FILETIME structure that receives the last write time.
|
||||
* This parameter can be NULL.
|
||||
* @return
|
||||
* If the function succeeds, the return value is ERROR_SUCCESS. If the function
|
||||
* fails, the return value is a nonzero error code defined in Winerror.h.
|
||||
*/
|
||||
public int RegQueryInfoKey(HKEY hKey, char[] lpClass,
|
||||
IntByReference lpcClass, IntByReference lpReserved,
|
||||
IntByReference lpcSubKeys, IntByReference lpcMaxSubKeyLen,
|
||||
IntByReference lpcMaxClassLen, IntByReference lpcValues,
|
||||
IntByReference lpcMaxValueNameLen, IntByReference lpcMaxValueLen,
|
||||
IntByReference lpcbSecurityDescriptor,
|
||||
WinBase.FILETIME lpftLastWriteTime);
|
||||
}
|
||||
@@ -0,0 +1,880 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import com.sun.jna.Memory;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.platform.win32.W32API.HANDLE;
|
||||
import com.sun.jna.platform.win32.W32API.HANDLEByReference;
|
||||
import com.sun.jna.platform.win32.WinNT.PSID;
|
||||
import com.sun.jna.platform.win32.WinNT.PSIDByReference;
|
||||
import com.sun.jna.platform.win32.WinNT.SID_AND_ATTRIBUTES;
|
||||
import com.sun.jna.platform.win32.WinReg.HKEY;
|
||||
import com.sun.jna.platform.win32.WinReg.HKEYByReference;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
|
||||
/**
|
||||
* Advapi32 utility API.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public abstract class Advapi32Util {
|
||||
|
||||
/**
|
||||
* A group.
|
||||
*/
|
||||
public static class Group {
|
||||
/**
|
||||
* Group name. When unavailable, always equals to sidString.
|
||||
*/
|
||||
public String name;
|
||||
/**
|
||||
* String representation of the group SID.
|
||||
*/
|
||||
public String sidString;
|
||||
/**
|
||||
* Binary representation of the group SID.
|
||||
*/
|
||||
public byte[] sid;
|
||||
}
|
||||
|
||||
/**
|
||||
* An account.
|
||||
*/
|
||||
public static class Account {
|
||||
/**
|
||||
* Account name.
|
||||
*/
|
||||
public String name;
|
||||
/**
|
||||
* Account domain.
|
||||
*/
|
||||
public String domain;
|
||||
/**
|
||||
* Account SID.
|
||||
*/
|
||||
public byte[] sid;
|
||||
/**
|
||||
* String representation of the account SID.
|
||||
*/
|
||||
public String sidString;
|
||||
/**
|
||||
* Account type, one of SID_NAME_USE.
|
||||
*/
|
||||
public int accountType;
|
||||
/**
|
||||
* Fully qualified account name.
|
||||
*/
|
||||
public String fqn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the name of the user associated with the current thread.
|
||||
* @return A user name.
|
||||
*/
|
||||
public static String getUserName() {
|
||||
char[] buffer = new char[128];
|
||||
IntByReference len = new IntByReference(buffer.length);
|
||||
boolean result = Advapi32.INSTANCE.GetUserNameW(buffer, len);
|
||||
|
||||
if (! result) {
|
||||
|
||||
int rc = Kernel32.INSTANCE.GetLastError();
|
||||
|
||||
switch(rc) {
|
||||
case W32Errors.ERROR_INSUFFICIENT_BUFFER:
|
||||
buffer = new char[len.getValue()];
|
||||
break;
|
||||
default:
|
||||
throw new Win32Exception(Native.getLastError());
|
||||
}
|
||||
|
||||
result = Advapi32.INSTANCE.GetUserNameW(buffer, len);
|
||||
}
|
||||
|
||||
if (! result) {
|
||||
throw new Win32Exception(Native.getLastError());
|
||||
}
|
||||
|
||||
return Native.toString(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a security identifier (SID) for the account on the current system.
|
||||
* @param accountName Specifies the account name.
|
||||
* @return A structure containing the account SID;
|
||||
*/
|
||||
public static Account getAccountByName(String accountName) {
|
||||
return getAccountByName(null, accountName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a security identifier (SID) for a given account.
|
||||
* @param systemName Name of the system.
|
||||
* @param accountName Account name.
|
||||
* @return A structure containing the account SID.
|
||||
*/
|
||||
public static Account getAccountByName(String systemName, String accountName) {
|
||||
IntByReference pSid = new IntByReference(0);
|
||||
IntByReference cchDomainName = new IntByReference(0);
|
||||
PointerByReference peUse = new PointerByReference();
|
||||
|
||||
if (Advapi32.INSTANCE.LookupAccountName(systemName, accountName, null, pSid, null, cchDomainName, peUse)) {
|
||||
throw new RuntimeException("LookupAccountNameW was expected to fail with ERROR_INSUFFICIENT_BUFFER");
|
||||
}
|
||||
|
||||
int rc = Kernel32.INSTANCE.GetLastError();
|
||||
if (pSid.getValue() == 0 || rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
|
||||
Memory sidMemory = new Memory(pSid.getValue());
|
||||
PSID result = new PSID(sidMemory);
|
||||
char[] referencedDomainName = new char[cchDomainName.getValue() + 1];
|
||||
|
||||
if (! Advapi32.INSTANCE.LookupAccountName(systemName, accountName, result, pSid, referencedDomainName, cchDomainName, peUse)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
|
||||
Account account = new Account();
|
||||
account.accountType = peUse.getPointer().getInt(0);
|
||||
account.name = accountName;
|
||||
|
||||
String[] accountNamePartsBs = accountName.split("\\\\", 2);
|
||||
String[] accountNamePartsAt = accountName.split("@", 2);
|
||||
|
||||
if (accountNamePartsBs.length == 2) {
|
||||
account.name = accountNamePartsBs[1];
|
||||
} else if (accountNamePartsAt.length == 2) {
|
||||
account.name = accountNamePartsAt[0];
|
||||
} else {
|
||||
account.name = accountName;
|
||||
}
|
||||
|
||||
if (cchDomainName.getValue() > 0) {
|
||||
account.domain = Native.toString(referencedDomainName);
|
||||
account.fqn = account.domain + "\\" + account.name;
|
||||
} else {
|
||||
account.fqn = account.name;
|
||||
}
|
||||
|
||||
account.sid = result.getBytes();
|
||||
account.sidString = convertSidToStringSid(new PSID(account.sid));
|
||||
return account;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the account by SID on the local system.
|
||||
*
|
||||
* @param sid SID.
|
||||
* @return Account.
|
||||
*/
|
||||
public static Account getAccountBySid(PSID sid) {
|
||||
return getAccountBySid(null, sid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the account by SID.
|
||||
*
|
||||
* @param systemName Name of the system.
|
||||
* @param sid SID.
|
||||
* @return Account.
|
||||
*/
|
||||
public static Account getAccountBySid(String systemName, PSID sid) {
|
||||
IntByReference cchName = new IntByReference();
|
||||
IntByReference cchDomainName = new IntByReference();
|
||||
PointerByReference peUse = new PointerByReference();
|
||||
|
||||
if (Advapi32.INSTANCE.LookupAccountSid(null, sid,
|
||||
null, cchName, null, cchDomainName, peUse)) {
|
||||
throw new RuntimeException("LookupAccountSidW was expected to fail with ERROR_INSUFFICIENT_BUFFER");
|
||||
}
|
||||
|
||||
int rc = Kernel32.INSTANCE.GetLastError();
|
||||
if (cchName.getValue() == 0 || rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
|
||||
char[] domainName = new char[cchDomainName.getValue()];
|
||||
char[] name = new char[cchName.getValue()];
|
||||
|
||||
if (! Advapi32.INSTANCE.LookupAccountSid(null, sid,
|
||||
name, cchName, domainName, cchDomainName, peUse)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
|
||||
Account account = new Account();
|
||||
account.accountType = peUse.getPointer().getInt(0);
|
||||
account.name = Native.toString(name);
|
||||
|
||||
if (cchDomainName.getValue() > 0) {
|
||||
account.domain = Native.toString(domainName);
|
||||
account.fqn = account.domain + "\\" + account.name;
|
||||
} else {
|
||||
account.fqn = account.name;
|
||||
}
|
||||
|
||||
account.sid = sid.getBytes();
|
||||
account.sidString = convertSidToStringSid(sid);
|
||||
return account;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a security identifier (SID) to a string format suitable for display,
|
||||
* storage, or transmission.
|
||||
* @param sid SID bytes.
|
||||
* @return String SID.
|
||||
*/
|
||||
public static String convertSidToStringSid(PSID sid) {
|
||||
PointerByReference stringSid = new PointerByReference();
|
||||
if (! Advapi32.INSTANCE.ConvertSidToStringSid(sid, stringSid)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
String result = stringSid.getValue().getString(0, true);
|
||||
Kernel32.INSTANCE.LocalFree(stringSid.getValue());
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string representation of a security identifier (SID) to
|
||||
* a binary format.
|
||||
* @param sid String SID.
|
||||
* @return SID bytes.
|
||||
*/
|
||||
public static byte[] convertStringSidToSid(String sid) {
|
||||
PSIDByReference pSID = new PSIDByReference();
|
||||
if (! Advapi32.INSTANCE.ConvertStringSidToSid(sid, pSID)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
return pSID.getValue().getBytes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an account name from a string SID on the local machine.
|
||||
*
|
||||
* @param sidString SID.
|
||||
* @return Account.
|
||||
*/
|
||||
public static Account getAccountBySid(String sidString) {
|
||||
return getAccountBySid(null, sidString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an account name from a string SID.
|
||||
*
|
||||
* @param systemName System name.
|
||||
* @param sidString SID.
|
||||
* @return Account.
|
||||
*/
|
||||
public static Account getAccountBySid(String systemName, String sidString) {
|
||||
return getAccountBySid(systemName, new PSID(convertStringSidToSid(sidString)));
|
||||
}
|
||||
|
||||
/**
|
||||
* This function returns the groups associated with a security token,
|
||||
* such as a user token.
|
||||
*
|
||||
* @param hToken Token.
|
||||
* @return Token groups.
|
||||
*/
|
||||
public static Group[] getTokenGroups(HANDLE hToken) {
|
||||
// get token group information size
|
||||
IntByReference tokenInformationLength = new IntByReference();
|
||||
if (Advapi32.INSTANCE.GetTokenInformation(hToken,
|
||||
WinNT.TOKEN_INFORMATION_CLASS.TokenGroups, null, 0, tokenInformationLength)
|
||||
|| Kernel32.INSTANCE.GetLastError() != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
|
||||
throw new RuntimeException("Expected GetTokenInformation to fail with ERROR_INSUFFICIENT_BUFFER");
|
||||
}
|
||||
// get token group information
|
||||
Memory tokenInformationBuffer = new Memory(tokenInformationLength.getValue());
|
||||
WinNT.TOKEN_GROUPS groups = new WinNT.TOKEN_GROUPS(tokenInformationBuffer);
|
||||
if (! Advapi32.INSTANCE.GetTokenInformation(hToken,
|
||||
WinNT.TOKEN_INFORMATION_CLASS.TokenGroups, groups,
|
||||
tokenInformationLength.getValue(), tokenInformationLength)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
ArrayList<Group> userGroups = new ArrayList<Group>();
|
||||
// make array of names
|
||||
for (SID_AND_ATTRIBUTES sidAndAttribute : groups.getGroups()) {
|
||||
Group group = new Group();
|
||||
group.sid = sidAndAttribute.Sid.getBytes();
|
||||
group.sidString = Advapi32Util.convertSidToStringSid(sidAndAttribute.Sid);
|
||||
try {
|
||||
group.name = Advapi32Util.getAccountBySid(sidAndAttribute.Sid).name;
|
||||
} catch(Exception e) {
|
||||
group.name = group.sidString;
|
||||
}
|
||||
userGroups.add(group);
|
||||
}
|
||||
return userGroups.toArray(new Group[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function returns the information about the user who owns a security token,
|
||||
*
|
||||
* @param hToken Token.
|
||||
* @return Token user.
|
||||
*/
|
||||
public static Account getTokenAccount(HANDLE hToken) {
|
||||
// get token group information size
|
||||
IntByReference tokenInformationLength = new IntByReference();
|
||||
if (Advapi32.INSTANCE.GetTokenInformation(hToken,
|
||||
WinNT.TOKEN_INFORMATION_CLASS.TokenUser, null, 0, tokenInformationLength)
|
||||
|| Kernel32.INSTANCE.GetLastError() != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
|
||||
throw new RuntimeException("Expected GetTokenInformation to fail with ERROR_INSUFFICIENT_BUFFER");
|
||||
}
|
||||
// get token user information
|
||||
Memory tokenInformationBuffer = new Memory(tokenInformationLength.getValue());
|
||||
WinNT.TOKEN_USER user = new WinNT.TOKEN_USER(tokenInformationBuffer);
|
||||
if (! Advapi32.INSTANCE.GetTokenInformation(hToken,
|
||||
WinNT.TOKEN_INFORMATION_CLASS.TokenUser, user,
|
||||
tokenInformationLength.getValue(), tokenInformationLength)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
return getAccountBySid(user.User.Sid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the group memberships of the currently logged on user.
|
||||
* @return An array of groups.
|
||||
*/
|
||||
public static Group[] getCurrentUserGroups() {
|
||||
HANDLEByReference phToken = new HANDLEByReference();
|
||||
try {
|
||||
// open thread or process token
|
||||
HANDLE threadHandle = Kernel32.INSTANCE.GetCurrentThread();
|
||||
if (! Advapi32.INSTANCE.OpenThreadToken(threadHandle,
|
||||
WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, true, phToken)) {
|
||||
if (W32Errors.ERROR_NO_TOKEN != Kernel32.INSTANCE.GetLastError()) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
HANDLE processHandle = Kernel32.INSTANCE.GetCurrentProcess();
|
||||
if (! Advapi32.INSTANCE.OpenProcessToken(processHandle,
|
||||
WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, phToken)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
}
|
||||
return getTokenGroups(phToken.getValue());
|
||||
} finally {
|
||||
if (phToken.getValue() != Kernel32.INVALID_HANDLE_VALUE) {
|
||||
if (! Kernel32.INSTANCE.CloseHandle(phToken.getValue())) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a registry key exists.
|
||||
* @param root
|
||||
* HKEY_LOCAL_MACHINE, etc.
|
||||
* @param key
|
||||
* Path to the registry key.
|
||||
* @return
|
||||
* True if the key exists.
|
||||
*/
|
||||
public static boolean registryKeyExists(HKEY root, String key) {
|
||||
HKEYByReference phkKey = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ, phkKey);
|
||||
switch(rc) {
|
||||
case W32Errors.ERROR_SUCCESS:
|
||||
Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
|
||||
return true;
|
||||
case W32Errors.ERROR_FILE_NOT_FOUND:
|
||||
return false;
|
||||
default:
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a registry value exists.
|
||||
* @param root
|
||||
* HKEY_LOCAL_MACHINE, etc.
|
||||
* @param key
|
||||
* Registry key path.
|
||||
* @param value
|
||||
* Value name.
|
||||
* @return
|
||||
* True if the value exists.
|
||||
*/
|
||||
public static boolean registryValueExists(HKEY root, String key, String value) {
|
||||
HKEYByReference phkKey = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ, phkKey);
|
||||
try {
|
||||
switch(rc) {
|
||||
case W32Errors.ERROR_SUCCESS:
|
||||
break;
|
||||
case W32Errors.ERROR_FILE_NOT_FOUND:
|
||||
return false;
|
||||
default:
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
IntByReference lpcbData = new IntByReference();
|
||||
IntByReference lpType = new IntByReference();
|
||||
rc = Advapi32.INSTANCE.RegQueryValueEx(
|
||||
phkKey.getValue(), value, 0, lpType, (char[]) null, lpcbData);
|
||||
switch(rc) {
|
||||
case W32Errors.ERROR_SUCCESS:
|
||||
case W32Errors.ERROR_INSUFFICIENT_BUFFER:
|
||||
return true;
|
||||
case W32Errors.ERROR_FILE_NOT_FOUND:
|
||||
return false;
|
||||
default:
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
} finally {
|
||||
if (phkKey.getValue() != Kernel32.INVALID_HANDLE_VALUE) {
|
||||
rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a registry REG_SZ value.
|
||||
* @param root
|
||||
* Root key.
|
||||
* @param key
|
||||
* Registry path.
|
||||
* @param value
|
||||
* Name of the value to retrieve.
|
||||
* @return
|
||||
* String value.
|
||||
*/
|
||||
public static String registryGetStringValue(HKEY root, String key, String value) {
|
||||
HKEYByReference phkKey = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ, phkKey);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
try {
|
||||
IntByReference lpcbData = new IntByReference();
|
||||
IntByReference lpType = new IntByReference();
|
||||
rc = Advapi32.INSTANCE.RegQueryValueEx(
|
||||
phkKey.getValue(), value, 0, lpType, (char[]) null, lpcbData);
|
||||
if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
if (lpType.getValue() != WinNT.REG_SZ) {
|
||||
throw new RuntimeException("Unexpected registry type " + lpType.getValue() + ", expected REG_SZ");
|
||||
}
|
||||
char[] data = new char[lpcbData.getValue()];
|
||||
rc = Advapi32.INSTANCE.RegQueryValueEx(
|
||||
phkKey.getValue(), value, 0, lpType, data, lpcbData);
|
||||
if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
return Native.toString(data);
|
||||
} finally {
|
||||
rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a registry DWORD value.
|
||||
* @param root
|
||||
* Root key.
|
||||
* @param key
|
||||
* Registry key path.
|
||||
* @param value
|
||||
* Name of the value to retrieve.
|
||||
* @return
|
||||
* Integer value.
|
||||
*/
|
||||
public static int registryGetIntValue(HKEY root, String key, String value) {
|
||||
HKEYByReference phkKey = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ, phkKey);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
try {
|
||||
IntByReference lpcbData = new IntByReference();
|
||||
IntByReference lpType = new IntByReference();
|
||||
rc = Advapi32.INSTANCE.RegQueryValueEx(
|
||||
phkKey.getValue(), value, 0, lpType, (char[]) null, lpcbData);
|
||||
if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
if (lpType.getValue() != WinNT.REG_DWORD) {
|
||||
throw new RuntimeException("Unexpected registry type " + lpType.getValue() + ", expected REG_SZ");
|
||||
}
|
||||
IntByReference data = new IntByReference();
|
||||
rc = Advapi32.INSTANCE.RegQueryValueEx(
|
||||
phkKey.getValue(), value, 0, lpType, data, lpcbData);
|
||||
if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
return data.getValue();
|
||||
} finally {
|
||||
rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a registry key.
|
||||
* @param hKey
|
||||
* Parent key.
|
||||
* @param keyName
|
||||
* Key name.
|
||||
*/
|
||||
public static void registryCreateKey(HKEY hKey, String keyName) {
|
||||
HKEYByReference phkResult = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegCreateKeyEx(hKey, keyName, 0, null, 0,
|
||||
WinNT.KEY_READ, null, phkResult, null);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
rc = Advapi32.INSTANCE.RegCloseKey(phkResult.getValue());
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a registry key.
|
||||
* @param root
|
||||
* Root key.
|
||||
* @param parentPath
|
||||
* Path to an existing registry key.
|
||||
* @param keyName
|
||||
* Key name.
|
||||
*/
|
||||
public static void registryCreateKey(HKEY root, String parentPath, String keyName) {
|
||||
HKEYByReference phkKey = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, parentPath, 0, WinNT.KEY_CREATE_SUB_KEY, phkKey);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
try {
|
||||
registryCreateKey(phkKey.getValue(), keyName);
|
||||
} finally {
|
||||
rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an integer value in registry.
|
||||
* @param hKey
|
||||
* Parent key.
|
||||
* @param name
|
||||
* Name.
|
||||
* @param value
|
||||
* Value.
|
||||
*/
|
||||
public static void registrySetIntValue(HKEY hKey, String name, int value) {
|
||||
byte[] data = new byte[4];
|
||||
data[0] = (byte)(value & 0xff);
|
||||
data[1] = (byte)((value >> 8) & 0xff);
|
||||
data[2] = (byte)((value >> 16) & 0xff);
|
||||
data[3] = (byte)((value >> 24) & 0xff);
|
||||
int rc = Advapi32.INSTANCE.RegSetValueEx(hKey, name, 0, WinNT.REG_DWORD, data, 4);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an integer value in registry.
|
||||
* @param root
|
||||
* Root key.
|
||||
* @param keyPath
|
||||
* Path to an existing registry key.
|
||||
* @param name
|
||||
* Name.
|
||||
* @param value
|
||||
* Value.
|
||||
*/
|
||||
public static void registrySetIntValue(HKEY root, String keyPath, String name, int value) {
|
||||
HKEYByReference phkKey = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ | WinNT.KEY_WRITE, phkKey);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
try {
|
||||
registrySetIntValue(phkKey.getValue(), name, value);
|
||||
} finally {
|
||||
rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a string value in registry.
|
||||
* @param hKey
|
||||
* Parent key.
|
||||
* @param name
|
||||
* Name.
|
||||
* @param value
|
||||
* Value.
|
||||
*/
|
||||
public static void registrySetStringValue(HKEY hKey, String name, String value) {
|
||||
char[] data = Native.toCharArray(value);
|
||||
int rc = Advapi32.INSTANCE.RegSetValueEx(hKey, name, 0, WinNT.REG_SZ, data, data.length * 2);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a string value in registry.
|
||||
* @param root
|
||||
* Root key.
|
||||
* @param keyPath
|
||||
* Path to an existing registry key.
|
||||
* @param name
|
||||
* Name.
|
||||
* @param value
|
||||
* Value.
|
||||
*/
|
||||
public static void registrySetStringValue(HKEY root, String keyPath, String name, String value) {
|
||||
HKEYByReference phkKey = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ | WinNT.KEY_WRITE, phkKey);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
try {
|
||||
registrySetStringValue(phkKey.getValue(), name, value);
|
||||
} finally {
|
||||
rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a registry key.
|
||||
* @param hKey
|
||||
* Parent key.
|
||||
* @param keyName
|
||||
* Name of the key to delete.
|
||||
*/
|
||||
public static void registryDeleteKey(HKEY hKey, String keyName) {
|
||||
int rc = Advapi32.INSTANCE.RegDeleteKey(hKey, keyName);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a registry key.
|
||||
* @param root
|
||||
* Root key.
|
||||
* @param keyPath
|
||||
* Path to an existing registry key.
|
||||
* @param keyName
|
||||
* Name of the key to delete.
|
||||
*/
|
||||
public static void registryDeleteKey(HKEY root, String keyPath, String keyName) {
|
||||
HKEYByReference phkKey = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ | WinNT.KEY_WRITE, phkKey);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
try {
|
||||
registryDeleteKey(phkKey.getValue(), keyName);
|
||||
} finally {
|
||||
rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a registry value.
|
||||
* @param hKey
|
||||
* Parent key.
|
||||
* @param valueName
|
||||
* Name of the value to delete.
|
||||
*/
|
||||
public static void registryDeleteValue(HKEY hKey, String valueName) {
|
||||
int rc = Advapi32.INSTANCE.RegDeleteValue(hKey, valueName);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a registry value.
|
||||
* @param root
|
||||
* Root key.
|
||||
* @param keyPath
|
||||
* Path to an existing registry key.
|
||||
* @param valueName
|
||||
* Name of the value to delete.
|
||||
*/
|
||||
public static void registryDeleteValue(HKEY root, String keyPath, String valueName) {
|
||||
HKEYByReference phkKey = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ | WinNT.KEY_WRITE, phkKey);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
try {
|
||||
registryDeleteValue(phkKey.getValue(), valueName);
|
||||
} finally {
|
||||
rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get names of the registry key's sub-keys.
|
||||
* @param hKey
|
||||
* Registry key.
|
||||
* @return
|
||||
* Array of registry key names.
|
||||
*/
|
||||
public static String[] registryGetKeys(HKEY hKey) {
|
||||
IntByReference lpcSubKeys = new IntByReference();
|
||||
IntByReference lpcMaxSubKeyLen = new IntByReference();
|
||||
int rc = Advapi32.INSTANCE.RegQueryInfoKey(hKey, null, null, null,
|
||||
lpcSubKeys, lpcMaxSubKeyLen, null, null, null, null, null, null);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
ArrayList<String> keys = new ArrayList<String>(lpcSubKeys.getValue());
|
||||
char[] name = new char[lpcMaxSubKeyLen.getValue() + 1];
|
||||
for (int i = 0; i < lpcSubKeys.getValue(); i++) {
|
||||
IntByReference lpcchValueName = new IntByReference(lpcMaxSubKeyLen.getValue() + 1);
|
||||
rc = Advapi32.INSTANCE.RegEnumKeyEx(hKey, i, name, lpcchValueName,
|
||||
null, null, null, null);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
keys.add(Native.toString(name));
|
||||
}
|
||||
return keys.toArray(new String[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get names of the registry key's sub-keys.
|
||||
* @param root
|
||||
* Root key.
|
||||
* @param keyPath
|
||||
* Path to a registry key.
|
||||
* @return
|
||||
* Array of registry key names.
|
||||
*/
|
||||
public static String[] registryGetKeys(HKEY root, String keyPath) {
|
||||
HKEYByReference phkKey = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ, phkKey);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
try {
|
||||
return registryGetKeys(phkKey.getValue());
|
||||
} finally {
|
||||
rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a table of registry values.
|
||||
* @param hKey
|
||||
* Registry key.
|
||||
* @return
|
||||
* Table of values.
|
||||
*/
|
||||
public static TreeMap<String, Object> registryGetValues(HKEY hKey) {
|
||||
IntByReference lpcValues = new IntByReference();
|
||||
IntByReference lpcMaxValueNameLen = new IntByReference();
|
||||
IntByReference lpcMaxValueLen = new IntByReference();
|
||||
int rc = Advapi32.INSTANCE.RegQueryInfoKey(hKey, null, null, null, null,
|
||||
null, null, lpcValues, lpcMaxValueNameLen, lpcMaxValueLen, null, null);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
TreeMap<String, Object> keyValues = new TreeMap<String, Object>();
|
||||
char[] name = new char[lpcMaxValueNameLen.getValue() + 1];
|
||||
byte[] data = new byte[lpcMaxValueLen.getValue()];
|
||||
for (int i = 0; i < lpcValues.getValue(); i++) {
|
||||
IntByReference lpcchValueName = new IntByReference(lpcMaxValueNameLen.getValue() + 1);
|
||||
IntByReference lpcbData = new IntByReference(lpcMaxValueLen.getValue());
|
||||
IntByReference lpType = new IntByReference();
|
||||
rc = Advapi32.INSTANCE.RegEnumValue(hKey, i, name, lpcchValueName, null,
|
||||
lpType, data, lpcbData);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
switch(lpType.getValue()) {
|
||||
case WinNT.REG_DWORD:
|
||||
keyValues.put(Native.toString(name),
|
||||
((int)(data[0] & 0xff)) +
|
||||
(((int)(data[1] & 0xff)) << 8) +
|
||||
(((int)(data[2] & 0xff)) << 16) +
|
||||
(((int)(data[3] & 0xff)) << 24));
|
||||
break;
|
||||
case WinNT.REG_SZ:
|
||||
try {
|
||||
keyValues.put(Native.toString(name),
|
||||
new String(data, 0, data.length - 2, "UTF-16LE"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unsupported type: " + lpType.getValue());
|
||||
}
|
||||
}
|
||||
return keyValues;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a table of registry values.
|
||||
* @param root
|
||||
* Registry root.
|
||||
* @param keyPath
|
||||
* Regitry key path.
|
||||
* @return
|
||||
* Table of values.
|
||||
*/
|
||||
public static TreeMap<String, Object> registryGetValues(HKEY root, String keyPath) {
|
||||
HKEYByReference phkKey = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ, phkKey);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) { throw new Win32Exception(rc);
|
||||
}
|
||||
try {
|
||||
return registryGetValues(phkKey.getValue());
|
||||
} finally {
|
||||
rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.platform.win32.WinCrypt.CRYPTPROTECT_PROMPTSTRUCT;
|
||||
import com.sun.jna.platform.win32.WinCrypt.DATA_BLOB;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/**
|
||||
* Crypt32.dll Interface.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface Crypt32 extends W32API {
|
||||
Crypt32 INSTANCE = (Crypt32) Native.loadLibrary("Crypt32",
|
||||
Crypt32.class, W32APIOptions.UNICODE_OPTIONS);
|
||||
|
||||
/**
|
||||
* The CryptProtectData function performs encryption on the data in a DATA_BLOB
|
||||
* structure. Typically, only a user with the same logon credential as the encrypter
|
||||
* can decrypt the data. In addition, the encryption and decryption usually must be
|
||||
* done on the same computer.
|
||||
* @param pDataIn
|
||||
* Pointer to a DATA_BLOB structure that contains the plaintext to be encrypted.
|
||||
* @param szDataDescr
|
||||
* String with a readable description of the data to be encrypted. This description
|
||||
* string is included with the encrypted data. This parameter is optional and can
|
||||
* be set to NULL, except on Windows 2000.
|
||||
* @param pOptionalEntropy
|
||||
* Pointer to a DATA_BLOB structure that contains a password or other additional
|
||||
* entropy used to encrypt the data. The DATA_BLOB structure used in the encryption
|
||||
* phase must also be used in the decryption phase. This parameter can be set to NULL
|
||||
* for no additional entropy.
|
||||
* @param pvReserved
|
||||
* Reserved for future use and must be set to NULL.
|
||||
* @param pPromptStruct
|
||||
* Pointer to a CRYPTPROTECT_PROMPTSTRUCT structure that provides information about
|
||||
* where and when prompts are to be displayed and what the content of those prompts
|
||||
* should be. This parameter can be set to NULL in both the encryption and decryption
|
||||
* phases.
|
||||
* @param dwFlags
|
||||
* One of CRYPTPROTECT_LOCAL_MACHINE, CRYPTPROTECT_UI_FORBIDDEN, CRYPTPROTECT_AUDIT,
|
||||
* CRYPTPROTECT_VERIFY_PROTECTION.
|
||||
* @param pDataOut
|
||||
* Pointer to a DATA_BLOB structure that receives the encrypted data. When you have
|
||||
* finished using the DATA_BLOB structure, free its pbData member by calling the
|
||||
* LocalFree function.
|
||||
* @return
|
||||
* If the function succeeds, the function returns TRUE. If the function fails,
|
||||
* it returns FALSE. For extended error information, call GetLastError.
|
||||
*/
|
||||
public boolean CryptProtectData(DATA_BLOB pDataIn, String szDataDescr,
|
||||
DATA_BLOB pOptionalEntropy, Pointer pvReserved,
|
||||
CRYPTPROTECT_PROMPTSTRUCT pPromptStruct,
|
||||
int dwFlags,
|
||||
DATA_BLOB pDataOut);
|
||||
|
||||
/**
|
||||
* The CryptUnprotectData function decrypts and does an integrity check of the data in
|
||||
* a DATA_BLOB structure. Usually, only a user with the same logon credentials as the
|
||||
* encrypter can decrypt the data. In addition, the encryption and decryption must be
|
||||
* done on the same computer.
|
||||
* @param pDataIn
|
||||
* Pointer to a DATA_BLOB structure that holds the encrypted data. The DATA_BLOB
|
||||
* structure's cbData member holds the length of the pbData member's byte string that
|
||||
* contains the text to be encrypted.
|
||||
* @param szDataDescr
|
||||
* Pointer to a string-readable description of the encrypted data included with the
|
||||
* encrypted data. This parameter can be set to NULL. When you have finished using
|
||||
* ppszDataDescr, free it by calling the LocalFree function.
|
||||
* @param pOptionalEntropy
|
||||
* Pointer to a DATA_BLOB structure that contains a password or other additional
|
||||
* entropy used when the data was encrypted. This parameter can be set to NULL;
|
||||
* however, if an optional entropy DATA_BLOB structure was used in the encryption
|
||||
* phase, that same DATA_BLOB structure must be used for the decryption phase.
|
||||
* @param pvReserved
|
||||
* Reserved for future use; must be set to NULL.
|
||||
* @param pPromptStruct
|
||||
* Pointer to a CRYPTPROTECT_PROMPTSTRUCT structure that provides information about
|
||||
* where and when prompts are to be displayed and what the content of those prompts
|
||||
* should be. This parameter can be set to NULL.
|
||||
* @param dwFlags
|
||||
* DWORD value that specifies options for this function. This parameter can be zero,
|
||||
* in which case no option is set, or CRYPTPROTECT_UI_FORBIDDEN.
|
||||
* @param pDataOut
|
||||
* Pointer to a DATA_BLOB structure where the function stores the decrypted data.
|
||||
* When you have finished using the DATA_BLOB structure, free its pbData member by
|
||||
* calling the LocalFree function.
|
||||
* @return
|
||||
* If the function succeeds, the return value is TRUE. If the function fails, the
|
||||
* return value is FALSE.
|
||||
*/
|
||||
public boolean CryptUnprotectData(DATA_BLOB pDataIn, PointerByReference szDataDescr,
|
||||
DATA_BLOB pOptionalEntropy, Pointer pvReserved,
|
||||
CRYPTPROTECT_PROMPTSTRUCT pPromptStruct,
|
||||
int dwFlags,
|
||||
DATA_BLOB pDataOut);
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.platform.win32.WinCrypt.CRYPTPROTECT_PROMPTSTRUCT;
|
||||
import com.sun.jna.platform.win32.WinCrypt.DATA_BLOB;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
|
||||
/**
|
||||
* Crypt32 utility API.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public abstract class Crypt32Util {
|
||||
|
||||
/**
|
||||
* Protect a blob of data.
|
||||
* @param data
|
||||
* Data to protect.
|
||||
* @return
|
||||
* Protected data.
|
||||
*/
|
||||
public static byte[] cryptProtectData(byte[] data) {
|
||||
return cryptProtectData(data, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protect a blob of data with optional flags.
|
||||
* @param data
|
||||
* Data to protect.
|
||||
* @param flags
|
||||
* Optional flags, eg. CRYPTPROTECT_LOCAL_MACHINE | CRYPTPROTECT_UI_FORBIDDEN.
|
||||
* @return
|
||||
* Protected data.
|
||||
*/
|
||||
public static byte[] cryptProtectData(byte[] data, int flags) {
|
||||
return cryptProtectData(data, null, flags, "", null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protect a blob of data.
|
||||
* @param data
|
||||
* Data to protect.
|
||||
* @param entropy
|
||||
* Optional entropy.
|
||||
* @param flags
|
||||
* Optional flags.
|
||||
* @param description
|
||||
* Optional description.
|
||||
* @param prompt
|
||||
* Prompt structure.
|
||||
* @return
|
||||
* Protected bytes.
|
||||
*/
|
||||
public static byte[] cryptProtectData(byte[] data, byte[] entropy, int flags,
|
||||
String description, CRYPTPROTECT_PROMPTSTRUCT prompt) {
|
||||
DATA_BLOB pDataIn = new DATA_BLOB(data);
|
||||
DATA_BLOB pDataProtected = new DATA_BLOB();
|
||||
DATA_BLOB pEntropy = (entropy == null) ? null : new DATA_BLOB(entropy);
|
||||
try {
|
||||
if (! Crypt32.INSTANCE.CryptProtectData(pDataIn, description,
|
||||
pEntropy, null, prompt, flags, pDataProtected)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
return pDataProtected.getData();
|
||||
} finally {
|
||||
if (pDataProtected.pbData != null) {
|
||||
Kernel32.INSTANCE.LocalFree(pDataProtected.pbData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unprotect a blob of data.
|
||||
* @param data
|
||||
* Data to unprotect.
|
||||
* @return
|
||||
* Unprotected blob of data.
|
||||
*/
|
||||
public static byte[] cryptUnprotectData(byte[] data) {
|
||||
return cryptUnprotectData(data, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unprotect a blob of data.
|
||||
* @param data
|
||||
* Data to unprotect.
|
||||
* @param flags
|
||||
* Optional flags, eg. CRYPTPROTECT_UI_FORBIDDEN.
|
||||
* @return
|
||||
* Unprotected blob of data.
|
||||
*/
|
||||
public static byte[] cryptUnprotectData(byte[] data, int flags) {
|
||||
return cryptUnprotectData(data, null, flags, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unprotect a blob of data.
|
||||
* @param data
|
||||
* Data to unprotect.
|
||||
* @param entropy
|
||||
* Optional entropy.
|
||||
* @param flags
|
||||
* Optional flags.
|
||||
* @param prompt
|
||||
* Optional prompt structure.
|
||||
* @return
|
||||
* Unprotected blob of data.
|
||||
*/
|
||||
public static byte[] cryptUnprotectData(byte[] data, byte[] entropy, int flags,
|
||||
CRYPTPROTECT_PROMPTSTRUCT prompt) {
|
||||
DATA_BLOB pDataIn = new DATA_BLOB(data);
|
||||
DATA_BLOB pDataUnprotected = new DATA_BLOB();
|
||||
DATA_BLOB pEntropy = (entropy == null) ? null : new DATA_BLOB(entropy);
|
||||
PointerByReference pDescription = new PointerByReference();
|
||||
try {
|
||||
if (! Crypt32.INSTANCE.CryptUnprotectData(pDataIn, pDescription,
|
||||
pEntropy, null, prompt, flags, pDataUnprotected)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
return pDataUnprotected.getData();
|
||||
} finally {
|
||||
if (pDataUnprotected.pbData != null) {
|
||||
Kernel32.INSTANCE.LocalFree(pDataUnprotected.pbData);
|
||||
}
|
||||
if (pDescription.getValue() != null) {
|
||||
Kernel32.INSTANCE.LocalFree(pDescription.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.NativeLong;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.WString;
|
||||
import com.sun.jna.platform.win32.Guid.GUID;
|
||||
import com.sun.jna.platform.win32.WinNT.PSID;
|
||||
|
||||
|
||||
/**
|
||||
* Ported from DsGetDC.h.
|
||||
* Windows SDK 6.0a
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public abstract class DsGetDC {
|
||||
|
||||
/**
|
||||
* The DOMAIN_CONTROLLER_INFO structure is used with the DsGetDcName
|
||||
* function to receive data about a domain controller.
|
||||
*/
|
||||
public static class DOMAIN_CONTROLLER_INFO extends Structure {
|
||||
|
||||
public static class ByReference extends DOMAIN_CONTROLLER_INFO implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
public DOMAIN_CONTROLLER_INFO() {
|
||||
|
||||
}
|
||||
|
||||
public DOMAIN_CONTROLLER_INFO(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a null-terminated WString that specifies the computer name
|
||||
* of the discovered domain controller. The returned computer name is
|
||||
* prefixed with "\\". The DNS-style name, for example, "\\phoenix.fabrikam.com",
|
||||
* is returned, if available. If the DNS-style name is not available, the
|
||||
* flat-style name (for example, "\\phoenix") is returned. This example would apply
|
||||
* if the domain is a Windows NT 4.0 domain or if the domain does not support the
|
||||
* IP family of protocols.
|
||||
*/
|
||||
public WString DomainControllerName;
|
||||
/**
|
||||
* Pointer to a null-terminated WString that specifies the address of the discovered
|
||||
* domain controller. The address is prefixed with "\\". This WString is one of the
|
||||
* types defined by the DomainControllerAddressType member.
|
||||
*/
|
||||
public WString DomainControllerAddress;
|
||||
/**
|
||||
* Indicates the type of WString that is contained in the DomainControllerAddress member.
|
||||
*/
|
||||
public int DomainControllerAddressType;
|
||||
/**
|
||||
* The GUID of the domain. This member is zero if the domain controller does not have
|
||||
* a Domain GUID; for example, the domain controller is not a Windows 2000 domain
|
||||
* controller.
|
||||
*/
|
||||
public GUID DomainGuid;
|
||||
/**
|
||||
* Pointer to a null-terminated WString that specifies the name of the domain. The
|
||||
* DNS-style name, for example, "fabrikam.com", is returned if available. Otherwise,
|
||||
* the flat-style name, for example, "fabrikam", is returned. This name may be different
|
||||
* than the requested domain name if the domain has been renamed.
|
||||
*/
|
||||
public WString DomainName;
|
||||
/**
|
||||
* Pointer to a null-terminated WString that specifies the name of the domain at the root
|
||||
* of the DS tree. The DNS-style name, for example, "fabrikam.com", is returned if
|
||||
* available. Otherwise, the flat-style name, for example, "fabrikam" is returned.
|
||||
*/
|
||||
public WString DnsForestName;
|
||||
/**
|
||||
* Contains a set of flags that describe the domain controller.
|
||||
*/
|
||||
public int Flags;
|
||||
/**
|
||||
* Pointer to a null-terminated WString that specifies the name of the site where the
|
||||
* domain controller is located. This member may be NULL if the domain controller is
|
||||
* not in a site; for example, the domain controller is a Windows NT 4.0 domain
|
||||
* controller.
|
||||
*/
|
||||
public WString DcSiteName;
|
||||
/**
|
||||
* Pointer to a null-terminated WString that specifies the name of the site that the
|
||||
* computer belongs to. The computer is specified in the ComputerName parameter passed
|
||||
* to DsGetDcName. This member may be NULL if the site that contains the computer
|
||||
* cannot be found; for example, if the DS administrator has not associated the
|
||||
* subnet that the computer is in with a valid site.
|
||||
*/
|
||||
public WString ClientSiteName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to DOMAIN_CONTROLLER_INFO.
|
||||
*/
|
||||
public static class PDOMAIN_CONTROLLER_INFO extends Structure {
|
||||
|
||||
public static class ByReference extends PDOMAIN_CONTROLLER_INFO implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
public DOMAIN_CONTROLLER_INFO.ByReference dci;
|
||||
}
|
||||
|
||||
/**
|
||||
* Domain is a member of the forest.
|
||||
*/
|
||||
public static final int DS_DOMAIN_IN_FOREST = 0x0001;
|
||||
/**
|
||||
* Domain is directly trusted.
|
||||
*/
|
||||
public static final int DS_DOMAIN_DIRECT_OUTBOUND = 0x0002;
|
||||
/**
|
||||
* Domain is root of a tree in the forest.
|
||||
*/
|
||||
public static final int DS_DOMAIN_TREE_ROOT = 0x0004;
|
||||
/**
|
||||
* Domain is the primary domain of queried server.
|
||||
*/
|
||||
public static final int DS_DOMAIN_PRIMARY = 0x0008;
|
||||
/**
|
||||
* Primary domain is running in native mode.
|
||||
*/
|
||||
public static final int DS_DOMAIN_NATIVE_MODE = 0x0010;
|
||||
/**
|
||||
* Domain is directly trusting.
|
||||
*/
|
||||
public static final int DS_DOMAIN_DIRECT_INBOUND = 0x0020;
|
||||
/**
|
||||
* Valid domain flags.
|
||||
*/
|
||||
public static final int DS_DOMAIN_VALID_FLAGS =
|
||||
DS_DOMAIN_IN_FOREST |
|
||||
DS_DOMAIN_DIRECT_OUTBOUND |
|
||||
DS_DOMAIN_TREE_ROOT |
|
||||
DS_DOMAIN_PRIMARY |
|
||||
DS_DOMAIN_NATIVE_MODE |
|
||||
DS_DOMAIN_DIRECT_INBOUND;
|
||||
|
||||
/**
|
||||
* The DS_DOMAIN_TRUSTS structure is used with the DsEnumerateDomainTrusts function to
|
||||
* contain trust data for a domain.
|
||||
*/
|
||||
public static class DS_DOMAIN_TRUSTS extends Structure {
|
||||
|
||||
public static class ByReference extends DS_DOMAIN_TRUSTS implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a null-terminated string that contains the NetBIOS name of the domain.
|
||||
*/
|
||||
public WString NetbiosDomainName;
|
||||
/**
|
||||
* Pointer to a null-terminated string that contains the DNS name of the domain. This member may be NULL.
|
||||
*/
|
||||
public WString DnsDomainName;
|
||||
/**
|
||||
* Contains a set of flags that specify more data about the domain trust.
|
||||
*/
|
||||
public NativeLong Flags;
|
||||
/**
|
||||
* Contains the index in the Domains array returned by the DsEnumerateDomainTrusts function that
|
||||
* corresponds to the parent domain of the domain represented by this structure.
|
||||
*/
|
||||
public NativeLong ParentIndex;
|
||||
/**
|
||||
* Contains a value that indicates the type of trust represented by this structure.
|
||||
*/
|
||||
public NativeLong TrustType;
|
||||
/**
|
||||
* Contains a value that indicates the attributes of the trust represented by this structure.
|
||||
*/
|
||||
public NativeLong TrustAttributes;
|
||||
|
||||
/**
|
||||
* Contains the security identifier of the domain represented by this structure.
|
||||
*/
|
||||
public PSID.ByReference DomainSid;
|
||||
|
||||
/**
|
||||
* Contains the GUID of the domain represented by this structure.
|
||||
*/
|
||||
public GUID DomainGuid;
|
||||
};
|
||||
|
||||
/**
|
||||
* A pointer to an array of DS_DOMAIN_TRUSTS.
|
||||
*/
|
||||
public static class PDS_DOMAIN_TRUSTS extends Structure {
|
||||
public static class ByReference extends PDS_DOMAIN_TRUSTS implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
public DS_DOMAIN_TRUSTS.ByReference t;
|
||||
|
||||
/**
|
||||
* Returns domain trusts.
|
||||
* @param count
|
||||
* Number of domain trusts.
|
||||
* @return
|
||||
*/
|
||||
public DS_DOMAIN_TRUSTS[] getTrusts(int count) {
|
||||
return (DS_DOMAIN_TRUSTS[]) t.toArray(count);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* <p/>
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/** Definition (incomplete) of <code>gdi32.dll</code>. */
|
||||
public interface GDI32 extends W32API {
|
||||
|
||||
GDI32 INSTANCE = (GDI32)
|
||||
Native.loadLibrary("gdi32", GDI32.class, W32APIOptions.DEFAULT_OPTIONS);
|
||||
|
||||
class RECT extends Structure {
|
||||
public int left;
|
||||
public int top;
|
||||
public int right;
|
||||
public int bottom;
|
||||
public Rectangle toRectangle() {
|
||||
return new Rectangle(left, top, right-left, bottom-top);
|
||||
}
|
||||
public String toString() {
|
||||
return "[(" + left + "," + top + ")(" + right + "," + bottom + ")]";
|
||||
}
|
||||
}
|
||||
|
||||
int RDH_RECTANGLES = 1;
|
||||
class RGNDATAHEADER extends Structure {
|
||||
public int dwSize = size();
|
||||
public int iType = RDH_RECTANGLES; // required
|
||||
public int nCount;
|
||||
public int nRgnSize;
|
||||
public RECT rcBound;
|
||||
}
|
||||
class RGNDATA extends Structure {
|
||||
public RGNDATAHEADER rdh;
|
||||
public byte[] Buffer;
|
||||
public RGNDATA(int bufferSize) {
|
||||
Buffer = new byte[bufferSize];
|
||||
allocateMemory();
|
||||
}
|
||||
}
|
||||
|
||||
public HRGN ExtCreateRegion(Pointer lpXform, int nCount, RGNDATA lpRgnData);
|
||||
|
||||
int RGN_AND = 1;
|
||||
int RGN_OR = 2;
|
||||
int RGN_XOR = 3;
|
||||
int RGN_DIFF = 4;
|
||||
int RGN_COPY = 5;
|
||||
|
||||
int ERROR = 0;
|
||||
int NULLREGION = 1;
|
||||
int SIMPLEREGION = 2;
|
||||
int COMPLEXREGION = 3;
|
||||
int CombineRgn(HRGN hrgnDest, HRGN hrgnSrc1, HRGN hrgnSrc2, int fnCombineMode);
|
||||
|
||||
HRGN CreateRectRgn(int nLeftRect, int nTopRect,
|
||||
int nRightRect, int nBottomRect);
|
||||
|
||||
HRGN CreateRoundRectRgn(int nLeftRect, int nTopRect,
|
||||
int nRightRect, int nBottomRect,
|
||||
int nWidthEllipse,
|
||||
int nHeightEllipse);
|
||||
int ALTERNATE = 1;
|
||||
int WINDING = 2;
|
||||
HRGN CreatePolyPolygonRgn(User32.POINT[] lppt, int[] lpPolyCounts, int nCount, int fnPolyFillMode);
|
||||
|
||||
boolean SetRectRgn(HRGN hrgn, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);
|
||||
|
||||
int SetPixel(HDC hDC, int x, int y, int crColor);
|
||||
|
||||
HDC CreateCompatibleDC(HDC hDC);
|
||||
boolean DeleteDC(HDC hDC);
|
||||
|
||||
int BI_RGB = 0;
|
||||
int BI_RLE8 = 1;
|
||||
int BI_RLE4 = 2;
|
||||
int BI_BITFIELDS = 3;
|
||||
int BI_JPEG = 4;
|
||||
int BI_PNG = 5;
|
||||
class BITMAPINFOHEADER extends Structure {
|
||||
public int biSize = size();
|
||||
public int biWidth;
|
||||
public int biHeight;
|
||||
public short biPlanes;
|
||||
public short biBitCount;
|
||||
public int biCompression;
|
||||
public int biSizeImage;
|
||||
public int biXPelsPerMeter;
|
||||
public int biYPelsPerMeter;
|
||||
public int biClrUsed;
|
||||
public int biClrImportant;
|
||||
}
|
||||
class RGBQUAD extends Structure {
|
||||
public byte rgbBlue;
|
||||
public byte rgbGreen;
|
||||
public byte rgbRed;
|
||||
public byte rgbReserved = 0;
|
||||
}
|
||||
class BITMAPINFO extends Structure {
|
||||
public BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER();
|
||||
//RGBQUAD:
|
||||
//byte rgbBlue;
|
||||
//byte rgbGreen;
|
||||
//byte rgbRed;
|
||||
//byte rgbReserved = 0;
|
||||
int[] bmiColors = new int[1];
|
||||
public BITMAPINFO() { this(1); }
|
||||
public BITMAPINFO(int size) {
|
||||
bmiColors = new int[size];
|
||||
allocateMemory();
|
||||
}
|
||||
}
|
||||
int DIB_RGB_COLORS = 0;
|
||||
int DIB_PAL_COLORS = 1;
|
||||
HBITMAP CreateDIBitmap(HDC hDC, BITMAPINFOHEADER lpbmih, int fdwInit,
|
||||
Pointer lpbInit, BITMAPINFO lpbmi, int fuUsage);
|
||||
HBITMAP CreateDIBSection(HDC hDC, BITMAPINFO pbmi, int iUsage,
|
||||
PointerByReference ppvBits, Pointer hSection,
|
||||
int dwOffset);
|
||||
HBITMAP CreateCompatibleBitmap(HDC hDC, int width, int height);
|
||||
|
||||
HANDLE SelectObject(HDC hDC, HANDLE hGDIObj);
|
||||
boolean DeleteObject(HANDLE p);
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
|
||||
/**
|
||||
* Ported from Guid.h.
|
||||
* Microsoft Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public abstract class Guid {
|
||||
|
||||
public static class GUID extends Structure {
|
||||
|
||||
public static class ByReference extends GUID implements Structure.ByReference {
|
||||
public ByReference() {
|
||||
|
||||
}
|
||||
|
||||
public ByReference(Pointer memory) {
|
||||
super(memory);
|
||||
}
|
||||
}
|
||||
|
||||
public GUID() {
|
||||
|
||||
}
|
||||
|
||||
public GUID(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
public int Data1;
|
||||
public short Data2;
|
||||
public short Data3;
|
||||
public byte[] Data4 = new byte[8];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,514 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* <p/>
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.nio.Buffer;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.ptr.ByReference;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/** Definition (incomplete) of <code>kernel32.dll</code>. */
|
||||
public interface Kernel32 extends W32API {
|
||||
|
||||
Kernel32 INSTANCE = (Kernel32) Native.loadLibrary("kernel32", Kernel32.class,
|
||||
W32APIOptions.UNICODE_OPTIONS);
|
||||
|
||||
/**
|
||||
* Frees the specified local memory object and invalidates its handle.
|
||||
* @param hLocal
|
||||
* A handle to the local memory object.
|
||||
* @return
|
||||
* If the function succeeds, the return value is NULL.
|
||||
* If the function fails, the return value is equal to a handle to the local memory object.
|
||||
* To get extended error information, call GetLastError.
|
||||
*/
|
||||
Pointer LocalFree(Pointer hLocal);
|
||||
|
||||
/**
|
||||
* Frees the specified global memory object and invalidates its handle.
|
||||
* @param hGlobal
|
||||
* A handle to the global memory object.
|
||||
* @return
|
||||
* If the function succeeds, the return value is NULL
|
||||
* If the function fails, the return value is equal to a handle to the global memory object.
|
||||
* To get extended error information, call GetLastError.
|
||||
*/
|
||||
Pointer GlobalFree(Pointer hGlobal);
|
||||
|
||||
/**
|
||||
* The GetModuleHandle function retrieves a module handle for the specified module
|
||||
* if the file has been mapped into the address space of the calling process.
|
||||
* @param name
|
||||
* Pointer to a null-terminated string that contains the name of the module
|
||||
* (either a .dll or .exe file).
|
||||
* @return
|
||||
* If the function succeeds, the return value is a handle to the specified module.
|
||||
* If the function fails, the return value is NULL. To get extended error
|
||||
* information, call GetLastError.
|
||||
*/
|
||||
HMODULE GetModuleHandle(String name);
|
||||
|
||||
/**
|
||||
* The GetSystemTime function retrieves the current system date and time.
|
||||
* The system time is expressed in Coordinated Universal Time (UTC).
|
||||
* @param lpSystemTime
|
||||
* Pointer to a SYSTEMTIME structure to receive the current system date and time.
|
||||
*/
|
||||
void GetSystemTime(WinBase.SYSTEMTIME lpSystemTime);
|
||||
|
||||
/**
|
||||
* The GetCurrentThreadId function retrieves the thread identifier of the calling thread.
|
||||
* @return The return value is the thread identifier of the calling thread.
|
||||
*/
|
||||
int GetCurrentThreadId();
|
||||
|
||||
/**
|
||||
* The GetCurrentThread function retrieves a pseudo handle for the current thread.
|
||||
* @return The return value is a pseudo handle for the current thread.
|
||||
*/
|
||||
HANDLE GetCurrentThread();
|
||||
|
||||
/**
|
||||
* This function returns the process identifier of the calling process.
|
||||
* @return The return value is the process identifier of the calling process.
|
||||
*/
|
||||
int GetCurrentProcessId();
|
||||
|
||||
/**
|
||||
* This function returns a pseudohandle for the current process.
|
||||
* @return The return value is a pseudohandle to the current process.
|
||||
*/
|
||||
HANDLE GetCurrentProcess();
|
||||
|
||||
/**
|
||||
* The GetProcessId function retrieves the process identifier of the
|
||||
* specified process.
|
||||
* @param process
|
||||
* Handle to the process. The handle must have the PROCESS_QUERY_INFORMATION access right.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the process identifier of the
|
||||
* specified process. If the function fails, the return value is zero. To get
|
||||
* extended error information, call GetLastError.
|
||||
*/
|
||||
int GetProcessId(HANDLE process);
|
||||
|
||||
/**
|
||||
* The GetProcessVersion function retrieves the major and minor version numbers of the system
|
||||
* on which the specified process expects to run.
|
||||
* @param processId
|
||||
* Process identifier of the process of interest. A value of zero specifies the
|
||||
* calling process.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the version of the system on
|
||||
* which the process expects to run. The high word of the return value contains
|
||||
* the major version number. The low word of the return value contains the minor
|
||||
* version number. If the function fails, the return value is zero. To get extended
|
||||
* error information, call GetLastError. The function fails if ProcessId is an
|
||||
* invalid value.
|
||||
*/
|
||||
int GetProcessVersion(int processId);
|
||||
|
||||
/**
|
||||
* The GetLastError function retrieves the calling thread's last-error code value.
|
||||
* The last-error code is maintained on a per-thread basis. Multiple threads do not
|
||||
* overwrite each other's last-error code.
|
||||
* @return
|
||||
* The return value is the calling thread's last-error code value.
|
||||
*/
|
||||
int GetLastError();
|
||||
|
||||
/**
|
||||
* The SetLastError function sets the last-error code for the calling thread.
|
||||
* @param dwErrCode
|
||||
* Last-error code for the thread.
|
||||
*/
|
||||
void SetLastError(int dwErrCode);
|
||||
|
||||
/**
|
||||
* The GetDriveType function determines whether a disk drive is a removable,
|
||||
* fixed, CD-ROM, RAM disk, or network drive.
|
||||
* @param rootPathName
|
||||
* Pointer to a null-terminated string that specifies the root directory of
|
||||
* the disk to return information about. A trailing backslash is required.
|
||||
* If this parameter is NULL, the function uses the root of the current directory.
|
||||
* @return
|
||||
* The return value specifies the type of drive.
|
||||
*/
|
||||
int GetDriveType(String rootPathName);
|
||||
|
||||
/**
|
||||
* The FormatMessage function formats a message string. The function requires a
|
||||
* message definition as input. The message definition can come from a buffer
|
||||
* passed into the function. It can come from a message table resource in an
|
||||
* already-loaded module. Or the caller can ask the function to search the
|
||||
* system's message table resource(s) for the message definition. The function
|
||||
* finds the message definition in a message table resource based on a message
|
||||
* identifier and a language identifier. The function copies the formatted message
|
||||
* text to an output buffer, processing any embedded insert sequences if requested.
|
||||
* @param dwFlags
|
||||
* Formatting options, and how to interpret the lpSource parameter. The low-order
|
||||
* byte of dwFlags specifies how the function handles line breaks in the output
|
||||
* buffer. The low-order byte can also specify the maximum width of a formatted
|
||||
* output line.
|
||||
* @param lpSource
|
||||
* Location of the message definition.
|
||||
* @param dwMessageId
|
||||
* Message identifier for the requested message.
|
||||
* @param dwLanguageId
|
||||
* Language identifier for the requested message.
|
||||
* @param lpBuffer
|
||||
* Pointer to a buffer that receives the null-terminated string that specifies the
|
||||
* formatted message.
|
||||
* @param nSize
|
||||
* If the FORMAT_MESSAGE_ALLOCATE_BUFFER flag is not set, this parameter specifies
|
||||
* the size of the output buffer, in TCHARs. If FORMAT_MESSAGE_ALLOCATE_BUFFER is
|
||||
* set, this parameter specifies the minimum number of TCHARs to allocate for an
|
||||
* output buffer.
|
||||
* @param va_list
|
||||
* Pointer to an array of values that are used as insert values in the formatted message.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the number of TCHARs stored in
|
||||
* the output buffer, excluding the terminating null character. If the function
|
||||
* fails, the return value is zero. To get extended error information, call
|
||||
* GetLastError.
|
||||
*/
|
||||
int FormatMessage(int dwFlags, Pointer lpSource, int dwMessageId,
|
||||
int dwLanguageId, PointerByReference lpBuffer,
|
||||
int nSize, Pointer va_list);
|
||||
|
||||
/**
|
||||
* The FormatMessage function formats a message string. The function requires a
|
||||
* message definition as input. The message definition can come from a buffer
|
||||
* passed into the function. It can come from a message table resource in an
|
||||
* already-loaded module. Or the caller can ask the function to search the
|
||||
* system's message table resource(s) for the message definition. The function
|
||||
* finds the message definition in a message table resource based on a message
|
||||
* identifier and a language identifier. The function copies the formatted message
|
||||
* text to an output buffer, processing any embedded insert sequences if requested.
|
||||
* @param dwFlags
|
||||
* Formatting options, and how to interpret the lpSource parameter. The low-order
|
||||
* byte of dwFlags specifies how the function handles line breaks in the output
|
||||
* buffer. The low-order byte can also specify the maximum width of a formatted
|
||||
* output line.
|
||||
* @param lpSource
|
||||
* Location of the message definition.
|
||||
* @param dwMessageId
|
||||
* Message identifier for the requested message.
|
||||
* @param dwLanguageId
|
||||
* Language identifier for the requested message.
|
||||
* @param lpBuffer
|
||||
* Pointer to a buffer that receives the null-terminated string that specifies the
|
||||
* formatted message.
|
||||
* @param nSize
|
||||
* If the FORMAT_MESSAGE_ALLOCATE_BUFFER flag is not set, this parameter specifies
|
||||
* the size of the output buffer, in TCHARs. If FORMAT_MESSAGE_ALLOCATE_BUFFER is
|
||||
* set, this parameter specifies the minimum number of TCHARs to allocate for an
|
||||
* output buffer.
|
||||
* @param va_list
|
||||
* Pointer to an array of values that are used as insert values in the formatted message.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the number of TCHARs stored in
|
||||
* the output buffer, excluding the terminating null character. If the function
|
||||
* fails, the return value is zero. To get extended error information, call
|
||||
* GetLastError.
|
||||
*/
|
||||
int FormatMessage(int dwFlags, Pointer lpSource, int dwMessageId,
|
||||
int dwLanguageId, Buffer lpBuffer,
|
||||
int nSize, Pointer va_list);
|
||||
|
||||
/**
|
||||
* The CreateFile function creates or opens a file, file stream, directory, physical
|
||||
* disk, volume, console buffer, tape drive, communications resource, mailslot, or
|
||||
* named pipe. The function returns a handle that can be used to access an object.
|
||||
* @param lpFileName
|
||||
* A pointer to a null-terminated string that specifies the name of an object to create or open.
|
||||
* @param dwDesiredAccess
|
||||
* The access to the object, which can be read, write, or both.
|
||||
* @param dwShareMode
|
||||
* The sharing mode of an object, which can be read, write, both, or none.
|
||||
* @param lpSecurityAttributes
|
||||
* A pointer to a SECURITY_ATTRIBUTES structure that determines whether or not
|
||||
* the returned handle can be inherited by child processes. If lpSecurityAttributes
|
||||
* is NULL, the handle cannot be inherited.
|
||||
* @param dwCreationDisposition
|
||||
* An action to take on files that exist and do not exist.
|
||||
* @param dwFlagsAndAttributes
|
||||
* The file attributes and flags.
|
||||
* @param hTemplateFile
|
||||
* Handle to a template file with the GENERIC_READ access right. The template file
|
||||
* supplies file attributes and extended attributes for the file that is being
|
||||
* created. This parameter can be NULL.
|
||||
* @return
|
||||
* If the function succeeds, the return value is an open handle to a specified file.
|
||||
* If a specified file exists before the function call and dwCreationDisposition is
|
||||
* CREATE_ALWAYS or OPEN_ALWAYS, a call to GetLastError returns ERROR_ALREADY_EXISTS,
|
||||
* even when the function succeeds. If a file does not exist before the call,
|
||||
* GetLastError returns 0 (zero). If the function fails, the return value is
|
||||
* INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.
|
||||
*/
|
||||
HANDLE CreateFile(String lpFileName, int dwDesiredAccess, int dwShareMode,
|
||||
WinNT.SECURITY_ATTRIBUTES lpSecurityAttributes, int dwCreationDisposition,
|
||||
int dwFlagsAndAttributes, HANDLE hTemplateFile);
|
||||
|
||||
|
||||
/**
|
||||
* The CreateDirectory function creates a new directory. If the underlying file
|
||||
* system supports security on files and directories, the function applies a
|
||||
* specified security descriptor to the new directory.
|
||||
* @param lpPathName
|
||||
* Pointer to a null-terminated string that specifies the path of the directory
|
||||
* to be created.
|
||||
* @param lpSecurityAttributes
|
||||
* Pointer to a SECURITY_ATTRIBUTES structure. The lpSecurityDescriptor member
|
||||
* of the structure specifies a security descriptor for the new directory. If
|
||||
* lpSecurityAttributes is NULL, the directory gets a default security descriptor.
|
||||
* @return
|
||||
* If the function succeeds, the return value is nonzero. If the function fails,
|
||||
* the return value is zero. To get extended error information, call GetLastError.
|
||||
*/
|
||||
boolean CreateDirectory(String lpPathName,
|
||||
WinNT.SECURITY_ATTRIBUTES lpSecurityAttributes);
|
||||
|
||||
HANDLE CreateIoCompletionPort(HANDLE FileHandle, HANDLE ExistingCompletionPort,
|
||||
Pointer CompletionKey, int NumberOfConcurrentThreads);
|
||||
|
||||
boolean GetQueuedCompletionStatus(HANDLE CompletionPort,
|
||||
IntByReference lpNumberOfBytes, ByReference lpCompletionKey,
|
||||
PointerByReference lpOverlapped, int dwMilliseconds);
|
||||
|
||||
boolean PostQueuedCompletionStatus(HANDLE CompletionPort,
|
||||
int dwNumberOfBytesTransferred, Pointer dwCompletionKey,
|
||||
WinBase.OVERLAPPED lpOverlapped);
|
||||
|
||||
/**
|
||||
* Waits until the specified object is in the signaled state or the time-out interval elapses.
|
||||
* To enter an alertable wait state, use the WaitForSingleObjectEx function.
|
||||
* To wait for multiple objects, use the WaitForMultipleObjects.
|
||||
* @param hHandle
|
||||
* A handle to the object. For a list of the object types whose handles can be specified, see the following Remarks section.
|
||||
* If this handle is closed while the wait is still pending, the function's behavior is undefined.
|
||||
* The handle must have the SYNCHRONIZE access right. For more information, see Standard Access Rights.
|
||||
* @param dwMilliseconds
|
||||
* The time-out interval, in milliseconds. If a nonzero value is specified, the function waits until the object is signaled or the interval elapses.
|
||||
* If dwMilliseconds is zero, the function does not enter a wait state if the object is not signaled; it always returns immediately.
|
||||
* If dwMilliseconds is INFINITE, the function will return only when the object is signaled.
|
||||
* @return
|
||||
* If the function succeeds, the return value indicates the event that caused the function to return.
|
||||
*/
|
||||
int WaitForSingleObject(HANDLE hHandle, int dwMilliseconds);
|
||||
|
||||
/**
|
||||
* Waits until one or all of the specified objects are in the signaled state or the time-out interval elapses.
|
||||
* To enter an alertable wait state, use the WaitForMultipleObjectsEx function.
|
||||
* @param nCount
|
||||
* The number of object handles in the array pointed to by lpHandles. The maximum number of object handles is MAXIMUM_WAIT_OBJECTS.
|
||||
* @param hHandle
|
||||
* An array of object handles. For a list of the object types whose handles can be specified, see the following Remarks section. The array can contain handles to objects of different types.
|
||||
* It may not contain multiple copies of the same handle.
|
||||
* If one of these handles is closed while the wait is still pending, the function's behavior is undefined.
|
||||
* The handles must have the SYNCHRONIZE access right. For more information, see Standard Access Rights.
|
||||
* @param bWaitAll
|
||||
* If this parameter is TRUE, the function returns when the state of all objects in the lpHandles array is signaled.
|
||||
* If FALSE, the function returns when the state of any one of the objects is set to signaled.
|
||||
* In the latter case, the return value indicates the object whose state caused the function to return.
|
||||
* @param dwMilliseconds
|
||||
* The time-out interval, in milliseconds. If a nonzero value is specified, the function waits until the specified objects are signaled or the interval elapses.
|
||||
* If dwMilliseconds is zero, the function does not enter a wait state if the specified objects are not signaled; it always returns immediately.
|
||||
* If dwMilliseconds is INFINITE, the function will return only when the specified objects are signaled.
|
||||
* @return
|
||||
* If the function succeeds, the return value indicates the event that caused the function to return.
|
||||
*/
|
||||
int WaitForMultipleObjects(int nCount, HANDLE[] hHandle, boolean bWaitAll, int dwMilliseconds);
|
||||
|
||||
/**
|
||||
* The DuplicateHandle function duplicates an object handle.
|
||||
*
|
||||
* @param hSourceProcessHandle
|
||||
* Handle to the process with the handle to duplicate.
|
||||
* The handle must have the PROCESS_DUP_HANDLE access right.
|
||||
* @param hSourceHandle
|
||||
* Handle to duplicate. This is an open object handle that is valid in the
|
||||
* context of the source process.
|
||||
* @param hTargetProcessHandle
|
||||
* Handle to the process that is to receive the duplicated handle.
|
||||
* The handle must have the PROCESS_DUP_HANDLE access right.
|
||||
* @param lpTargetHandle
|
||||
* Pointer to a variable that receives the duplicate handle. This handle value is valid in
|
||||
* the context of the target process. If hSourceHandle is a pseudo handle returned by
|
||||
* GetCurrentProcess or GetCurrentThread, DuplicateHandle converts it to a real handle to
|
||||
* a process or thread, respectively.
|
||||
* @param dwDesiredAccess
|
||||
* Access requested for the new handle.
|
||||
* @param bInheritHandle
|
||||
* Indicates whether the handle is inheritable.
|
||||
* @param dwOptions
|
||||
* Optional actions.
|
||||
* @return
|
||||
* If the function succeeds, the return value is nonzero.
|
||||
* If the function fails, the return value is zero. To get extended error information,
|
||||
* call GetLastError.
|
||||
*/
|
||||
boolean DuplicateHandle(HANDLE hSourceProcessHandle, HANDLE hSourceHandle,
|
||||
HANDLE hTargetProcessHandle, HANDLEByReference lpTargetHandle,
|
||||
int dwDesiredAccess, boolean bInheritHandle, int dwOptions);
|
||||
|
||||
/**
|
||||
* The CloseHandle function closes an open object handle.
|
||||
*
|
||||
* @param hObject
|
||||
* Handle to an open object. This parameter can be a pseudo handle or INVALID_HANDLE_VALUE.
|
||||
* @return
|
||||
* If the function succeeds, the return value is nonzero.
|
||||
* If the function fails, the return value is zero. To get extended error information,
|
||||
* call GetLastError.
|
||||
*/
|
||||
boolean CloseHandle(HANDLE hObject);
|
||||
|
||||
// TODO: figure out how OVERLAPPED is used and apply an appropriate mapping
|
||||
interface OVERLAPPED_COMPLETION_ROUTINE extends StdCallCallback {
|
||||
void callback(int errorCode, int nBytesTransferred,
|
||||
WinBase.OVERLAPPED overlapped);
|
||||
}
|
||||
|
||||
/** NOTE: only exists in unicode form (W suffix). Define this method
|
||||
* explicitly with the W suffix to avoid inadvertent calls in ASCII mode.
|
||||
*/
|
||||
public boolean ReadDirectoryChangesW(HANDLE directory,
|
||||
WinNT.FILE_NOTIFY_INFORMATION info, int length, boolean watchSubtree,
|
||||
int notifyFilter, IntByReference bytesReturned, WinBase.OVERLAPPED overlapped,
|
||||
OVERLAPPED_COMPLETION_ROUTINE completionRoutine);
|
||||
|
||||
/** ASCII version. Use {@link Native#toString(byte[])} to obtain the short
|
||||
* path from the <code>byte</code> array.
|
||||
* Use only if <code>w32.ascii==true</code>.
|
||||
*/
|
||||
int GetShortPathName(String lpszLongPath, byte[] lpdzShortPath, int cchBuffer);
|
||||
|
||||
/** Unicode version (the default). Use {@link Native#toString(char[])} to
|
||||
* obtain the short path from the <code>char</code> array.
|
||||
*/
|
||||
int GetShortPathName(String lpszLongPath, char[] lpdzShortPath, int cchBuffer);
|
||||
|
||||
/**
|
||||
* The LocalAlloc function allocates the specified number of bytes from the heap.
|
||||
* Windows memory management does not provide a separate local heap and global heap.
|
||||
* @param type
|
||||
* Memory allocation attributes. The default is the LMEM_FIXED value.
|
||||
* @param cbInput
|
||||
* Number of bytes to allocate. If this parameter is zero and the uFlags parameter
|
||||
* specifies LMEM_MOVEABLE, the function returns a handle to a memory object that
|
||||
* is marked as discarded.
|
||||
* @return
|
||||
* If the function succeeds, the return value is a handle to the newly allocated memory object.
|
||||
* If the function fails, the return value is NULL. To get extended error information, call GetLastError.
|
||||
*/
|
||||
Pointer LocalAlloc(int type, int cbInput);
|
||||
|
||||
boolean WriteFile(HANDLE hFile, byte[] lpBuffer, int nNumberOfBytesToWrite,
|
||||
IntByReference lpNumberOfBytesWritten,
|
||||
WinBase.OVERLAPPED lpOverlapped);
|
||||
|
||||
HANDLE CreateEvent(WinNT.SECURITY_ATTRIBUTES lpEventAttributes,
|
||||
boolean bManualReset, boolean bInitialState,
|
||||
String lpName);
|
||||
|
||||
boolean SetEvent(HANDLE hEvent);
|
||||
|
||||
boolean PulseEvent(HANDLE hEvent);
|
||||
|
||||
HANDLE CreateFileMapping(HANDLE hFile, WinNT.SECURITY_ATTRIBUTES lpAttributes,
|
||||
int flProtect, int dwMaximumSizeHigh,
|
||||
int dwMaximumSizeLow, String lpName);
|
||||
|
||||
Pointer MapViewOfFile(HANDLE hFileMappingObject, int dwDesiredAccess,
|
||||
int dwFileOffsetHigh, int dwFileOffsetLow,
|
||||
int dwNumberOfBytesToMap);
|
||||
|
||||
boolean UnmapViewOfFile(Pointer lpBaseAddress);
|
||||
|
||||
/**
|
||||
* Retrieves only the NetBIOS name of the local computer.
|
||||
*
|
||||
* @param buffer
|
||||
* A pointer to a buffer that receives the computer name or the cluster virtual server
|
||||
* name. The buffer size should be large enough to contain MAX_COMPUTERNAME_LENGTH + 1
|
||||
* characters.
|
||||
* @param lpnSize
|
||||
* On input, specifies the size of the buffer, in TCHARs. On output, the number of TCHARs
|
||||
* copied to the destination buffer, not including the terminating null character. If
|
||||
* the buffer is too small, the function fails and GetLastError returns
|
||||
* ERROR_BUFFER_OVERFLOW. The lpnSize parameter specifies the size of the buffer required,
|
||||
* including the terminating null character.
|
||||
* @return
|
||||
* If the function succeeds, the return value is a nonzero value.
|
||||
* If the function fails, the return value is zero. To get extended error information,
|
||||
* call GetLastError.
|
||||
*/
|
||||
public boolean GetComputerName(char[] buffer, IntByReference lpnSize);
|
||||
|
||||
/**
|
||||
* The OpenThread function opens an existing thread object.
|
||||
* @param dwDesiredAccess
|
||||
* Access to the thread object. This access right is checked against any security
|
||||
* descriptor for the thread.
|
||||
* @param bInheritHandle
|
||||
* If this parameter is TRUE, the new process inherits the handle. If the parameter
|
||||
* is FALSE, the handle is not inherited.
|
||||
* @param dwThreadId
|
||||
* Identifier of the thread to be opened.
|
||||
* @return
|
||||
* If the function succeeds, the return value is an open handle to the specified process.
|
||||
* If the function fails, the return value is NULL. To get extended error information,
|
||||
* call GetLastError.
|
||||
*/
|
||||
HANDLE OpenThread(int dwDesiredAccess, boolean bInheritHandle, int dwThreadId);
|
||||
|
||||
/**
|
||||
* This function returns a handle to an existing process object.
|
||||
* @param fdwAccess
|
||||
* Not supported; set to zero.
|
||||
* @param fInherit
|
||||
* Not supported; set to FALSE.
|
||||
* @param IDProcess
|
||||
* Specifies the process identifier of the process to open.
|
||||
* @return
|
||||
* An open handle to the specified process indicates success.
|
||||
* NULL indicates failure.
|
||||
* To get extended error information, call GetLastError.
|
||||
*/
|
||||
HANDLE OpenProcess(int fdwAccess, boolean fInherit, int IDProcess);
|
||||
|
||||
/**
|
||||
* The GetTempPath function retrieves the path of the directory designated
|
||||
* for temporary files.
|
||||
* @param nBufferLength
|
||||
* Size of the string buffer identified by lpBuffer, in TCHARs.
|
||||
* @param buffer
|
||||
* Pointer to a string buffer that receives the null-terminated string specifying the
|
||||
* temporary file path. The returned string ends with a backslash, for example,
|
||||
* C:\TEMP\.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the length, in TCHARs, of the string
|
||||
* copied to lpBuffer, not including the terminating null character. If the return value
|
||||
* is greater than nBufferLength, the return value is the length, in TCHARs, of the
|
||||
* buffer required to hold the path.
|
||||
*
|
||||
* If the function fails, the return value is zero. To get extended error information,
|
||||
* call GetLastError.
|
||||
*/
|
||||
DWORD GetTempPath(DWORD nBufferLength, char[] buffer);
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.LastErrorException;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.platform.win32.W32API.DWORD;
|
||||
import com.sun.jna.platform.win32.W32API.HRESULT;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
|
||||
/**
|
||||
* Kernel32 utility API.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public abstract class Kernel32Util {
|
||||
|
||||
/**
|
||||
* Get current computer NetBIOS name.
|
||||
* @return
|
||||
* Netbios name.
|
||||
*/
|
||||
public static String getComputerName() {
|
||||
char buffer[] = new char[WinBase.MAX_COMPUTERNAME_LENGTH() + 1];
|
||||
IntByReference lpnSize = new IntByReference(buffer.length);
|
||||
if (! Kernel32.INSTANCE.GetComputerName(buffer, lpnSize)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
return Native.toString(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a message from an HRESULT.
|
||||
* @param code
|
||||
* HRESULT
|
||||
* @return
|
||||
* Formatted message.
|
||||
*/
|
||||
public static String formatMessageFromHR(HRESULT code) {
|
||||
PointerByReference buffer = new PointerByReference();
|
||||
if (0 == Kernel32.INSTANCE.FormatMessage(
|
||||
WinBase.FORMAT_MESSAGE_ALLOCATE_BUFFER
|
||||
| WinBase.FORMAT_MESSAGE_FROM_SYSTEM
|
||||
| WinBase.FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
null,
|
||||
code.intValue(),
|
||||
0, // TODO: MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT)
|
||||
buffer,
|
||||
0,
|
||||
null)) {
|
||||
throw new LastErrorException(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
String s = buffer.getValue().getString(0, ! Boolean.getBoolean("w32.ascii"));
|
||||
s = s.replace(".\r",".").replace(".\n",".");
|
||||
Kernel32.INSTANCE.LocalFree(buffer.getValue());
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a system message from an error code.
|
||||
* @param code
|
||||
* Error code, typically a result of GetLastError.
|
||||
* @return
|
||||
* Formatted message.
|
||||
*/
|
||||
public static String formatMessageFromLastErrorCode(int code) {
|
||||
return formatMessageFromHR(W32Errors.HRESULT_FROM_WIN32(code));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the path designated for temporary files.
|
||||
* @return
|
||||
* Path.
|
||||
*/
|
||||
public static String getTempPath() {
|
||||
DWORD nBufferLength = new DWORD(WinDef.MAX_PATH);
|
||||
char[] buffer = new char[nBufferLength.intValue()];
|
||||
if (Kernel32.INSTANCE.GetTempPath(nBufferLength, buffer).intValue() == 0) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
return Native.toString(buffer);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,309 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.WString;
|
||||
import com.sun.jna.platform.win32.WinNT.PSID;
|
||||
|
||||
/**
|
||||
* Ported from LMAccess.h.
|
||||
* Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface LMAccess {
|
||||
|
||||
public static class LOCALGROUP_INFO_0 extends Structure {
|
||||
public LOCALGROUP_INFO_0() {
|
||||
super();
|
||||
}
|
||||
|
||||
public LOCALGROUP_INFO_0(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
public WString lgrui0_name;
|
||||
}
|
||||
|
||||
public static class LOCALGROUP_INFO_1 extends Structure {
|
||||
public LOCALGROUP_INFO_1() {
|
||||
super();
|
||||
}
|
||||
|
||||
public LOCALGROUP_INFO_1(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
public WString lgrui1_name;
|
||||
public WString lgrui1_comment;
|
||||
}
|
||||
|
||||
//
|
||||
// bit masks for the NetUserEnum filter parameter.
|
||||
//
|
||||
|
||||
public static final int FILTER_TEMP_DUPLICATE_ACCOUNT = 0x0001;
|
||||
public static final int FILTER_NORMAL_ACCOUNT = 0x0002;
|
||||
// public static final int FILTER_PROXY_ACCOUNT = 0x0004;
|
||||
public static final int FILTER_INTERDOMAIN_TRUST_ACCOUNT = 0x0008;
|
||||
public static final int FILTER_WORKSTATION_TRUST_ACCOUNT = 0x0010;
|
||||
public static final int FILTER_SERVER_TRUST_ACCOUNT = 0x0020;
|
||||
|
||||
/**
|
||||
* The USER_INFO_0 structure contains a user account name.
|
||||
*/
|
||||
public static class USER_INFO_0 extends Structure {
|
||||
public USER_INFO_0() {
|
||||
super();
|
||||
}
|
||||
|
||||
public USER_INFO_0(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a Unicode string that specifies the name of the user account.
|
||||
*/
|
||||
public WString usri0_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The USER_INFO_1 structure contains information about a user account, including
|
||||
* account name, password data, privilege level, and the path to the user's home
|
||||
* directory.
|
||||
*/
|
||||
public static class USER_INFO_1 extends Structure {
|
||||
public USER_INFO_1() {
|
||||
super();
|
||||
}
|
||||
|
||||
public USER_INFO_1(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a Unicode string that specifies the name of the user
|
||||
* account.
|
||||
*/
|
||||
public WString usri1_name;
|
||||
/**
|
||||
* Pointer to a Unicode string that specifies the password of the user
|
||||
* indicated by the usri1_name member.
|
||||
*/
|
||||
public WString usri1_password;
|
||||
/**
|
||||
* Specifies a DWORD value that indicates the number of seconds that have
|
||||
* elapsed since the usri1_password member was last changed.
|
||||
*/
|
||||
public int usri1_password_age;
|
||||
/**
|
||||
* Specifies a DWORD value that indicates the level of privilege assigned
|
||||
* to the usri1_name member.
|
||||
*/
|
||||
public int usri1_priv;
|
||||
/**
|
||||
* Pointer to a Unicode string specifying the path of the home directory
|
||||
* for the user specified in the usri1_name member.
|
||||
*/
|
||||
public WString usri1_home_dir;
|
||||
/**
|
||||
* Pointer to a Unicode string that contains a comment to associate with
|
||||
* the user account.
|
||||
*/
|
||||
public WString usri1_comment;
|
||||
/**
|
||||
* Specifies a DWORD value that determines several features.
|
||||
*/
|
||||
public int usri1_flags;
|
||||
/**
|
||||
* Pointer to a Unicode string specifying the path for the user's
|
||||
* logon script file.
|
||||
*/
|
||||
public WString usri1_script_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* The GROUP_USERS_INFO_0 structure contains global group member information.
|
||||
*/
|
||||
public static class GROUP_USERS_INFO_0 extends Structure {
|
||||
public GROUP_USERS_INFO_0() {
|
||||
super();
|
||||
}
|
||||
|
||||
public GROUP_USERS_INFO_0(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a null-terminated Unicode character string that specifies a name.
|
||||
*/
|
||||
public WString grui0_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The LOCALGROUP_USERS_INFO_0 structure contains local group member information.
|
||||
*/
|
||||
public static class LOCALGROUP_USERS_INFO_0 extends Structure {
|
||||
public LOCALGROUP_USERS_INFO_0() {
|
||||
super();
|
||||
}
|
||||
|
||||
public LOCALGROUP_USERS_INFO_0(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a Unicode string specifying the name of a local group to which the user belongs.
|
||||
*/
|
||||
public WString lgrui0_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The GROUP_INFO_0 structure contains the name of a global group in the security
|
||||
* database, which is the security accounts manager (SAM) database or, in the case
|
||||
* of domain controllers, the Active Directory.
|
||||
*/
|
||||
public static class GROUP_INFO_0 extends Structure {
|
||||
public GROUP_INFO_0() {
|
||||
super();
|
||||
}
|
||||
|
||||
public GROUP_INFO_0(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a null-terminated Unicode character string that specifies
|
||||
* the name of the global group.
|
||||
*/
|
||||
public WString grpi0_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* The GROUP_INFO_1 structure contains a global group name and a comment to
|
||||
* associate with the group.
|
||||
*/
|
||||
public static class GROUP_INFO_1 extends Structure {
|
||||
public GROUP_INFO_1() {
|
||||
super();
|
||||
}
|
||||
|
||||
public GROUP_INFO_1(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a null-terminated Unicode character string that specifies
|
||||
* the name of the global group.
|
||||
*/
|
||||
public WString grpi1_name;
|
||||
/**
|
||||
* Pointer to a null-terminated Unicode character string that specifies
|
||||
* a remark associated with the global group. This member can be a null
|
||||
* string. The comment can contain MAXCOMMENTSZ characters.
|
||||
*/
|
||||
public WString grpi1_comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* The GROUP_INFO_2 structure contains information about a global group, including
|
||||
* name, identifier, and resource attributes.
|
||||
*/
|
||||
public static class GROUP_INFO_2 extends Structure {
|
||||
public GROUP_INFO_2() {
|
||||
super();
|
||||
}
|
||||
|
||||
public GROUP_INFO_2(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a null-terminated Unicode character string that
|
||||
* specifies the name of the global group.
|
||||
*/
|
||||
public WString grpi2_name;
|
||||
/**
|
||||
* Pointer to a null-terminated Unicode character string that contains a
|
||||
* remark associated with the global group. This member can be a null string.
|
||||
* The comment can contain MAXCOMMENTSZ characters.
|
||||
*/
|
||||
public WString grpi2_comment;
|
||||
/**
|
||||
* Specifies a DWORD value that contains the relative identifier (RID) of
|
||||
* the global group.
|
||||
*/
|
||||
public int grpi2_group_id;
|
||||
/**
|
||||
* These attributes are hard-coded to SE_GROUP_MANDATORY, SE_GROUP_ENABLED,
|
||||
* and SE_GROUP_ENABLED_BY_DEFAULT.
|
||||
*/
|
||||
public int grpi2_attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* The GROUP_INFO_3 structure contains information about a global group, including
|
||||
* name, security identifier (SID), and resource attributes.
|
||||
*/
|
||||
public static class GROUP_INFO_3 extends Structure {
|
||||
public GROUP_INFO_3() {
|
||||
super();
|
||||
}
|
||||
|
||||
public GROUP_INFO_3(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a null-terminated Unicode character string that
|
||||
* specifies the name of the global group.
|
||||
*/
|
||||
public WString grpi3_name;
|
||||
/**
|
||||
* Pointer to a null-terminated Unicode character string that
|
||||
* contains a remark associated with the global group. This member can be
|
||||
* a null string. The comment can contain MAXCOMMENTSZ characters.
|
||||
*/
|
||||
public WString grpi3_comment;
|
||||
/**
|
||||
* Pointer to a SID structure that contains the security identifier (SID) that
|
||||
* uniquely identifies the global group.
|
||||
*/
|
||||
public PSID grpi3_group_sid;
|
||||
/**
|
||||
* These attributes are hard-coded to SE_GROUP_MANDATORY, SE_GROUP_ENABLED, and
|
||||
* SE_GROUP_ENABLED_BY_DEFAULT.
|
||||
*/
|
||||
public int grpi3_attributes;
|
||||
}
|
||||
|
||||
//
|
||||
// Privilege levels (USER_INFO_X field usriX_priv (X = 0/1)).
|
||||
//
|
||||
|
||||
public static final int USER_PRIV_MASK = 3;
|
||||
public static final int USER_PRIV_GUEST = 0;
|
||||
public static final int USER_PRIV_USER = 1;
|
||||
public static final int USER_PRIV_ADMIN = 2;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
/**
|
||||
* Ported from LMCons.h.
|
||||
* @author dblock[at]dblock.org
|
||||
* Windows SDK 6.0A
|
||||
*/
|
||||
public interface LMCons {
|
||||
public static final int NETBIOS_NAME_LEN = 16; // NetBIOS net name (bytes)
|
||||
|
||||
/**
|
||||
* Value to be used with APIs which have a "preferred maximum length" parameter.
|
||||
* This value indicates that the API should just allocate "as much as it takes."
|
||||
*/
|
||||
public static final int MAX_PREFERRED_LENGTH = -1;
|
||||
}
|
||||
@@ -0,0 +1,564 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
/**
|
||||
* Ported from LMErr.h.
|
||||
* @author dblock[at]dblock.org
|
||||
* Windows SDK 6.0A
|
||||
*/
|
||||
public interface LMErr {
|
||||
public static final int NERR_Success = 0;
|
||||
public static final int NERR_BASE = 2100;
|
||||
|
||||
public static final int NERR_NetNotStarted = NERR_BASE + 2; /* The workstation driver is not installed. */
|
||||
public static final int NERR_UnknownServer = NERR_BASE + 3; /* The server could not be located. */
|
||||
public static final int NERR_ShareMem = NERR_BASE + 4; /* An internal error occurred. The network cannot access a shared memory segment. */
|
||||
|
||||
public static final int NERR_NoNetworkResource = NERR_BASE + 5; /* A network resource shortage occurred . */
|
||||
public static final int NERR_RemoteOnly = NERR_BASE + 6; /* This operation is not supported on workstations. */
|
||||
public static final int NERR_DevNotRedirected = NERR_BASE + 7; /* The device is not connected. */
|
||||
/* NERR_BASE + 8 is used for ERROR_CONNECTED_OTHER_PASSWORD */
|
||||
/* NERR_BASE + 9 is used for ERROR_CONNECTED_OTHER_PASSWORD_DEFAULT */
|
||||
/* UNUSED BASE + 10 */
|
||||
/* UNUSED BASE + 11 */
|
||||
/* UNUSED BASE + 12 */
|
||||
/* UNUSED BASE + 13 */
|
||||
public static final int NERR_ServerNotStarted = NERR_BASE + 14; /* The Server service is not started. */
|
||||
public static final int NERR_ItemNotFound = NERR_BASE + 15; /* The queue is empty. */
|
||||
public static final int NERR_UnknownDevDir = NERR_BASE + 16; /* The device or directory does not exist. */
|
||||
public static final int NERR_RedirectedPath = NERR_BASE + 17; /* The operation is invalid on a redirected resource. */
|
||||
public static final int NERR_DuplicateShare = NERR_BASE + 18; /* The name has already been shared. */
|
||||
public static final int NERR_NoRoom = NERR_BASE + 19; /* The server is currently out of the requested resource. */
|
||||
/* UNUSED BASE + 20 */
|
||||
public static final int NERR_TooManyItems = NERR_BASE + 21; /* Requested addition of items exceeds the maximum allowed. */
|
||||
public static final int NERR_InvalidMaxUsers = NERR_BASE + 22; /* The Peer service supports only two simultaneous users. */
|
||||
public static final int NERR_BufTooSmall = NERR_BASE + 23; /* The API return buffer is too small. */
|
||||
/* UNUSED BASE + 24 */
|
||||
/* UNUSED BASE + 25 */
|
||||
/* UNUSED BASE + 26 */
|
||||
public static final int NERR_RemoteErr = NERR_BASE + 27; /* A remote API error occurred. */
|
||||
/* UNUSED BASE + 28 */
|
||||
/* UNUSED BASE + 29 */
|
||||
/* UNUSED BASE + 30 */
|
||||
public static final int NERR_LanmanIniError = NERR_BASE + 31; /* An error occurred when opening or reading the configuration file. */
|
||||
/* UNUSED BASE + 32 */
|
||||
/* UNUSED BASE + 33 */
|
||||
/* UNUSED BASE + 34 */
|
||||
/* UNUSED BASE + 35 */
|
||||
public static final int NERR_NetworkError = NERR_BASE + 36; /* A general network error occurred. */
|
||||
public static final int NERR_WkstaInconsistentState = NERR_BASE + 37;
|
||||
/* The Workstation service is in an inconsistent state. Restart the computer before restarting the Workstation service. */
|
||||
public static final int NERR_WkstaNotStarted = NERR_BASE + 38; /* The Workstation service has not been started. */
|
||||
public static final int NERR_BrowserNotStarted = NERR_BASE + 39; /* The requested information is not available. */
|
||||
public static final int NERR_InternalError = NERR_BASE + 40; /* An internal Windows error occurred.*/
|
||||
public static final int NERR_BadTransactConfig = NERR_BASE + 41; /* The server is not configured for transactions. */
|
||||
public static final int NERR_InvalidAPI = NERR_BASE + 42; /* The requested API is not supported on the remote server. */
|
||||
public static final int NERR_BadEventName = NERR_BASE + 43; /* The event name is invalid. */
|
||||
public static final int NERR_DupNameReboot = NERR_BASE + 44; /* The computer name already exists on the network. Change it and restart the computer. */
|
||||
/*
|
||||
* Config API related
|
||||
* Error codes from BASE + 45 to BASE + 49
|
||||
*/
|
||||
|
||||
/* UNUSED BASE + 45 */
|
||||
public static final int NERR_CfgCompNotFound = NERR_BASE + 46; /* The specified component could not be found in the configuration information. */
|
||||
public static final int NERR_CfgParamNotFound = NERR_BASE + 47; /* The specified parameter could not be found in the configuration information. */
|
||||
public static final int NERR_LineTooLong = NERR_BASE + 49; /* A line in the configuration file is too long. */
|
||||
|
||||
/*
|
||||
* Spooler API related
|
||||
* Error codes from BASE + 50 to BASE + 79
|
||||
*/
|
||||
|
||||
public static final int NERR_QNotFound = NERR_BASE + 50; /* The printer does not exist. */
|
||||
public static final int NERR_JobNotFound = NERR_BASE + 51; /* The print job does not exist. */
|
||||
public static final int NERR_DestNotFound = NERR_BASE + 52; /* The printer destination cannot be found. */
|
||||
public static final int NERR_DestExists = NERR_BASE + 53; /* The printer destination already exists. */
|
||||
public static final int NERR_QExists = NERR_BASE + 54; /* The printer queue already exists. */
|
||||
public static final int NERR_QNoRoom = NERR_BASE + 55; /* No more printers can be added. */
|
||||
public static final int NERR_JobNoRoom = NERR_BASE + 56; /* No more print jobs can be added. */
|
||||
public static final int NERR_DestNoRoom = NERR_BASE + 57; /* No more printer destinations can be added. */
|
||||
public static final int NERR_DestIdle = NERR_BASE + 58; /* This printer destination is idle and cannot accept control operations. */
|
||||
public static final int NERR_DestInvalidOp = NERR_BASE + 59; /* This printer destination request contains an invalid control function. */
|
||||
public static final int NERR_ProcNoRespond = NERR_BASE + 60; /* The print processor is not responding. */
|
||||
public static final int NERR_SpoolerNotLoaded = NERR_BASE + 61; /* The spooler is not running. */
|
||||
public static final int NERR_DestInvalidState = NERR_BASE + 62; /* This operation cannot be performed on the print destination in its current state. */
|
||||
public static final int NERR_QInvalidState = NERR_BASE + 63; /* This operation cannot be performed on the printer queue in its current state. */
|
||||
public static final int NERR_JobInvalidState = NERR_BASE + 64; /* This operation cannot be performed on the print job in its current state. */
|
||||
public static final int NERR_SpoolNoMemory = NERR_BASE + 65; /* A spooler memory allocation failure occurred. */
|
||||
public static final int NERR_DriverNotFound = NERR_BASE + 66; /* The device driver does not exist. */
|
||||
public static final int NERR_DataTypeInvalid = NERR_BASE + 67; /* The data type is not supported by the print processor. */
|
||||
public static final int NERR_ProcNotFound = NERR_BASE + 68; /* The print processor is not installed. */
|
||||
|
||||
/*
|
||||
* Service API related
|
||||
* Error codes from BASE + 80 to BASE + 99
|
||||
*/
|
||||
|
||||
public static final int NERR_ServiceTableLocked = NERR_BASE + 80; /* The service database is locked. */
|
||||
public static final int NERR_ServiceTableFull = NERR_BASE + 81; /* The service table is full. */
|
||||
public static final int NERR_ServiceInstalled = NERR_BASE + 82; /* The requested service has already been started. */
|
||||
public static final int NERR_ServiceEntryLocked = NERR_BASE + 83; /* The service does not respond to control actions. */
|
||||
public static final int NERR_ServiceNotInstalled = NERR_BASE + 84; /* The service has not been started. */
|
||||
public static final int NERR_BadServiceName = NERR_BASE + 85; /* The service name is invalid. */
|
||||
public static final int NERR_ServiceCtlTimeout = NERR_BASE + 86; /* The service is not responding to the control function. */
|
||||
public static final int NERR_ServiceCtlBusy = NERR_BASE + 87; /* The service control is busy. */
|
||||
public static final int NERR_BadServiceProgName = NERR_BASE + 88; /* The configuration file contains an invalid service program name. */
|
||||
public static final int NERR_ServiceNotCtrl = NERR_BASE + 89; /* The service could not be controlled in its present state. */
|
||||
public static final int NERR_ServiceKillProc = NERR_BASE + 90; /* The service ended abnormally. */
|
||||
public static final int NERR_ServiceCtlNotValid = NERR_BASE + 91; /* The requested pause, continue, or stop is not valid for this service. */
|
||||
public static final int NERR_NotInDispatchTbl = NERR_BASE + 92; /* The service control dispatcher could not find the service name in the dispatch table. */
|
||||
public static final int NERR_BadControlRecv = NERR_BASE + 93; /* The service control dispatcher pipe read failed. */
|
||||
public static final int NERR_ServiceNotStarting = NERR_BASE + 94; /* A thread for the new service could not be created. */
|
||||
|
||||
/*
|
||||
* Wksta and Logon API related
|
||||
* Error codes from BASE + 100 to BASE + 118
|
||||
*/
|
||||
|
||||
public static final int NERR_AlreadyLoggedOn = NERR_BASE + 100; /* This workstation is already logged on to the local-area network. */
|
||||
public static final int NERR_NotLoggedOn = NERR_BASE + 101; /* The workstation is not logged on to the local-area network. */
|
||||
public static final int NERR_BadUsername = NERR_BASE + 102; /* The user name or group name parameter is invalid. */
|
||||
public static final int NERR_BadPassword = NERR_BASE + 103; /* The password parameter is invalid. */
|
||||
public static final int NERR_UnableToAddName_W = NERR_BASE + 104; /* @W The logon processor did not add the message alias. */
|
||||
public static final int NERR_UnableToAddName_F = NERR_BASE + 105; /* The logon processor did not add the message alias. */
|
||||
public static final int NERR_UnableToDelName_W = NERR_BASE + 106; /* @W The logoff processor did not delete the message alias. */
|
||||
public static final int NERR_UnableToDelName_F = NERR_BASE + 107; /* The logoff processor did not delete the message alias. */
|
||||
/* UNUSED BASE + 108 */
|
||||
public static final int NERR_LogonsPaused = NERR_BASE + 109; /* Network logons are paused. */
|
||||
public static final int NERR_LogonServerConflict = NERR_BASE + 110;/* A centralized logon-server conflict occurred. */
|
||||
public static final int NERR_LogonNoUserPath = NERR_BASE + 111; /* The server is configured without a valid user path. */
|
||||
public static final int NERR_LogonScriptError = NERR_BASE + 112; /* An error occurred while loading or running the logon script. */
|
||||
/* UNUSED BASE + 113 */
|
||||
public static final int NERR_StandaloneLogon = NERR_BASE + 114; /* The logon server was not specified. Your computer will be logged on as STANDALONE. */
|
||||
public static final int NERR_LogonServerNotFound = NERR_BASE + 115; /* The logon server could not be found. */
|
||||
public static final int NERR_LogonDomainExists = NERR_BASE + 116; /* There is already a logon domain for this computer. */
|
||||
public static final int NERR_NonValidatedLogon = NERR_BASE + 117; /* The logon server could not validate the logon. */
|
||||
|
||||
/*
|
||||
* ACF API related = access, user, group;
|
||||
* Error codes from BASE + 119 to BASE + 149
|
||||
*/
|
||||
|
||||
public static final int NERR_ACFNotFound = NERR_BASE + 119; /* The security database could not be found. */
|
||||
public static final int NERR_GroupNotFound = NERR_BASE + 120; /* The group name could not be found. */
|
||||
public static final int NERR_UserNotFound = NERR_BASE + 121; /* The user name could not be found. */
|
||||
public static final int NERR_ResourceNotFound = NERR_BASE + 122; /* The resource name could not be found. */
|
||||
public static final int NERR_GroupExists = NERR_BASE + 123; /* The group already exists. */
|
||||
public static final int NERR_UserExists = NERR_BASE + 124; /* The account already exists. */
|
||||
public static final int NERR_ResourceExists = NERR_BASE + 125; /* The resource permission list already exists. */
|
||||
public static final int NERR_NotPrimary = NERR_BASE + 126; /* This operation is only allowed on the primary domain controller of the domain. */
|
||||
public static final int NERR_ACFNotLoaded = NERR_BASE + 127; /* The security database has not been started. */
|
||||
public static final int NERR_ACFNoRoom = NERR_BASE + 128; /* There are too many names in the user accounts database. */
|
||||
public static final int NERR_ACFFileIOFail = NERR_BASE + 129; /* A disk I/O failure occurred.*/
|
||||
public static final int NERR_ACFTooManyLists = NERR_BASE + 130; /* The limit of 64 entries per resource was exceeded. */
|
||||
public static final int NERR_UserLogon = NERR_BASE + 131; /* Deleting a user with a session is not allowed. */
|
||||
public static final int NERR_ACFNoParent = NERR_BASE + 132; /* The parent directory could not be located. */
|
||||
public static final int NERR_CanNotGrowSegment = NERR_BASE + 133; /* Unable to add to the security database session cache segment. */
|
||||
public static final int NERR_SpeGroupOp = NERR_BASE + 134; /* This operation is not allowed on this special group. */
|
||||
public static final int NERR_NotInCache = NERR_BASE + 135; /* This user is not cached in user accounts database session cache. */
|
||||
public static final int NERR_UserInGroup = NERR_BASE + 136; /* The user already belongs to this group. */
|
||||
public static final int NERR_UserNotInGroup = NERR_BASE + 137; /* The user does not belong to this group. */
|
||||
public static final int NERR_AccountUndefined = NERR_BASE + 138; /* This user account is undefined. */
|
||||
public static final int NERR_AccountExpired = NERR_BASE + 139; /* This user account has expired. */
|
||||
public static final int NERR_InvalidWorkstation = NERR_BASE + 140; /* The user is not allowed to log on from this workstation. */
|
||||
public static final int NERR_InvalidLogonHours = NERR_BASE + 141; /* The user is not allowed to log on at this time. */
|
||||
public static final int NERR_PasswordExpired = NERR_BASE + 142; /* The password of this user has expired. */
|
||||
public static final int NERR_PasswordCantChange = NERR_BASE + 143; /* The password of this user cannot change. */
|
||||
public static final int NERR_PasswordHistConflict = NERR_BASE + 144; /* This password cannot be used now. */
|
||||
public static final int NERR_PasswordTooShort = NERR_BASE + 145; /* The password does not meet the password policy requirements. Check the minimum password length, password complexity and password history requirements. */
|
||||
public static final int NERR_PasswordTooRecent = NERR_BASE + 146; /* The password of this user is too recent to change. */
|
||||
public static final int NERR_InvalidDatabase = NERR_BASE + 147; /* The security database is corrupted. */
|
||||
public static final int NERR_DatabaseUpToDate = NERR_BASE + 148; /* No updates are necessary to this replicant network/local security database. */
|
||||
public static final int NERR_SyncRequired = NERR_BASE + 149; /* This replicant database is outdated; synchronization is required. */
|
||||
|
||||
/*
|
||||
* Use API related
|
||||
* Error codes from BASE + 150 to BASE + 169
|
||||
*/
|
||||
|
||||
public static final int NERR_UseNotFound = NERR_BASE + 150; /* The network connection could not be found. */
|
||||
public static final int NERR_BadAsgType = NERR_BASE + 151; /* This asg_type is invalid. */
|
||||
public static final int NERR_DeviceIsShared = NERR_BASE + 152; /* This device is currently being shared. */
|
||||
public static final int NERR_SameAsComputerName = NERR_BASE + 153; /* The user name may not be same as computer name. */
|
||||
|
||||
|
||||
/*
|
||||
* Message Server related
|
||||
* Error codes BASE + 170 to BASE + 209
|
||||
*/
|
||||
|
||||
public static final int NERR_NoComputerName = NERR_BASE + 170; /* The computer name could not be added as a message alias. The name may already exist on the network. */
|
||||
public static final int NERR_MsgAlreadyStarted = NERR_BASE + 171; /* The Messenger service is already started. */
|
||||
public static final int NERR_MsgInitFailed = NERR_BASE + 172; /* The Messenger service failed to start. */
|
||||
public static final int NERR_NameNotFound = NERR_BASE + 173; /* The message alias could not be found on the network. */
|
||||
public static final int NERR_AlreadyForwarded = NERR_BASE + 174; /* This message alias has already been forwarded. */
|
||||
public static final int NERR_AddForwarded = NERR_BASE + 175; /* This message alias has been added but is still forwarded. */
|
||||
public static final int NERR_AlreadyExists = NERR_BASE + 176; /* This message alias already exists locally. */
|
||||
public static final int NERR_TooManyNames = NERR_BASE + 177; /* The maximum number of added message aliases has been exceeded. */
|
||||
public static final int NERR_DelComputerName = NERR_BASE + 178; /* The computer name could not be deleted.*/
|
||||
public static final int NERR_LocalForward = NERR_BASE + 179; /* Messages cannot be forwarded back to the same workstation. */
|
||||
public static final int NERR_GrpMsgProcessor = NERR_BASE + 180; /* An error occurred in the domain message processor. */
|
||||
public static final int NERR_PausedRemote = NERR_BASE + 181; /* The message was sent, but the recipient has paused the Messenger service. */
|
||||
public static final int NERR_BadReceive = NERR_BASE + 182; /* The message was sent but not received. */
|
||||
public static final int NERR_NameInUse = NERR_BASE + 183; /* The message alias is currently in use. Try again later. */
|
||||
public static final int NERR_MsgNotStarted = NERR_BASE + 184; /* The Messenger service has not been started. */
|
||||
public static final int NERR_NotLocalName = NERR_BASE + 185; /* The name is not on the local computer. */
|
||||
public static final int NERR_NoForwardName = NERR_BASE + 186; /* The forwarded message alias could not be found on the network. */
|
||||
public static final int NERR_RemoteFull = NERR_BASE + 187; /* The message alias table on the remote station is full. */
|
||||
public static final int NERR_NameNotForwarded = NERR_BASE + 188; /* Messages for this alias are not currently being forwarded. */
|
||||
public static final int NERR_TruncatedBroadcast = NERR_BASE + 189; /* The broadcast message was truncated. */
|
||||
public static final int NERR_InvalidDevice = NERR_BASE + 194; /* This is an invalid device name. */
|
||||
public static final int NERR_WriteFault = NERR_BASE + 195; /* A write fault occurred. */
|
||||
/* UNUSED BASE + 196 */
|
||||
public static final int NERR_DuplicateName = NERR_BASE + 197; /* A duplicate message alias exists on the network. */
|
||||
public static final int NERR_DeleteLater = NERR_BASE + 198; /* @W This message alias will be deleted later. */
|
||||
public static final int NERR_IncompleteDel = NERR_BASE + 199; /* The message alias was not successfully deleted from all networks. */
|
||||
public static final int NERR_MultipleNets = NERR_BASE + 200; /* This operation is not supported on computers with multiple networks. */
|
||||
|
||||
/*
|
||||
* Server API related
|
||||
* Error codes BASE + 210 to BASE + 229
|
||||
*/
|
||||
|
||||
public static final int NERR_NetNameNotFound = NERR_BASE + 210; /* This shared resource does not exist.*/
|
||||
public static final int NERR_DeviceNotShared = NERR_BASE + 211; /* This device is not shared. */
|
||||
public static final int NERR_ClientNameNotFound = NERR_BASE + 212; /* A session does not exist with that computer name. */
|
||||
public static final int NERR_FileIdNotFound = NERR_BASE + 214; /* There is not an open file with that identification number. */
|
||||
public static final int NERR_ExecFailure = NERR_BASE + 215; /* A failure occurred when executing a remote administration command. */
|
||||
public static final int NERR_TmpFile = NERR_BASE + 216; /* A failure occurred when opening a remote temporary file. */
|
||||
public static final int NERR_TooMuchData = NERR_BASE + 217; /* The data returned from a remote administration command has been truncated to 64K. */
|
||||
public static final int NERR_DeviceShareConflict = NERR_BASE + 218; /* This device cannot be shared as both a spooled and a non-spooled resource. */
|
||||
public static final int NERR_BrowserTableIncomplete = NERR_BASE + 219; /* The information in the list of servers may be incorrect. */
|
||||
public static final int NERR_NotLocalDomain = NERR_BASE + 220; /* The computer is not active in this domain. */
|
||||
public static final int NERR_IsDfsShare = NERR_BASE + 221; /* The share must be removed from the Distributed File System before it can be deleted. */
|
||||
|
||||
/*
|
||||
* CharDev API related
|
||||
* Error codes BASE + 230 to BASE + 249
|
||||
*/
|
||||
|
||||
/* UNUSED BASE + 230 */
|
||||
public static final int NERR_DevInvalidOpCode = NERR_BASE + 231; /* The operation is invalid for this device. */
|
||||
public static final int NERR_DevNotFound = NERR_BASE + 232; /* This device cannot be shared. */
|
||||
public static final int NERR_DevNotOpen = NERR_BASE + 233; /* This device was not open. */
|
||||
public static final int NERR_BadQueueDevString = NERR_BASE + 234; /* This device name list is invalid. */
|
||||
public static final int NERR_BadQueuePriority = NERR_BASE + 235; /* The queue priority is invalid. */
|
||||
public static final int NERR_NoCommDevs = NERR_BASE + 237; /* There are no shared communication devices. */
|
||||
public static final int NERR_QueueNotFound = NERR_BASE + 238; /* The queue you specified does not exist. */
|
||||
public static final int NERR_BadDevString = NERR_BASE + 240; /* This list of devices is invalid. */
|
||||
public static final int NERR_BadDev = NERR_BASE + 241; /* The requested device is invalid. */
|
||||
public static final int NERR_InUseBySpooler = NERR_BASE + 242; /* This device is already in use by the spooler. */
|
||||
public static final int NERR_CommDevInUse = NERR_BASE + 243; /* This device is already in use as a communication device. */
|
||||
|
||||
/*
|
||||
* NetICanonicalize and NetIType and NetIMakeLMFileName
|
||||
* NetIListCanon and NetINameCheck
|
||||
* Error codes BASE + 250 to BASE + 269
|
||||
*/
|
||||
|
||||
public static final int NERR_InvalidComputer = NERR_BASE + 251; /* This computer name is invalid. */
|
||||
/* UNUSED BASE + 252 */
|
||||
/* UNUSED BASE + 253 */
|
||||
public static final int NERR_MaxLenExceeded = NERR_BASE + 254; /* The string and prefix specified are too long. */
|
||||
/* UNUSED BASE + 255 */
|
||||
public static final int NERR_BadComponent = NERR_BASE + 256; /* This path component is invalid. */
|
||||
public static final int NERR_CantType = NERR_BASE + 257; /* Could not determine the type of input. */
|
||||
/* UNUSED BASE + 258 */
|
||||
/* UNUSED BASE + 259 */
|
||||
public static final int NERR_TooManyEntries = NERR_BASE + 262; /* The buffer for types is not big enough. */
|
||||
|
||||
/*
|
||||
* NetProfile
|
||||
* Error codes BASE + 270 to BASE + 276
|
||||
*/
|
||||
|
||||
public static final int NERR_ProfileFileTooBig = NERR_BASE + 270; /* Profile files cannot exceed 64K. */
|
||||
public static final int NERR_ProfileOffset = NERR_BASE + 271; /* The start offset is out of range. */
|
||||
public static final int NERR_ProfileCleanup = NERR_BASE + 272; /* The system cannot delete current connections to network resources. */
|
||||
public static final int NERR_ProfileUnknownCmd = NERR_BASE + 273; /* The system was unable to parse the command line in this file.*/
|
||||
public static final int NERR_ProfileLoadErr = NERR_BASE + 274; /* An error occurred while loading the profile file. */
|
||||
public static final int NERR_ProfileSaveErr = NERR_BASE + 275; /* @W Errors occurred while saving the profile file. The profile was partially saved. */
|
||||
|
||||
|
||||
/*
|
||||
* NetAudit and NetErrorLog
|
||||
* Error codes BASE + 277 to BASE + 279
|
||||
*/
|
||||
|
||||
public static final int NERR_LogOverflow = NERR_BASE + 277; /* Log file %1 is full. */
|
||||
public static final int NERR_LogFileChanged = NERR_BASE + 278; /* This log file has changed between reads. */
|
||||
public static final int NERR_LogFileCorrupt = NERR_BASE + 279; /* Log file %1 is corrupt. */
|
||||
|
||||
|
||||
/*
|
||||
* NetRemote
|
||||
* Error codes BASE + 280 to BASE + 299
|
||||
*/
|
||||
public static final int NERR_SourceIsDir = NERR_BASE + 280; /* The source path cannot be a directory. */
|
||||
public static final int NERR_BadSource = NERR_BASE + 281; /* The source path is illegal. */
|
||||
public static final int NERR_BadDest = NERR_BASE + 282; /* The destination path is illegal. */
|
||||
public static final int NERR_DifferentServers = NERR_BASE + 283; /* The source and destination paths are on different servers. */
|
||||
/* UNUSED BASE + 284 */
|
||||
public static final int NERR_RunSrvPaused = NERR_BASE + 285; /* The Run server you requested is paused. */
|
||||
/* UNUSED BASE + 286 */
|
||||
/* UNUSED BASE + 287 */
|
||||
/* UNUSED BASE + 288 */
|
||||
public static final int NERR_ErrCommRunSrv = NERR_BASE + 289; /* An error occurred when communicating with a Run server. */
|
||||
/* UNUSED BASE + 290 */
|
||||
public static final int NERR_ErrorExecingGhost = NERR_BASE + 291; /* An error occurred when starting a background process. */
|
||||
public static final int NERR_ShareNotFound = NERR_BASE + 292; /* The shared resource you are connected to could not be found.*/
|
||||
/* UNUSED BASE + 293 */
|
||||
/* UNUSED BASE + 294 */
|
||||
|
||||
|
||||
/*
|
||||
* NetWksta.sys = redir; returned error codes.
|
||||
*
|
||||
* NERR_BASE + = 300-329;
|
||||
*/
|
||||
|
||||
public static final int NERR_InvalidLana = NERR_BASE + 300; /* The LAN adapter number is invalid. */
|
||||
public static final int NERR_OpenFiles = NERR_BASE + 301; /* There are open files on the connection. */
|
||||
public static final int NERR_ActiveConns = NERR_BASE + 302; /* Active connections still exist. */
|
||||
public static final int NERR_BadPasswordCore = NERR_BASE + 303; /* This share name or password is invalid. */
|
||||
public static final int NERR_DevInUse = NERR_BASE + 304; /* The device is being accessed by an active process. */
|
||||
public static final int NERR_LocalDrive = NERR_BASE + 305; /* The drive letter is in use locally. */
|
||||
|
||||
/*
|
||||
* Alert error codes.
|
||||
*
|
||||
* NERR_BASE + = 330-339;
|
||||
*/
|
||||
public static final int NERR_AlertExists = NERR_BASE + 330; /* The specified client is already registered for the specified event. */
|
||||
public static final int NERR_TooManyAlerts = NERR_BASE + 331; /* The alert table is full. */
|
||||
public static final int NERR_NoSuchAlert = NERR_BASE + 332; /* An invalid or nonexistent alert name was raised. */
|
||||
public static final int NERR_BadRecipient = NERR_BASE + 333; /* The alert recipient is invalid.*/
|
||||
public static final int NERR_AcctLimitExceeded = NERR_BASE + 334; /* A user's session with this server has been deleted
|
||||
* because the user's logon hours are no longer valid. */
|
||||
|
||||
/*
|
||||
* Additional Error and Audit log codes.
|
||||
*
|
||||
* NERR_BASE + (340-343;
|
||||
*/
|
||||
public static final int NERR_InvalidLogSeek = NERR_BASE + 340; /* The log file does not contain the requested record number. */
|
||||
/* UNUSED BASE + 341 */
|
||||
/* UNUSED BASE + 342 */
|
||||
/* UNUSED BASE + 343 */
|
||||
|
||||
/*
|
||||
* Additional UAS and NETLOGON codes
|
||||
*
|
||||
* NERR_BASE + (350-359;
|
||||
*/
|
||||
public static final int NERR_BadUasConfig = NERR_BASE + 350; /* The user accounts database is not configured correctly. */
|
||||
public static final int NERR_InvalidUASOp = NERR_BASE + 351; /* This operation is not permitted when the Netlogon service is running. */
|
||||
public static final int NERR_LastAdmin = NERR_BASE + 352; /* This operation is not allowed on the last administrative account. */
|
||||
public static final int NERR_DCNotFound = NERR_BASE + 353; /* Could not find domain controller for this domain. */
|
||||
public static final int NERR_LogonTrackingError = NERR_BASE + 354; /* Could not set logon information for this user. */
|
||||
public static final int NERR_NetlogonNotStarted = NERR_BASE + 355; /* The Netlogon service has not been started. */
|
||||
public static final int NERR_CanNotGrowUASFile = NERR_BASE + 356; /* Unable to add to the user accounts database. */
|
||||
public static final int NERR_TimeDiffAtDC = NERR_BASE + 357; /* This server's clock is not synchronized with the primary domain controller's clock. */
|
||||
public static final int NERR_PasswordMismatch = NERR_BASE + 358; /* A password mismatch has been detected. */
|
||||
|
||||
|
||||
/*
|
||||
* Server Integration error codes.
|
||||
*
|
||||
* NERR_BASE + (360-369;
|
||||
*/
|
||||
public static final int NERR_NoSuchServer = NERR_BASE + 360; /* The server identification does not specify a valid server. */
|
||||
public static final int NERR_NoSuchSession = NERR_BASE + 361; /* The session identification does not specify a valid session. */
|
||||
public static final int NERR_NoSuchConnection = NERR_BASE + 362; /* The connection identification does not specify a valid connection. */
|
||||
public static final int NERR_TooManyServers = NERR_BASE + 363; /* There is no space for another entry in the table of available servers. */
|
||||
public static final int NERR_TooManySessions = NERR_BASE + 364; /* The server has reached the maximum number of sessions it supports. */
|
||||
public static final int NERR_TooManyConnections = NERR_BASE + 365; /* The server has reached the maximum number of connections it supports. */
|
||||
public static final int NERR_TooManyFiles = NERR_BASE + 366; /* The server cannot open more files because it has reached its maximum number. */
|
||||
public static final int NERR_NoAlternateServers = NERR_BASE + 367; /* There are no alternate servers registered on this server. */
|
||||
/* UNUSED BASE + 368 */
|
||||
/* UNUSED BASE + 369 */
|
||||
|
||||
public static final int NERR_TryDownLevel = NERR_BASE + 370; /* Try down-level = remote admin protocol; version of API instead. */
|
||||
|
||||
/*
|
||||
* UPS error codes.
|
||||
*
|
||||
* NERR_BASE + = 380-384;
|
||||
*/
|
||||
public static final int NERR_UPSDriverNotStarted = NERR_BASE + 380; /* The UPS driver could not be accessed by the UPS service. */
|
||||
public static final int NERR_UPSInvalidConfig = NERR_BASE + 381; /* The UPS service is not configured correctly. */
|
||||
public static final int NERR_UPSInvalidCommPort = NERR_BASE + 382; /* The UPS service could not access the specified Comm Port. */
|
||||
public static final int NERR_UPSSignalAsserted = NERR_BASE + 383; /* The UPS indicated a line fail or low battery situation. Service not started. */
|
||||
public static final int NERR_UPSShutdownFailed = NERR_BASE + 384; /* The UPS service failed to perform a system shut down. */
|
||||
|
||||
/*
|
||||
* Remoteboot error codes.
|
||||
*
|
||||
* NERR_BASE + = 400-419;
|
||||
* Error codes 400 - 405 are used by RPLBOOT.SYS.
|
||||
* Error codes 403, 407 - 416 are used by RPLLOADR.COM,
|
||||
* Error code 417 is the alerter message of REMOTEBOOT = RPLSERVR.EXE;.
|
||||
* Error code 418 is for when REMOTEBOOT can't start
|
||||
* Error code 419 is for a disallowed 2nd rpl connection
|
||||
*
|
||||
*/
|
||||
public static final int NERR_BadDosRetCode = NERR_BASE + 400; /* The program below returned an MS-DOS error code:*/
|
||||
public static final int NERR_ProgNeedsExtraMem = NERR_BASE + 401; /* The program below needs more memory:*/
|
||||
public static final int NERR_BadDosFunction = NERR_BASE + 402; /* The program below called an unsupported MS-DOS function:*/
|
||||
public static final int NERR_RemoteBootFailed = NERR_BASE + 403; /* The workstation failed to boot.*/
|
||||
public static final int NERR_BadFileCheckSum = NERR_BASE + 404; /* The file below is corrupt.*/
|
||||
public static final int NERR_NoRplBootSystem = NERR_BASE + 405; /* No loader is specified in the boot-block definition file.*/
|
||||
public static final int NERR_RplLoadrNetBiosErr = NERR_BASE + 406; /* NetBIOS returned an error: The NCB and SMB are dumped above.*/
|
||||
public static final int NERR_RplLoadrDiskErr = NERR_BASE + 407; /* A disk I/O error occurred.*/
|
||||
public static final int NERR_ImageParamErr = NERR_BASE + 408; /* Image parameter substitution failed.*/
|
||||
public static final int NERR_TooManyImageParams = NERR_BASE + 409; /* Too many image parameters cross disk sector boundaries.*/
|
||||
public static final int NERR_NonDosFloppyUsed = NERR_BASE + 410; /* The image was not generated from an MS-DOS diskette formatted with /S.*/
|
||||
public static final int NERR_RplBootRestart = NERR_BASE + 411; /* Remote boot will be restarted later.*/
|
||||
public static final int NERR_RplSrvrCallFailed = NERR_BASE + 412; /* The call to the Remoteboot server failed.*/
|
||||
public static final int NERR_CantConnectRplSrvr = NERR_BASE + 413; /* Cannot connect to the Remoteboot server.*/
|
||||
public static final int NERR_CantOpenImageFile = NERR_BASE + 414; /* Cannot open image file on the Remoteboot server.*/
|
||||
public static final int NERR_CallingRplSrvr = NERR_BASE + 415; /* Connecting to the Remoteboot server...*/
|
||||
public static final int NERR_StartingRplBoot = NERR_BASE + 416; /* Connecting to the Remoteboot server...*/
|
||||
public static final int NERR_RplBootServiceTerm = NERR_BASE + 417; /* Remote boot service was stopped; check the error log for the cause of the problem.*/
|
||||
public static final int NERR_RplBootStartFailed = NERR_BASE + 418; /* Remote boot startup failed; check the error log for the cause of the problem.*/
|
||||
public static final int NERR_RPL_CONNECTED = NERR_BASE + 419; /* A second connection to a Remoteboot resource is not allowed.*/
|
||||
|
||||
/*
|
||||
* FTADMIN API error codes
|
||||
*
|
||||
* NERR_BASE + = 425-434;
|
||||
*
|
||||
* = Currently not used in NT;
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Browser service API error codes
|
||||
*
|
||||
* NERR_BASE + = 450-475;
|
||||
*
|
||||
*/
|
||||
public static final int NERR_BrowserConfiguredToNotRun = NERR_BASE + 450; /* The browser service was configured with MaintainServerList = No. */
|
||||
|
||||
/*
|
||||
* Additional Remoteboot error codes.
|
||||
*
|
||||
* NERR_BASE + = 510-550;
|
||||
*/
|
||||
public static final int NERR_RplNoAdaptersStarted = NERR_BASE + 510; /*Service failed to start since none of the network adapters started with this service.*/
|
||||
public static final int NERR_RplBadRegistry = NERR_BASE + 511; /*Service failed to start due to bad startup information in the registry.*/
|
||||
public static final int NERR_RplBadDatabase = NERR_BASE + 512; /*Service failed to start because its database is absent or corrupt.*/
|
||||
public static final int NERR_RplRplfilesShare = NERR_BASE + 513; /*Service failed to start because RPLFILES share is absent.*/
|
||||
public static final int NERR_RplNotRplServer = NERR_BASE + 514; /*Service failed to start because RPLUSER group is absent.*/
|
||||
public static final int NERR_RplCannotEnum = NERR_BASE + 515; /*Cannot enumerate service records.*/
|
||||
public static final int NERR_RplWkstaInfoCorrupted = NERR_BASE + 516; /*Workstation record information has been corrupted.*/
|
||||
public static final int NERR_RplWkstaNotFound = NERR_BASE + 517; /*Workstation record was not found.*/
|
||||
public static final int NERR_RplWkstaNameUnavailable = NERR_BASE + 518; /*Workstation name is in use by some other workstation.*/
|
||||
public static final int NERR_RplProfileInfoCorrupted = NERR_BASE + 519; /*Profile record information has been corrupted.*/
|
||||
public static final int NERR_RplProfileNotFound = NERR_BASE + 520; /*Profile record was not found.*/
|
||||
public static final int NERR_RplProfileNameUnavailable = NERR_BASE + 521; /*Profile name is in use by some other profile.*/
|
||||
public static final int NERR_RplProfileNotEmpty = NERR_BASE + 522; /*There are workstations using this profile.*/
|
||||
public static final int NERR_RplConfigInfoCorrupted = NERR_BASE + 523; /*Configuration record information has been corrupted.*/
|
||||
public static final int NERR_RplConfigNotFound = NERR_BASE + 524; /*Configuration record was not found.*/
|
||||
public static final int NERR_RplAdapterInfoCorrupted = NERR_BASE + 525; /*Adapter id record information has been corrupted.*/
|
||||
public static final int NERR_RplInternal = NERR_BASE + 526; /*An internal service error has occurred.*/
|
||||
public static final int NERR_RplVendorInfoCorrupted = NERR_BASE + 527; /*Vendor id record information has been corrupted.*/
|
||||
public static final int NERR_RplBootInfoCorrupted = NERR_BASE + 528; /*Boot block record information has been corrupted.*/
|
||||
public static final int NERR_RplWkstaNeedsUserAcct = NERR_BASE + 529; /*The user account for this workstation record is missing.*/
|
||||
public static final int NERR_RplNeedsRPLUSERAcct = NERR_BASE + 530; /*The RPLUSER local group could not be found.*/
|
||||
public static final int NERR_RplBootNotFound = NERR_BASE + 531; /*Boot block record was not found.*/
|
||||
public static final int NERR_RplIncompatibleProfile = NERR_BASE + 532; /*Chosen profile is incompatible with this workstation.*/
|
||||
public static final int NERR_RplAdapterNameUnavailable = NERR_BASE + 533; /*Chosen network adapter id is in use by some other workstation.*/
|
||||
public static final int NERR_RplConfigNotEmpty = NERR_BASE + 534; /*There are profiles using this configuration.*/
|
||||
public static final int NERR_RplBootInUse = NERR_BASE + 535; /*There are workstations, profiles or configurations using this boot block.*/
|
||||
public static final int NERR_RplBackupDatabase = NERR_BASE + 536; /*Service failed to backup Remoteboot database.*/
|
||||
public static final int NERR_RplAdapterNotFound = NERR_BASE + 537; /*Adapter record was not found.*/
|
||||
public static final int NERR_RplVendorNotFound = NERR_BASE + 538; /*Vendor record was not found.*/
|
||||
public static final int NERR_RplVendorNameUnavailable = NERR_BASE + 539; /*Vendor name is in use by some other vendor record.*/
|
||||
public static final int NERR_RplBootNameUnavailable = NERR_BASE + 540; /*(boot name, vendor id; is in use by some other boot block record.*/
|
||||
public static final int NERR_RplConfigNameUnavailable = NERR_BASE + 541; /*Configuration name is in use by some other configuration.*/
|
||||
|
||||
/**INTERNAL_ONLY**/
|
||||
|
||||
/*
|
||||
* Dfs API error codes.
|
||||
*
|
||||
* NERR_BASE + = 560-590;
|
||||
*/
|
||||
|
||||
public static final int NERR_DfsInternalCorruption = NERR_BASE + 560; /*The internal database maintained by the DFS service is corrupt*/
|
||||
public static final int NERR_DfsVolumeDataCorrupt = NERR_BASE + 561; /*One of the records in the internal DFS database is corrupt*/
|
||||
public static final int NERR_DfsNoSuchVolume = NERR_BASE + 562; /*There is no DFS name whose entry path matches the input Entry Path*/
|
||||
public static final int NERR_DfsVolumeAlreadyExists = NERR_BASE + 563; /*A root or link with the given name already exists*/
|
||||
public static final int NERR_DfsAlreadyShared = NERR_BASE + 564; /*The server share specified is already shared in the DFS*/
|
||||
public static final int NERR_DfsNoSuchShare = NERR_BASE + 565; /*The indicated server share does not support the indicated DFS namespace*/
|
||||
public static final int NERR_DfsNotALeafVolume = NERR_BASE + 566; /*The operation is not valid on this portion of the namespace*/
|
||||
public static final int NERR_DfsLeafVolume = NERR_BASE + 567; /*The operation is not valid on this portion of the namespace*/
|
||||
public static final int NERR_DfsVolumeHasMultipleServers = NERR_BASE + 568; /*The operation is ambiguous because the link has multiple servers*/
|
||||
public static final int NERR_DfsCantCreateJunctionPoint = NERR_BASE + 569; /*Unable to create a link*/
|
||||
public static final int NERR_DfsServerNotDfsAware = NERR_BASE + 570; /*The server is not DFS Aware*/
|
||||
public static final int NERR_DfsBadRenamePath = NERR_BASE + 571; /*The specified rename target path is invalid*/
|
||||
public static final int NERR_DfsVolumeIsOffline = NERR_BASE + 572; /*The specified DFS link is offline*/
|
||||
public static final int NERR_DfsNoSuchServer = NERR_BASE + 573; /*The specified server is not a server for this link*/
|
||||
public static final int NERR_DfsCyclicalName = NERR_BASE + 574; /*A cycle in the DFS name was detected*/
|
||||
public static final int NERR_DfsNotSupportedInServerDfs = NERR_BASE + 575; /*The operation is not supported on a server-based DFS*/
|
||||
public static final int NERR_DfsDuplicateService = NERR_BASE + 576; /*This link is already supported by the specified server-share*/
|
||||
public static final int NERR_DfsCantRemoveLastServerShare = NERR_BASE + 577; /*Can't remove the last server-share supporting this root or link*/
|
||||
public static final int NERR_DfsVolumeIsInterDfs = NERR_BASE + 578; /*The operation is not supported for an Inter-DFS link*/
|
||||
public static final int NERR_DfsInconsistent = NERR_BASE + 579; /*The internal state of the DFS Service has become inconsistent*/
|
||||
public static final int NERR_DfsServerUpgraded = NERR_BASE + 580; /*The DFS Service has been installed on the specified server*/
|
||||
public static final int NERR_DfsDataIsIdentical = NERR_BASE + 581; /*The DFS data being reconciled is identical*/
|
||||
public static final int NERR_DfsCantRemoveDfsRoot = NERR_BASE + 582; /*The DFS root cannot be deleted - Uninstall DFS if required*/
|
||||
public static final int NERR_DfsChildOrParentInDfs = NERR_BASE + 583; /*A child or parent directory of the share is already in a DFS*/
|
||||
public static final int NERR_DfsInternalError = NERR_BASE + 590; /*DFS internal error*/
|
||||
|
||||
/*
|
||||
* Net setup error codes.
|
||||
*
|
||||
* NERR_BASE + = 591-600;
|
||||
*/
|
||||
public static final int NERR_SetupAlreadyJoined = NERR_BASE + 591; /*This machine is already joined to a domain.*/
|
||||
public static final int NERR_SetupNotJoined = NERR_BASE + 592; /*This machine is not currently joined to a domain.*/
|
||||
public static final int NERR_SetupDomainController = NERR_BASE + 593; /*This machine is a domain controller and cannot be unjoined from a domain.*/
|
||||
public static final int NERR_DefaultJoinRequired = NERR_BASE + 594; /*The destination domain controller does not support creating machine accounts in OUs.*/
|
||||
public static final int NERR_InvalidWorkgroupName = NERR_BASE + 595; /*The specified workgroup name is invalid.*/
|
||||
public static final int NERR_NameUsesIncompatibleCodePage = NERR_BASE + 596; /*The specified computer name is incompatible with the default language used on the domain controller.*/
|
||||
public static final int NERR_ComputerAccountNotFound = NERR_BASE + 597; /*The specified computer account could not be found. Contact an administrator to verify the account is in the domain. If the account has been deleted unjoin, reboot, and rejoin the domain.*/
|
||||
public static final int NERR_PersonalSku = NERR_BASE + 598; /*This version of Windows cannot be joined to a domain.*/
|
||||
public static final int NERR_SetupCheckDNSConfig = NERR_BASE + 599; /*An attempt to resolve the DNS name of a DC in the domain being joined has failed. Please verify this client is configured to reach a DNS server that can resolve DNS names in the target domain.*/
|
||||
|
||||
/*
|
||||
* Some Password and account error results
|
||||
*
|
||||
* NERR_BASE + = 601 - 608;
|
||||
*/
|
||||
public static final int NERR_PasswordMustChange = NERR_BASE + 601; /* Password must change at next logon */
|
||||
public static final int NERR_AccountLockedOut = NERR_BASE + 602; /* Account is locked out */
|
||||
public static final int NERR_PasswordTooLong = NERR_BASE + 603; /* Password is too long */
|
||||
public static final int NERR_PasswordNotComplexEnough = NERR_BASE + 604; /* Password doesn't meet the complexity policy */
|
||||
public static final int NERR_PasswordFilterError = NERR_BASE + 605; /* Password doesn't meet the requirements of the filter dll's */
|
||||
|
||||
/***********WARNING ****************
|
||||
*The range 2750-2799 has been *
|
||||
*allocated to the IBM LAN Server *
|
||||
***********************************/
|
||||
|
||||
/***********WARNING ****************
|
||||
*The range 2900-2999 has been *
|
||||
*reserved for Microsoft OEMs *
|
||||
***********************************/
|
||||
|
||||
public static final int MAX_NERR = NERR_BASE + 899; /* This is the last error in NERR range. */
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
/**
|
||||
* Ported from LMJoin.h.
|
||||
* Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface LMJoin {
|
||||
|
||||
/**
|
||||
* Status of a workstation.
|
||||
*/
|
||||
public abstract class NETSETUP_JOIN_STATUS {
|
||||
public static final int NetSetupUnknownStatus = 0;
|
||||
public static final int NetSetupUnjoined = 1;
|
||||
public static final int NetSetupWorkgroupName = 2;
|
||||
public static final int NetSetupDomainName = 3;
|
||||
};
|
||||
|
||||
}
|
||||
Alguns arquivos não foram exibidos porque demasiados arquivos foram alterados neste diff Mostrar Mais
Referência em uma Nova Issue
Bloquear um usuário