|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: JNI Layer for FilePlatformSpecifics |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <memory> |
|
19 #include <caf/content.h> |
|
20 |
|
21 #include "javajniutils.h" |
|
22 #include "jstringutils.h" |
|
23 #include "logger.h" |
|
24 |
|
25 #include "filemanager.h" |
|
26 #include "fileextendedcommon.h" |
|
27 #include "s60filesystemutilities.h" |
|
28 #include "com_nokia_mj_impl_fileutils_FilePlatformSpecifics.h" |
|
29 |
|
30 using namespace java::util; |
|
31 using namespace java::fileutils; |
|
32 using namespace java::fileutility; |
|
33 |
|
34 /* |
|
35 * Class: com_nokia_mj_impl_fileutils_FilePlatformSpecifics |
|
36 * Method: _copy |
|
37 * Signature: (Ljava/lang/String;Ljava/lang/String;Z)Z |
|
38 */ |
|
39 JNIEXPORT jboolean JNICALL Java_com_nokia_mj_impl_fileutils_FilePlatformSpecifics__1copy( |
|
40 JNIEnv *aJni, jclass, jstring source, jstring destination, |
|
41 jboolean overwrite) |
|
42 { |
|
43 std::wstring sourcePath = FileUtil::jstringToWstring(aJni, source); |
|
44 std::wstring destPath = FileUtil::jstringToWstring(aJni, destination); |
|
45 |
|
46 return FileManager::copy(sourcePath, destPath, overwrite); |
|
47 } |
|
48 |
|
49 /* |
|
50 * Class: com_nokia_mj_impl_fileutils_FilePlatformSpecifics |
|
51 * Method: _move |
|
52 * Signature: (Ljava/lang/String;Ljava/lang/String;Z)Z |
|
53 */ |
|
54 JNIEXPORT jboolean JNICALL Java_com_nokia_mj_impl_fileutils_FilePlatformSpecifics__1move( |
|
55 JNIEnv *aJni, jclass, jstring source, jstring destination, |
|
56 jboolean overwrite) |
|
57 { |
|
58 std::wstring sourcePath = FileUtil::jstringToWstring(aJni, source); |
|
59 std::wstring destPath = FileUtil::jstringToWstring(aJni, destination); |
|
60 |
|
61 return FileManager::move(sourcePath, destPath, overwrite); |
|
62 } |
|
63 |
|
64 /* |
|
65 * Class: com_nokia_mj_impl_fileutils_FilePlatformSpecifics |
|
66 * Method: _copyAll |
|
67 * Signature: (Ljava/lang/String;Ljava/lang/String;Z)Z |
|
68 */ |
|
69 JNIEXPORT jboolean JNICALL Java_com_nokia_mj_impl_fileutils_FilePlatformSpecifics__1copyAll( |
|
70 JNIEnv *aJni, jclass, jstring source, jstring destination, |
|
71 jboolean overwrite) |
|
72 { |
|
73 std::wstring sourcePath = FileUtil::jstringToWstring(aJni, source); |
|
74 std::wstring destPath = FileUtil::jstringToWstring(aJni, destination); |
|
75 |
|
76 return FileManager::copyAll(sourcePath, destPath, overwrite); |
|
77 } |
|
78 |
|
79 /* |
|
80 * Class: com_nokia_mj_impl_fileutils_FilePlatformSpecifics |
|
81 * Method: _deleteAll |
|
82 * Signature: (Ljava/lang/String;)Z |
|
83 */ |
|
84 JNIEXPORT jboolean JNICALL Java_com_nokia_mj_impl_fileutils_FilePlatformSpecifics__1deleteAll( |
|
85 JNIEnv *aJni, jclass, jstring target) |
|
86 { |
|
87 std::wstring sourcePath = FileUtil::jstringToWstring(aJni, target); |
|
88 |
|
89 return FileManager::deleteAll(sourcePath); |
|
90 } |
|
91 |
|
92 /* |
|
93 * Class: com_nokia_mj_impl_fileutils_FilePlatformSpecifics |
|
94 * Method: _setHidden |
|
95 * Signature: (Ljava/lang/String;Z)V |
|
96 */ |
|
97 JNIEXPORT void JNICALL Java_com_nokia_mj_impl_fileutils_FilePlatformSpecifics__1setHidden( |
|
98 JNIEnv *aJni, jclass, jstring fileName, jboolean hidden) |
|
99 { |
|
100 JStringUtils name(*aJni, fileName); |
|
101 TBool hide = hidden; |
|
102 |
|
103 TRAPD(err, S60FileSystemUtilities::SetHiddenL(name, hide)); |
|
104 if (err != KErrNone) |
|
105 { |
|
106 ELOG1(EJavaFile, |
|
107 "Java_com_nokia_mj_impl_file_FileSystemUtils__1sethidden %d", |
|
108 err); |
|
109 JniUtils::throwNewException(aJni, "java/io/IOException", ""); |
|
110 return; |
|
111 } |
|
112 return; |
|
113 } |
|
114 |
|
115 |
|
116 /* |
|
117 * Class: com_nokia_mj_impl_fileutils_FilePlatformSpecifics |
|
118 * Method: getContentId |
|
119 * Signature: (Ljava/lang/String;Z)V |
|
120 */ |
|
121 JNIEXPORT jstring JNICALL Java_com_nokia_mj_impl_fileutils_FilePlatformSpecifics__1getContentId( |
|
122 JNIEnv *aJni, jclass, jstring fileName) |
|
123 { |
|
124 JStringUtils path(*aJni, fileName); |
|
125 TDesC* pathStr = &path; |
|
126 |
|
127 std::auto_ptr<ContentAccess::CContent> content(0); |
|
128 |
|
129 TRAPD(err, content.reset(ContentAccess::CContent::NewL(*pathStr))); |
|
130 |
|
131 jstring contentId = 0; |
|
132 |
|
133 if (KErrNone == err) |
|
134 { |
|
135 TBool drmProtected = EFalse; |
|
136 err = content->GetAttribute( |
|
137 ContentAccess::EIsProtected, drmProtected); |
|
138 |
|
139 if (KErrNone == err && drmProtected) |
|
140 { |
|
141 std::auto_ptr<HBufC>contentIdBuf( |
|
142 HBufC::New(ContentAccess::KMaxCafContentName)); |
|
143 if (contentIdBuf.get()) |
|
144 { |
|
145 TPtr idPtr(contentIdBuf->Des()); |
|
146 content->GetStringAttribute(ContentAccess::EContentID, idPtr); |
|
147 contentId = aJni->NewString(idPtr.Ptr(), idPtr.Length()); |
|
148 } |
|
149 } |
|
150 } |
|
151 return contentId; |
|
152 } |
|
153 |
|
154 |