54 } |
63 } |
55 |
64 |
56 |
65 |
57 TTime DosTimeToTTime(TInt aDosTime,TInt aDosDate) |
66 TTime DosTimeToTTime(TInt aDosTime,TInt aDosDate) |
58 // |
67 // |
59 // Deciphers the dos time/date entry information and converts to TTime |
68 // Deciphers the dos time/date entry information and converts to TTime |
60 // |
69 // |
61 { |
70 { |
62 TInt secMask=0x1F; |
71 TInt secMask=0x1F; |
63 TInt minMask=0x07E0; |
72 TInt minMask=0x07E0; |
64 TInt hrMask=0xF800; |
73 TInt hrMask=0xF800; |
65 TInt dayMask=0x1F; |
74 TInt dayMask=0x1F; |
66 TInt monthMask=0x01E0; |
75 TInt monthMask=0x01E0; |
67 TInt yearMask=0xFE00; |
76 TInt yearMask=0xFE00; |
68 |
77 |
69 TInt secs=(aDosTime&secMask)*2; |
78 TInt secs=(aDosTime&secMask)*2; |
70 TInt mins=(aDosTime&minMask)>>5; |
79 TInt mins=(aDosTime&minMask)>>5; |
71 TInt hrs=(aDosTime&hrMask)>>11; |
80 TInt hrs=(aDosTime&hrMask)>>11; |
72 TInt days=(aDosDate&dayMask)-1; |
81 TInt days=(aDosDate&dayMask)-1; |
73 TMonth months=(TMonth)(((aDosDate&monthMask)>>5)-1); |
82 TMonth months=(TMonth)(((aDosDate&monthMask)>>5)-1); |
74 TInt years=((aDosDate&yearMask)>>9)+1980; |
83 TInt years=((aDosDate&yearMask)>>9)+1980; |
75 |
84 |
76 TDateTime datetime; |
85 TDateTime datetime; |
77 TInt ret=datetime.Set(years,months,days,hrs,mins,secs,0); |
86 TInt ret=datetime.Set(years,months,days,hrs,mins,secs,0); |
78 if (ret==KErrNone) |
87 if (ret==KErrNone) |
79 return(TTime(datetime)); |
88 return(TTime(datetime)); |
80 return(TTime(0)); |
89 return(TTime(0)); |
81 } |
90 } |
82 |
91 |
83 TInt DosTimeFromTTime(const TTime& aTime) |
92 TInt DosTimeFromTTime(const TTime& aTime) |
84 // |
93 // |
85 // Converts a TTime to a dos time |
94 // Converts a TTime to a dos time |
86 // |
95 // |
87 { |
96 { |
88 TDateTime dateTime=aTime.DateTime(); |
97 TDateTime dateTime=aTime.DateTime(); |
89 TInt dosSecs=dateTime.Second()/2; |
98 TInt dosSecs=dateTime.Second()/2; |
90 TInt dosMins=dateTime.Minute()<<5; |
99 TInt dosMins=dateTime.Minute()<<5; |
91 TInt dosHrs=dateTime.Hour()<<11; |
100 TInt dosHrs=dateTime.Hour()<<11; |
92 return dosSecs|dosMins|dosHrs; |
101 return dosSecs|dosMins|dosHrs; |
93 } |
102 } |
94 |
103 |
95 TInt DosDateFromTTime(const TTime& aTime) |
104 TInt DosDateFromTTime(const TTime& aTime) |
96 // |
105 // |
97 // Converts a TTime to a dos date |
106 // Converts a TTime to a dos date |
98 // |
107 // |
99 { |
108 { |
100 |
109 |
101 TDateTime dateTime=aTime.DateTime(); |
110 TDateTime dateTime=aTime.DateTime(); |
102 TInt dosDays=dateTime.Day()+1; |
111 TInt dosDays=dateTime.Day()+1; |
103 TInt dosMonths=(dateTime.Month()+1)<<5; |
112 TInt dosMonths=(dateTime.Month()+1)<<5; |
104 TInt dosYears=(dateTime.Year()-1980)<<9; |
113 TInt dosYears=(dateTime.Year()-1980)<<9; |
105 return dosDays|dosMonths|dosYears; |
114 return dosDays|dosMonths|dosYears; |
106 } |
115 } |
107 |
116 |
108 TBuf8<12> DosNameToStdFormat(const TDesC8& aDosName) |
117 TBuf8<12> DosNameToStdFormat(const TDesC8& aDosName) |
109 // |
118 // |
110 // Converts xxx.yyy to standard format aaaaaaaayyy |
119 // Converts xxx.yyy to standard format aaaaaaaayyy |
111 // |
120 // |
112 { |
121 { |
113 |
122 |
114 __ASSERT_DEBUG(aDosName.Length()>=0 && aDosName.Length()<=12,Fault(EFatBadDosFormatName)); |
123 __ASSERT_DEBUG(aDosName.Length()>=0 && aDosName.Length()<=12,Fault(EFatBadDosFormatName)); |
115 TBuf8<12> result; |
124 TBuf8<12> result; |
116 Mem::Fill((TUint8*)result.Ptr(),result.MaxSize(),' '); |
125 Mem::Fill((TUint8*)result.Ptr(),result.MaxSize(),' '); |
117 TInt dotPos=aDosName.Locate('.'); |
126 TInt dotPos=aDosName.Locate('.'); |
118 if (dotPos==KErrNotFound) |
127 if (dotPos==KErrNotFound) |
119 { |
128 { |
120 result=aDosName; |
129 result=aDosName; |
121 result.SetLength(11); |
130 result.SetLength(11); |
122 return result; |
131 return result; |
123 } |
132 } |
124 result=aDosName.Left(dotPos); |
133 result=aDosName.Left(dotPos); |
125 result.SetLength(11); |
134 result.SetLength(11); |
126 TPtr8 ext(&result[8],3); |
135 TPtr8 ext(&result[8],3); |
127 ext=aDosName.Right(aDosName.Length()-dotPos-1); |
136 ext=aDosName.Right(aDosName.Length()-dotPos-1); |
128 return result; |
137 return result; |
129 } |
138 } |
130 |
139 |
131 TBuf8<12> DosNameFromStdFormat(const TDesC8& aStdFormatName) |
140 TBuf8<12> DosNameFromStdFormat(const TDesC8& aStdFormatName) |
132 // |
141 // |
133 // Converts aaaaaaaayyy to dos name format xxx.yyy |
142 // Converts aaaaaaaayyy to dos name format xxx.yyy |
134 // |
143 // |
135 { |
144 { |
136 |
145 |
137 __ASSERT_DEBUG(aStdFormatName.Length()==11,Fault(EFatBadStdFormatName)); |
146 __ASSERT_DEBUG(aStdFormatName.Length()==11,Fault(EFatBadStdFormatName)); |
138 TBuf8<12> result; |
147 TBuf8<12> result; |
139 TInt nameLen=aStdFormatName.Locate(' '); |
148 TInt nameLen=aStdFormatName.Locate(' '); |
140 if (nameLen>8 || nameLen==KErrNotFound) |
149 if (nameLen>8 || nameLen==KErrNotFound) |
141 nameLen=8; |
150 nameLen=8; |
142 result=aStdFormatName.Left(nameLen); |
151 result=aStdFormatName.Left(nameLen); |
143 TPtrC8 ext(&aStdFormatName[8],3); |
152 TPtrC8 ext(&aStdFormatName[8],3); |
144 TInt extLen=ext.Locate(' '); |
153 TInt extLen=ext.Locate(' '); |
145 if (extLen) |
154 if (extLen) |
146 result.Append(TChar('.')); |
155 result.Append(TChar('.')); |
147 if (extLen==KErrNotFound) |
156 if (extLen==KErrNotFound) |
148 extLen=3; |
157 extLen=3; |
149 result.Append(ext.Left(extLen)); |
158 result.Append(ext.Left(extLen)); |
150 if(result.Length() && result[0]==0x05 ) |
159 if(result.Length() && result[0]==0x05 ) |
151 { |
160 { |
152 result[0]=0xE5; |
161 result[0]=0xE5; |
153 } |
162 } |
154 return result; |
163 return result; |
155 } |
164 } |
156 |
165 |
157 TInt NumberOfVFatEntries(TInt aNameLength) |
166 TInt NumberOfVFatEntries(TInt aNameLength) |
158 // |
167 // |
159 // Return the number of VFat entries required to describe a filename of length aNameLength |
168 // Return the number of VFat entries required to describe a filename of length aNameLength |
160 // |
169 // |
161 { |
170 { |
162 TInt numberOfEntries=0; |
171 TInt numberOfEntries=0; |
163 if (aNameLength%KMaxVFatEntryName) |
172 if (aNameLength%KMaxVFatEntryName) |
164 aNameLength++; // Include a zero terminator |
173 aNameLength++; // Include a zero terminator |
165 // If aNameLength is a exact multiple of KMaxVFatEntryName, don't bother |
174 // If aNameLength is a exact multiple of KMaxVFatEntryName, don't bother |
166 // with a zero terminator - it just adds an unnecessary directory entry |
175 // with a zero terminator - it just adds an unnecessary directory entry |
167 |
176 |
168 numberOfEntries=(1+(aNameLength/KMaxVFatEntryName)); |
177 numberOfEntries=(1+(aNameLength/KMaxVFatEntryName)); |
169 |
178 |
170 if (aNameLength%KMaxVFatEntryName) |
179 if (aNameLength%KMaxVFatEntryName) |
171 numberOfEntries++; |
180 numberOfEntries++; |
172 |
181 |
173 return(numberOfEntries); |
182 return(numberOfEntries); |
174 } |
183 } |
175 |
184 |
176 //----------------------------------------------------------------------------- |
185 //----------------------------------------------------------------------------- |
177 /** |
186 /** |
178 Calculate DOS short name checksum |
187 Calculate DOS short name checksum |
179 @param aShortName short name descriptor (must be at least 11 bytes long) |
188 @param aShortName short name descriptor (must be at least 11 bytes long) |