win32-xpath 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES +5 -2
- data/ext/win32/xpath.c +26 -20
- data/win32-xpath.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90f69c4379b494123344aafd8b6233c50517e0b4
|
4
|
+
data.tar.gz: 4ef3203f711bfd16ef2a8584be510c3b13cf27d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65817259cfad01b3cd2bd382168a9de2db81a83726181d44822ab2fc415d7e9ef987d895bbb4af1c37aa5863424ead5800492fdb9668e9f33f7d62b6ef1c771f
|
7
|
+
data.tar.gz: 2efba9b2ed51ca12132e86f8914aa3d03ea8eea7dce3c8f947053eb6a6331976da7d89e82aa0371804a4b06a52483c0aa7e03da0c9efcda6d9d5779d070b17c9
|
data/CHANGES
CHANGED
data/ext/win32/xpath.c
CHANGED
@@ -6,6 +6,12 @@
|
|
6
6
|
|
7
7
|
#define MAX_WPATH MAX_PATH * sizeof(wchar_t)
|
8
8
|
|
9
|
+
// Equivalent to raise SystemCallError.new(string, errnum)
|
10
|
+
void rb_raise_syserr(const char* msg, int errnum){
|
11
|
+
VALUE v_sys = rb_funcall(rb_eSystemCallError, rb_intern("new"), 2, rb_str_new2(msg), INT2FIX(errnum));
|
12
|
+
rb_funcall(rb_mKernel, rb_intern("raise"), 1, v_sys);
|
13
|
+
}
|
14
|
+
|
9
15
|
// Helper function to find user's home directory
|
10
16
|
wchar_t* find_user(wchar_t* str){
|
11
17
|
SID* sid;
|
@@ -39,25 +45,25 @@ wchar_t* find_user(wchar_t* str){
|
|
39
45
|
rb_raise(rb_eArgError, "can't find user %ls", str);
|
40
46
|
}
|
41
47
|
|
42
|
-
ruby_xfree(dom);
|
48
|
+
ruby_xfree(dom); // Don't need this any more
|
43
49
|
|
44
50
|
// Get the stringy version of the SID
|
45
51
|
if (!ConvertSidToStringSidW(sid, &str_sid)){
|
46
52
|
ruby_xfree(sid);
|
47
|
-
|
53
|
+
rb_raise_syserr("ConvertSidToStringSid", GetLastError());
|
48
54
|
}
|
49
55
|
|
50
|
-
ruby_xfree(sid);
|
56
|
+
ruby_xfree(sid); // Don't need this any more
|
51
57
|
|
52
58
|
// Mash the stringified SID onto our base key
|
53
59
|
if(swprintf(subkey, MAX_PATH, L"%s%s", key_base, str_sid) < 0)
|
54
|
-
|
60
|
+
rb_raise_syserr("swprintf", GetLastError());
|
55
61
|
|
56
62
|
// Get the key handle we need
|
57
63
|
rv = RegOpenKeyExW(HKEY_LOCAL_MACHINE, subkey, 0, KEY_QUERY_VALUE, &phkResult);
|
58
64
|
|
59
65
|
if (rv != ERROR_SUCCESS)
|
60
|
-
|
66
|
+
rb_raise_syserr("RegOpenKeyEx", GetLastError());
|
61
67
|
|
62
68
|
lpData = (wchar_t*)malloc(MAX_WPATH);
|
63
69
|
cbData = MAX_WPATH;
|
@@ -68,13 +74,13 @@ wchar_t* find_user(wchar_t* str){
|
|
68
74
|
|
69
75
|
if (rv != ERROR_SUCCESS){
|
70
76
|
ruby_xfree(lpData);
|
71
|
-
rb_raise(rb_eArgError, "can't find user %ls", str);
|
77
|
+
rb_raise(rb_eArgError, "can't find home directory for user %ls", str);
|
72
78
|
}
|
73
79
|
|
74
80
|
// Append any remaining path data that was originally present
|
75
81
|
if (ptr){
|
76
82
|
if (swprintf(lpData, MAX_WPATH, L"%s/%s", lpData, ptr) < 0)
|
77
|
-
|
83
|
+
rb_raise_syserr("swprintf", GetLastError());
|
78
84
|
}
|
79
85
|
|
80
86
|
return lpData;
|
@@ -108,7 +114,7 @@ wchar_t* expand_tilde(){
|
|
108
114
|
|
109
115
|
if(!size || !size2){
|
110
116
|
if (GetLastError() != ERROR_ENVVAR_NOT_FOUND)
|
111
|
-
|
117
|
+
rb_raise_syserr("GetEnvironmentVariable", GetLastError());
|
112
118
|
else
|
113
119
|
rb_raise(rb_eArgError, "couldn't find HOME environment -- expanding '~'");
|
114
120
|
}
|
@@ -119,11 +125,11 @@ wchar_t* expand_tilde(){
|
|
119
125
|
if(!GetEnvironmentVariableW(env, home, size) || !GetEnvironmentVariableW(env2, temp, size2)){
|
120
126
|
ruby_xfree(home);
|
121
127
|
ruby_xfree(temp);
|
122
|
-
|
128
|
+
rb_raise_syserr("GetEnvironmentVariable", GetLastError());
|
123
129
|
}
|
124
130
|
|
125
131
|
if(!PathAppendW(home, temp))
|
126
|
-
|
132
|
+
rb_raise_syserr("PathAppend", GetLastError());
|
127
133
|
}
|
128
134
|
else{
|
129
135
|
home = (wchar_t*)ruby_xmalloc(MAX_WPATH);
|
@@ -131,7 +137,7 @@ wchar_t* expand_tilde(){
|
|
131
137
|
|
132
138
|
if(!size){
|
133
139
|
ruby_xfree(home);
|
134
|
-
|
140
|
+
rb_raise_syserr("GetEnvironmentVariable", GetLastError());
|
135
141
|
}
|
136
142
|
}
|
137
143
|
|
@@ -186,7 +192,7 @@ static VALUE rb_xpath(int argc, VALUE* argv, VALUE self){
|
|
186
192
|
|
187
193
|
if(!MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(v_path), -1, path, length)){
|
188
194
|
ruby_xfree(path);
|
189
|
-
|
195
|
+
rb_raise_syserr("MultibyteToWideChar", GetLastError());
|
190
196
|
}
|
191
197
|
|
192
198
|
// Convert all forward slashes to backslashes to Windows API functions work properly
|
@@ -206,7 +212,7 @@ static VALUE rb_xpath(int argc, VALUE* argv, VALUE self){
|
|
206
212
|
|
207
213
|
if (!PathAppendW(home, ++ptr)){
|
208
214
|
ruby_xfree(home);
|
209
|
-
|
215
|
+
rb_raise_syserr("PathAppend", GetLastError());
|
210
216
|
}
|
211
217
|
}
|
212
218
|
|
@@ -239,7 +245,7 @@ static VALUE rb_xpath(int argc, VALUE* argv, VALUE self){
|
|
239
245
|
|
240
246
|
if (!MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(v_dir), -1, dir, length)){
|
241
247
|
ruby_xfree(dir);
|
242
|
-
|
248
|
+
rb_raise_syserr("MultibyteToWideChar", GetLastError());
|
243
249
|
}
|
244
250
|
|
245
251
|
while (wcsstr(dir, L"/"))
|
@@ -254,7 +260,7 @@ static VALUE rb_xpath(int argc, VALUE* argv, VALUE self){
|
|
254
260
|
|
255
261
|
if (!PathAppendW(dir, ++ptr)){
|
256
262
|
ruby_xfree(dir);
|
257
|
-
|
263
|
+
rb_raise_syserr("PathAppend", GetLastError());
|
258
264
|
}
|
259
265
|
}
|
260
266
|
}
|
@@ -265,7 +271,7 @@ static VALUE rb_xpath(int argc, VALUE* argv, VALUE self){
|
|
265
271
|
if (PathIsRelativeW(path)){
|
266
272
|
if(!PathAppendW(dir, path)){
|
267
273
|
ruby_xfree(dir);
|
268
|
-
|
274
|
+
rb_raise_syserr("PathAppend", GetLastError());
|
269
275
|
}
|
270
276
|
|
271
277
|
// Remove leading slashes from relative paths
|
@@ -288,7 +294,7 @@ static VALUE rb_xpath(int argc, VALUE* argv, VALUE self){
|
|
288
294
|
|
289
295
|
if(!length){
|
290
296
|
ruby_xfree(wpwd);
|
291
|
-
|
297
|
+
rb_raise_syserr("GetCurrentDirectory", GetLastError());
|
292
298
|
}
|
293
299
|
|
294
300
|
// Convert backslashes into forward slashes
|
@@ -302,7 +308,7 @@ static VALUE rb_xpath(int argc, VALUE* argv, VALUE self){
|
|
302
308
|
|
303
309
|
if (!length){
|
304
310
|
ruby_xfree(pwd);
|
305
|
-
|
311
|
+
rb_raise_syserr("WideCharToMultiByte", GetLastError());
|
306
312
|
}
|
307
313
|
|
308
314
|
return rb_str_new2(pwd);
|
@@ -321,7 +327,7 @@ static VALUE rb_xpath(int argc, VALUE* argv, VALUE self){
|
|
321
327
|
|
322
328
|
if (!length){
|
323
329
|
ruby_xfree(buffer);
|
324
|
-
|
330
|
+
rb_raise_syserr("GetFullPathName", GetLastError());
|
325
331
|
}
|
326
332
|
|
327
333
|
// Convert backslashes into forward slashes
|
@@ -336,7 +342,7 @@ static VALUE rb_xpath(int argc, VALUE* argv, VALUE self){
|
|
336
342
|
|
337
343
|
if (!length){
|
338
344
|
ruby_xfree(final_path);
|
339
|
-
|
345
|
+
rb_raise_syserr("WideCharToMultiByte", GetLastError());
|
340
346
|
}
|
341
347
|
|
342
348
|
v_path = rb_str_new(final_path, length - 1); // Don't count null terminator
|
data/win32-xpath.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: win32-xpath
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel J. Berger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02
|
11
|
+
date: 2015-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|