|
1 /* |
|
2 * Copyright (c) 2006 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "musuifileutil.h" |
|
20 #include "muslogger.h" // debug logging |
|
21 #include "musuidefinitions.h" |
|
22 #include "musuidialogutil.h" |
|
23 #include "mussettings.h" |
|
24 #include <musui.rsg> |
|
25 |
|
26 #include <f32file.h> |
|
27 #include <StringLoader.h> |
|
28 #include <AknGlobalNote.h> |
|
29 #include <apparc.h> |
|
30 |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 TBool MusUiFileUtil::FileExists( const TDesC& aFullFileName ) |
|
37 { |
|
38 MUS_LOG( "mus: [MUSUI ] -> MusUiFileUtil::FileExists" ); |
|
39 |
|
40 TBool fileExists( EFalse ); |
|
41 RFs fs; |
|
42 |
|
43 if ( fs.Connect() == KErrNone ) |
|
44 { |
|
45 TUint att; |
|
46 fileExists = ( fs.Att( aFullFileName, att ) != KErrNotFound ); |
|
47 fs.Close(); |
|
48 } |
|
49 |
|
50 MUS_LOG( "mus: [MUSUI ] <- MusUiFileUtil::FileExists" ); |
|
51 |
|
52 return fileExists; |
|
53 } |
|
54 |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 void MusUiFileUtil::VideoFilePathExistsL( const TDesC& aVideoFilePath) |
|
61 { |
|
62 MUS_LOG( "mus: [MUSUI ] -> MusUiFileUtil::VideoFilePathExistsL" ); |
|
63 |
|
64 RFs fs; |
|
65 |
|
66 User::LeaveIfError( fs.Connect() ); |
|
67 CleanupClosePushL( fs ); |
|
68 TInt error = fs.MkDirAll( aVideoFilePath ); |
|
69 CleanupStack::PopAndDestroy( &fs ); |
|
70 |
|
71 MUS_LOG1( "mus: [MUSUI ] <- MusUiFileUtil::VideoFilePathExistsL,%d",error ); |
|
72 User::Leave(error); |
|
73 } |
|
74 |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 // ----------------------------------------------------------------------------- |
|
78 // |
|
79 void MusUiFileUtil::CreateVideoFileNameL( const TDesC& aVideoFilePath, |
|
80 TFileName& aFileName ) |
|
81 { |
|
82 MUS_LOG( "mus: [MUSUI ] -> MusUiFileUtil::CreateVideoFileNameL" ); |
|
83 |
|
84 RFs fs; |
|
85 TParse parse; |
|
86 TFileName fullFileName; |
|
87 TUint att; |
|
88 |
|
89 User::LeaveIfError( fs.Connect() ); |
|
90 CleanupClosePushL( fs ); |
|
91 |
|
92 if ( fs.Att( aVideoFilePath, att ) == KErrNone ) |
|
93 { |
|
94 if ( MultimediaSharingSettings::OperatorVariantSettingL() == |
|
95 MusSettingsKeys::EStandard ) |
|
96 { |
|
97 HBufC* temp = StringLoader::LoadLC( R_MUS_VIEW_SAVED_FILENAME ); |
|
98 User::LeaveIfError( parse.Set( aVideoFilePath, temp, NULL ) ); |
|
99 CleanupStack::PopAndDestroy( temp ); |
|
100 fullFileName = parse.FullName(); |
|
101 fullFileName.Append( KMusVideoFileNameExtension ); |
|
102 User::LeaveIfError( |
|
103 CApaApplication::GenerateFileName( fs, fullFileName ) ); |
|
104 User::LeaveIfError( parse.Set( fullFileName, NULL, NULL ) ); |
|
105 } |
|
106 else // operator specific case |
|
107 { |
|
108 RBuf newName; |
|
109 newName.CreateL( KMaxFileName ); |
|
110 CleanupClosePushL( newName ); |
|
111 |
|
112 TEntry entry; |
|
113 TInt i = 1; |
|
114 // path + 'VS' + date + 'V' + counter + extension |
|
115 _LIT( KFormatStringOne, "%S%S%S%S%02d%S" ); |
|
116 _LIT( KFormatStringTwo, "%S%S%S%S%d%S" ); |
|
117 TBuf<16> format; |
|
118 format = KFormatStringOne; |
|
119 |
|
120 // get current date |
|
121 _LIT( KDateFormat, "%F%M%D%*Y" ); |
|
122 TTime time; |
|
123 time.UniversalTime(); |
|
124 TBuf<6> dateString; |
|
125 time.FormatL( dateString, KDateFormat ); |
|
126 |
|
127 // generate a valid filename that doesn't already exist... |
|
128 do |
|
129 { |
|
130 TPtrC driveAndPath = aVideoFilePath; |
|
131 TPtrC date = dateString; |
|
132 newName.Format( format, |
|
133 &driveAndPath, &KMusVideoFileNameBegining, |
|
134 &date, &KMusVideoFileNameVersion, |
|
135 i++, &KMusVideoFileNameExtension ); |
|
136 |
|
137 if ( newName.Length() > KMaxFileName ) |
|
138 { |
|
139 User::Leave( KErrOverflow ); |
|
140 } |
|
141 |
|
142 if ( i >= 100 ) |
|
143 { |
|
144 format = KFormatStringTwo; |
|
145 } |
|
146 } // Continue until DoesNotExist |
|
147 while ( fs.Entry( newName, entry ) == KErrNone ); |
|
148 |
|
149 fullFileName.Copy( newName ); |
|
150 User::LeaveIfError( parse.Set( newName, NULL, NULL ) ); |
|
151 |
|
152 CleanupStack::PopAndDestroy( &newName ); |
|
153 } |
|
154 |
|
155 RFile file; |
|
156 CleanupClosePushL( file ); |
|
157 User::LeaveIfError( |
|
158 file.Create( fs, fullFileName, EFileWrite | EFileShareExclusive ) ); |
|
159 CleanupStack::PopAndDestroy( &file ); |
|
160 } |
|
161 |
|
162 CleanupStack::PopAndDestroy( &fs ); |
|
163 |
|
164 aFileName = parse.Name(); |
|
165 |
|
166 MUS_LOG( "mus: [MUSUI ] < - MusUiFileUtil::CreateVideoFileNameL" ); |
|
167 } |
|
168 |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 void MusUiFileUtil::DeleteFileL( const TDesC& aFileName ) |
|
175 { |
|
176 RFs fs; |
|
177 User::LeaveIfError( fs.Connect() ); |
|
178 CleanupClosePushL( fs ); |
|
179 TInt error = fs.Delete( aFileName ); |
|
180 if ( ( error != KErrNone ) && ( error != KErrNotFound ) ) |
|
181 { |
|
182 User::Leave( error ); |
|
183 } |
|
184 CleanupStack::PopAndDestroy( &fs ); |
|
185 } |
|
186 |
|
187 |
|
188 // end of file |