@@ -69,24 +69,6 @@ jlong fileTimeToMillis(FILETIME ft) {
69
69
return millis ;
70
70
}
71
71
72
- /*
73
- * Get a null-terminated byte array from a java byte array.
74
- * The returned bytearray needs to be freed when not used
75
- * anymore. Use free(result) to do that.
76
- */
77
- jbyte * getByteArray (JNIEnv * env , jbyteArray target ) {
78
- jsize n ;
79
- jbyte * temp , * result ;
80
-
81
- temp = (* env )-> GetByteArrayElements (env , target , 0 );
82
- n = (* env )-> GetArrayLength (env , target );
83
- result = malloc ((n + 1 ) * sizeof (jbyte ));
84
- memcpy (result , temp , n * sizeof (jbyte ));
85
- result [n ] = '\0' ;
86
- (* env )-> ReleaseByteArrayElements (env , target , temp , 0 );
87
- return result ;
88
- }
89
-
90
72
/*
91
73
* Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives
92
74
* Method: nativeAttributes
@@ -104,24 +86,6 @@ JNIEXPORT jint JNICALL Java_org_eclipse_core_internal_filesystem_local_LocalFile
104
86
return attributes ;
105
87
}
106
88
107
- /*
108
- * Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives
109
- * Method: internalIsUnicode
110
- * Signature: ()Z
111
- */
112
- JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_filesystem_local_LocalFileNatives_internalIsUnicode
113
- (JNIEnv * env , jclass clazz ) {
114
- OSVERSIONINFO osvi ;
115
- memset (& osvi , 0 , sizeof (OSVERSIONINFO ));
116
- osvi .dwOSVersionInfoSize = sizeof (OSVERSIONINFO );
117
- if (!GetVersionEx (& osvi ))
118
- return JNI_FALSE ;
119
- // only Windows NT 4, Windows 2K and XP support Unicode API calls
120
- if (!(osvi .dwMajorVersion >= 5 || (osvi .dwPlatformId == VER_PLATFORM_WIN32_NT && osvi .dwMajorVersion == 4 )))
121
- return JNI_FALSE ;
122
- return JNI_TRUE ;
123
- }
124
-
125
89
/*
126
90
* Get a null-terminated short array from a java char array.
127
91
* The returned short array needs to be freed when not used
@@ -140,93 +104,6 @@ jchar* getCharArray(JNIEnv *env, jcharArray target) {
140
104
return result ;
141
105
}
142
106
143
- /*
144
- * Returns a Java string object for a given windows character string
145
- */
146
- jstring windowsTojstring ( JNIEnv * env , char * str )
147
- {
148
- jstring rtn = 0 ;
149
- int slen = strlen (str );
150
- wchar_t * buffer = 0 ;
151
- if ( slen == 0 )
152
- rtn = (* env )-> NewStringUTF ( env , str ); //UTF ok since empty string
153
- else
154
- {
155
- int length =
156
- MultiByteToWideChar ( CP_ACP , 0 , (LPCSTR )str , slen , NULL , 0 );
157
- buffer = malloc ( length * 2 + 1 );
158
- if ( MultiByteToWideChar ( CP_ACP , 0 , (LPCSTR )str , slen ,
159
- (LPWSTR )buffer , length ) > 0 )
160
- rtn = (* env )-> NewString ( env , (jchar * )buffer , length );
161
- }
162
- if ( buffer )
163
- free ( buffer );
164
- return rtn ;
165
- }
166
-
167
- /*
168
- * Converts a WIN32_FIND_DATA to IFileInfo
169
- */
170
- jboolean convertFindDataToFileInfo (JNIEnv * env , WIN32_FIND_DATA info , jobject fileInfo ) {
171
- jclass cls ;
172
- jmethodID mid ;
173
- ULONGLONG fileLength ;
174
-
175
- cls = (* env )-> GetObjectClass (env , fileInfo );
176
- if (cls == 0 ) return JNI_FALSE ;
177
-
178
- // select interesting information
179
- //exists
180
- mid = (* env )-> GetMethodID (env , cls , "setExists" , "(Z)V" );
181
- if (mid == 0 ) return JNI_FALSE ;
182
- (* env )-> CallVoidMethod (env , fileInfo , mid , JNI_TRUE );
183
-
184
- // file name
185
- mid = (* env )-> GetMethodID (env , cls , "setName" , "(Ljava/lang/String;)V" );
186
- if (mid == 0 ) return JNI_FALSE ;
187
- (* env )-> CallVoidMethod (env , fileInfo , mid , windowsTojstring (env , info .cFileName ));
188
-
189
- // last modified
190
- mid = (* env )-> GetMethodID (env , cls , "setLastModified" , "(J)V" );
191
- if (mid == 0 ) return JNI_FALSE ;
192
- (* env )-> CallVoidMethod (env , fileInfo , mid , fileTimeToMillis (info .ftLastWriteTime ));
193
-
194
- // file length
195
- fileLength = (info .nFileSizeHigh * (((ULONGLONG )MAXDWORD )+ 1 )) + info .nFileSizeLow ;
196
- mid = (* env )-> GetMethodID (env , cls , "setLength" , "(J)V" );
197
- if (mid == 0 ) return JNI_FALSE ;
198
- (* env )-> CallVoidMethod (env , fileInfo , mid , fileLength );
199
-
200
- // folder or file?
201
- if (info .dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) {
202
- mid = (* env )-> GetMethodID (env , cls , "setAttribute" , "(IZ)V" );
203
- if (mid == 0 ) return JNI_FALSE ;
204
- (* env )-> CallVoidMethod (env , fileInfo , mid , ATTRIBUTE_DIRECTORY , JNI_TRUE );
205
- }
206
-
207
- // read-only?
208
- if (info .dwFileAttributes & FILE_ATTRIBUTE_READONLY ) {
209
- mid = (* env )-> GetMethodID (env , cls , "setAttribute" , "(IZ)V" );
210
- if (mid == 0 ) return JNI_FALSE ;
211
- (* env )-> CallVoidMethod (env , fileInfo , mid , ATTRIBUTE_READ_ONLY , JNI_TRUE );
212
- }
213
-
214
- // archive?
215
- if (info .dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE ) {
216
- mid = (* env )-> GetMethodID (env , cls , "setAttribute" , "(IZ)V" );
217
- if (mid == 0 ) return JNI_FALSE ;
218
- (* env )-> CallVoidMethod (env , fileInfo , mid , ATTRIBUTE_ARCHIVE , JNI_TRUE );
219
- }
220
-
221
- // hidden?
222
- if (info .dwFileAttributes & FILE_ATTRIBUTE_HIDDEN ) {
223
- mid = (* env )-> GetMethodID (env , cls , "setAttribute" , "(IZ)V" );
224
- if (mid == 0 ) return JNI_FALSE ;
225
- (* env )-> CallVoidMethod (env , fileInfo , mid , ATTRIBUTE_HIDDEN , JNI_TRUE );
226
- }
227
- return JNI_TRUE ;
228
- }
229
-
230
107
/*
231
108
* Set symbolic link information in IFileInfo
232
109
*/
@@ -398,38 +275,6 @@ jboolean setIOError(JNIEnv *env, jobject fileInfo) {
398
275
return JNI_TRUE ;
399
276
}
400
277
401
- /*
402
- * Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives
403
- * Method: internalGetFileInfo
404
- * Signature: ([CLorg/eclipse/core/filesystem/IFileInfo;)Z
405
- */
406
- JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_filesystem_local_LocalFileNatives_internalGetFileInfo
407
- (JNIEnv * env , jclass clazz , jbyteArray target , jobject fileInfo ) {
408
- jbyte * name ;
409
- jsize size ;
410
- HANDLE handle ;
411
- WIN32_FIND_DATA info ;
412
-
413
- name = getByteArray (env , target );
414
- size = (* env )-> GetArrayLength (env , target );
415
- // FindFirstFile does not work at the root level. However, we
416
- // don't need it because the root will never change timestamp
417
- // The pattern \\?\c:\ represents a root path
418
- if (size == 7 && name [2 ] == '?' && name [5 ] == ':' && name [6 ] == '\\' ) {
419
- free (name );
420
- return fillEmptyDirectory (env , fileInfo );
421
- }
422
- handle = FindFirstFile (name , & info );
423
- free (name );
424
- if (handle == INVALID_HANDLE_VALUE ) {
425
- if (GetLastError () != ERROR_FILE_NOT_FOUND )
426
- setIOError (env , fileInfo );
427
- return JNI_FALSE ;
428
- }
429
- FindClose (handle );
430
- return convertFindDataToFileInfo (env , info , fileInfo );
431
- }
432
-
433
278
/*
434
279
* Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives
435
280
* Method: internalGetFileInfoW
@@ -466,127 +311,6 @@ JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_filesystem_local_Local
466
311
return result ;
467
312
}
468
313
469
- /*
470
- * Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives
471
- * Method: internalCopyAttributes
472
- * Signature: ([B[BZ)Z
473
- */
474
- JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_filesystem_local_LocalFileNatives_internalCopyAttributes
475
- (JNIEnv * env , jclass clazz , jbyteArray source , jbyteArray destination , jboolean copyLastModified ) {
476
-
477
- HANDLE handle ;
478
- WIN32_FIND_DATA info ;
479
- jbyte * sourceFile , * destinationFile ;
480
- int success = 1 ;
481
-
482
- sourceFile = getByteArray (env , source );
483
- destinationFile = getByteArray (env , destination );
484
-
485
- handle = FindFirstFile (sourceFile , & info );
486
- if (handle != INVALID_HANDLE_VALUE ) {
487
- success = SetFileAttributes (destinationFile , info .dwFileAttributes );
488
- if (success != 0 && copyLastModified ) {
489
- // does not honor copyLastModified
490
- // call to SetFileTime should pass file handle instead of file name
491
- // success = SetFileTime(destinationFile, &info.ftCreationTime, &info.ftLastAccessTime, &info.ftLastWriteTime);
492
- }
493
- } else {
494
- success = 0 ;
495
- }
496
-
497
- free (sourceFile );
498
- free (destinationFile );
499
- FindClose (handle );
500
- return success ;
501
- }
502
-
503
- /*
504
- * Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives
505
- * Method: internalCopyAttributesW
506
- * Signature: ([C[CZ)Z
507
- */
508
- JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_filesystem_local_LocalFileNatives_internalCopyAttributesW
509
- (JNIEnv * env , jclass clazz , jcharArray source , jcharArray destination , jboolean copyLastModified ) {
510
-
511
- HANDLE handle ;
512
- WIN32_FIND_DATAW info ;
513
- jchar * sourceFile , * destinationFile ;
514
- int success = 1 ;
515
-
516
- sourceFile = getCharArray (env , source );
517
- destinationFile = getCharArray (env , destination );
518
-
519
- handle = FindFirstFileW (sourceFile , & info );
520
-
521
- if (handle != INVALID_HANDLE_VALUE ) {
522
- success = SetFileAttributesW (destinationFile , info .dwFileAttributes );
523
- if (success != 0 && copyLastModified ) {
524
- // does not honor copyLastModified
525
- // call to SetFileTime should pass file handle instead of file name
526
- // success = SetFileTime(destinationFile, &info.ftCreationTime, &info.ftLastAccessTime, &info.ftLastWriteTime);
527
- }
528
- } else {
529
- success = 0 ;
530
- }
531
-
532
- free (sourceFile );
533
- free (destinationFile );
534
- FindClose (handle );
535
- return success ;
536
- }
537
-
538
- /*
539
- * Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives
540
- * Method: internalSetFileInfo
541
- * Signature: ([BLorg/eclipse/core/filesystem/IFileInfo;)Z
542
- */
543
- JNIEXPORT jboolean JNICALL Java_org_eclipse_core_internal_filesystem_local_LocalFileNatives_internalSetFileInfo
544
- (JNIEnv * env , jclass clazz , jcharArray target , jobject obj ) {
545
-
546
- HANDLE handle ;
547
- jbyte * targetFile ;
548
- jmethodID mid ;
549
- int success = JNI_FALSE ;
550
- DWORD attributes ;
551
- jboolean readOnly , hidden , archive ;
552
- jclass cls ;
553
-
554
- /* find out if we need to set the readonly bit */
555
- cls = (* env )-> GetObjectClass (env , obj );
556
- mid = (* env )-> GetMethodID (env , cls , "getAttribute" , "(I)Z" );
557
- if (mid == 0 ) goto fail ;
558
- readOnly = (* env )-> CallBooleanMethod (env , obj , mid , ATTRIBUTE_READ_ONLY );
559
-
560
- /* find out if we need to set the archive bit */
561
- archive = (* env )-> CallBooleanMethod (env , obj , mid , ATTRIBUTE_ARCHIVE );
562
-
563
- /* find out if we need to set the hidden bit */
564
- hidden = (* env )-> CallBooleanMethod (env , obj , mid , ATTRIBUTE_HIDDEN );
565
-
566
- targetFile = getByteArray (env , target );
567
- attributes = GetFileAttributes (targetFile );
568
- if (attributes == (DWORD )- 1 ) goto fail ;
569
-
570
- if (readOnly )
571
- attributes = attributes | FILE_ATTRIBUTE_READONLY ;
572
- else
573
- attributes = attributes & ~FILE_ATTRIBUTE_READONLY ;
574
- if (archive )
575
- attributes = attributes | FILE_ATTRIBUTE_ARCHIVE ;
576
- else
577
- attributes = attributes & ~FILE_ATTRIBUTE_ARCHIVE ;
578
- if (hidden )
579
- attributes = attributes | FILE_ATTRIBUTE_HIDDEN ;
580
- else
581
- attributes = attributes & ~FILE_ATTRIBUTE_HIDDEN ;
582
-
583
- success = SetFileAttributes (targetFile , attributes );
584
-
585
- fail :
586
- free (targetFile );
587
- return success ;
588
- }
589
-
590
314
/*
591
315
* Class: org_eclipse_core_internal_filesystem_local_LocalFileNatives
592
316
* Method: internalSetFileInfoW
0 commit comments