17 |
17 |
18 |
18 |
19 |
19 |
20 // INCLUDE FILES |
20 // INCLUDE FILES |
21 #include <bldvariant.hrh> |
21 #include <bldvariant.hrh> |
22 #include <browser_platform_variant.hrh> |
22 #include <Browser_platform_variant.hrh> |
23 |
23 |
24 #include "FileExt.h" |
24 #include "FileExt.h" |
25 #include "HttpClientApp.h" |
25 #include "HttpClientApp.h" |
26 #include "HttpDownload.h" |
26 #include "HttpDownload.h" |
27 #include "HttpStorage.h" |
27 #include "HttpStorage.h" |
28 #include "HttpDownloadManagerServerEngine.h" |
28 #include "HttpDownloadManagerServerEngine.h" |
29 #include "HttpDownloadMgrLogger.h" |
29 #include "HttpDownloadMgrLogger.h" |
30 #include "HeaderField.h" |
30 #include "HeaderField.h" |
31 #include "BuffStorage.h" |
31 #include "BuffStorage.h" |
32 |
32 |
33 #include <SysUtil.h> |
33 #include <sysutil.h> |
34 #include <DocumentHandler.h> |
34 #include <DocumentHandler.h> |
35 #include <APMSTD.H> |
35 #include <apmstd.h> |
36 |
36 |
37 #ifdef __SYNCML_DM_FOTA |
37 #ifdef __SYNCML_DM_FOTA |
38 #include <fotaengine.h> |
38 #include <fotaengine.h> |
39 #endif |
39 #endif |
40 |
40 |
67 // LOCAL FUNCTION PROTOTYPES |
67 // LOCAL FUNCTION PROTOTYPES |
68 //?type ?function_name( ?arg_type, ?arg_type ); |
68 //?type ?function_name( ?arg_type, ?arg_type ); |
69 |
69 |
70 // FORWARD DECLARATIONS |
70 // FORWARD DECLARATIONS |
71 //class ?FORWARD_CLASSNAME; |
71 //class ?FORWARD_CLASSNAME; |
72 |
|
73 //Music Store Warning Level Feature Flag |
|
74 #ifdef DOWNLOADMGR_WARNINGLEVEL_ENABLED_FF |
|
75 |
|
76 #include <uiklafinternalcrkeys.h> |
|
77 #include <centralrepository.h> |
|
78 |
|
79 //Beside the OOD threshold value, we need to reserve extra disk space |
|
80 //for harvest server do the harvest, set this as 1M |
|
81 const TInt KFreeSpaceExtraReserved(1024*1024); |
|
82 |
|
83 static TBool CheckFreeSpaceWarningThreshold( RFs& aFs, TInt aBytesToWrite, TInt aDrive ) |
|
84 { |
|
85 TBool isSpace = EFalse; |
|
86 CRepository* repository = NULL; |
|
87 TInt64 thresholdValue( 0 ); |
|
88 TVolumeInfo volumeInfo; |
|
89 TInt err = aFs.Volume( volumeInfo, aDrive ); |
|
90 if ( err == KErrNone ) // get warning threshold |
|
91 { |
|
92 TRAP( err, repository = CRepository::NewL( KCRUidUiklaf ) ); |
|
93 } |
|
94 if ( err == KErrNone ) |
|
95 { |
|
96 if ( volumeInfo.iDrive.iDriveAtt & KDriveAttRemovable ) // for E and F |
|
97 { |
|
98 TInt warningValue( 0 ); |
|
99 err = repository->Get( KUikOODDiskFreeSpaceWarningNoteLevelMassMemory, warningValue ); |
|
100 if ( err == KErrNone ) |
|
101 { |
|
102 thresholdValue = warningValue + KFreeSpaceExtraReserved; |
|
103 } |
|
104 } |
|
105 else |
|
106 { |
|
107 TInt warningUsagePercent( 0 ); |
|
108 err = repository->Get( KUikOODDiskFreeSpaceWarningNoteLevel, warningUsagePercent ); |
|
109 if ( err == KErrNone ) |
|
110 { |
|
111 thresholdValue = ( ( volumeInfo.iSize * ( 100 - warningUsagePercent ) ) / 100 ) |
|
112 + KFreeSpaceExtraReserved; |
|
113 } |
|
114 } |
|
115 delete repository; |
|
116 } |
|
117 if ( err == KErrNone ) // Check warning threshold |
|
118 { |
|
119 isSpace = volumeInfo.iFree > thresholdValue + aBytesToWrite; |
|
120 } |
|
121 return isSpace; |
|
122 } |
|
123 #endif |
|
124 |
72 |
125 // ============================ MEMBER FUNCTIONS =============================== |
73 // ============================ MEMBER FUNCTIONS =============================== |
126 |
74 |
127 // ----------------------------------------------------------------------------- |
75 // ----------------------------------------------------------------------------- |
128 // CHttpStorage::CHttpStorage |
76 // CHttpStorage::CHttpStorage |
746 CLOG_WRITE8_1( "Bad drive letter [%c]", drives[i] ); |
694 CLOG_WRITE8_1( "Bad drive letter [%c]", drives[i] ); |
747 } |
695 } |
748 } |
696 } |
749 CleanupStack::PopAndDestroy( drivesDynList ); |
697 CleanupStack::PopAndDestroy( drivesDynList ); |
750 CLOG_WRITE_2( "Saving content to %d Drive with %d B free space", driveSpaceMax, freeSpaceMax ); |
698 CLOG_WRITE_2( "Saving content to %d Drive with %d B free space", driveSpaceMax, freeSpaceMax ); |
751 TUint aStatus ; |
699 |
752 |
700 TDriveInfo driveInfo; |
753 if( KErrNone == DriveInfo::GetDriveStatus( iDownload->ClientApp()->Engine()->Fs(), driveSpaceMax , aStatus )) |
701 |
754 { |
702 if( !iDownload->ClientApp()->Engine()->Fs().Drive( driveInfo, driveSpaceMax) ) |
755 iRemovableStatus = (aStatus & DriveInfo::EDriveExternallyMountable) ? aStatus : 0 ; |
703 { |
756 if( iRemovableStatus ) |
704 iRemovableDest = (driveInfo.iDriveAtt & KDriveAttRemovable); |
757 { |
705 CLOG_WRITE_1( "Removable: [%d]", iRemovableDest ); |
758 iRemovableStatus = (aStatus & DriveInfo::EDriveRemovable) ? KDriveAttRemovable : KDriveAttInternal ; |
706 CLOG_WRITE_1( "driveInfo.iDriveAtt: [%d]", driveInfo.iDriveAtt ); |
759 } |
707 } |
760 else |
708 else |
761 { |
709 { |
762 iRemovableStatus = KDriveAttLocal ; |
710 CLOG_WRITE("DriveInfo failed"); |
763 } |
711 } |
764 CLOG_WRITE_1( "Removable: [%d]", iRemovableStatus ); |
|
765 CLOG_WRITE_1( "DriveInfo Status [%d]", aStatus ); |
|
766 } |
|
767 else |
|
768 { |
|
769 CLOG_WRITE("DriveStatus failed"); |
|
770 } |
|
771 |
712 |
772 return driveSpaceMax; |
713 return driveSpaceMax; |
773 #else |
714 #else |
774 // If no MMC is inserted, this will leave (and not set mmcOk). |
715 // If no MMC is inserted, this will leave (and not set mmcOk). |
775 bytesToWrite = iLength; |
716 bytesToWrite = iLength; |
779 TBool mmcOk = EFalse; |
720 TBool mmcOk = EFalse; |
780 TRAP_IGNORE( mmcOk = !SysUtil::MMCSpaceBelowCriticalLevelL |
721 TRAP_IGNORE( mmcOk = !SysUtil::MMCSpaceBelowCriticalLevelL |
781 ( &fs, bytesToWrite ); ) |
722 ( &fs, bytesToWrite ); ) |
782 if(!mmcOk) |
723 if(!mmcOk) |
783 { |
724 { |
784 iRemovableStatus = KDriveAttInternal ; |
|
785 CLOG_WRITE( "no MMC present" ); |
725 CLOG_WRITE( "no MMC present" ); |
786 return EDriveC; |
726 return EDriveC; |
787 } |
727 } |
788 CLOG_WRITE( "MMC is present " ); |
728 CLOG_WRITE( "MMC is present " ); |
789 TVolumeInfo volInfoC; |
729 TVolumeInfo volInfoC; |
790 TVolumeInfo volInfoE; |
730 TVolumeInfo volInfoE; |
791 fs.Volume(volInfoC,EDriveC); |
731 fs.Volume(volInfoC,EDriveC); |
792 fs.Volume(volInfoE,EDriveE); |
732 fs.Volume(volInfoE,EDriveE); |
793 TInt64 freeC = volInfoC.iFree;//free memory available in that drive |
733 TInt64 freeC = volInfoC.iFree;//free memory available in that drive |
794 TInt64 freeE = volInfoE.iFree; |
734 TInt64 freeE = volInfoE.iFree; |
795 freeC = freeE?EDriveC:EDriveE;//put the file in which ever drive has more memory |
735 return freeC>=freeE?EDriveC:EDriveE;//put the file in which ever drive has more memory |
796 iRemovableStatus = (EDriveC == freeC) ? KDriveAttInternal : KDriveAttRemovable ; |
|
797 return freeC; |
|
798 #endif |
736 #endif |
799 } |
737 } |
800 |
738 |
801 // Destination is FFS in default |
739 // Destination is FFS in default |
802 #ifdef RD_MULTIPLE_DRIVE |
740 #ifdef RD_MULTIPLE_DRIVE |
856 HBufC8* drivesDynList = iDownload->ClientApp()->Engine()->QueryDynDriveListLC(); |
793 HBufC8* drivesDynList = iDownload->ClientApp()->Engine()->QueryDynDriveListLC(); |
857 TPtrC8 drives( *drivesDynList ); |
794 TPtrC8 drives( *drivesDynList ); |
858 #else |
795 #else |
859 TPtrC drives( iDownload->ClientApp()->Engine()->iDriveLettersCenRep ); |
796 TPtrC drives( iDownload->ClientApp()->Engine()->iDriveLettersCenRep ); |
860 #endif |
797 #endif |
861 //Music Store Warning Level Feature Flag |
798 |
862 #ifdef DOWNLOADMGR_WARNINGLEVEL_ENABLED_FF |
799 // drive letters are separated by semicolons |
863 // Check warning or critical level and change drive if warning or critical level would get crossed |
800 for( TInt i = 0; i < drives.Length() && (err || !isSpace); i = i + 2 ) |
864 // On first round, check warning level only |
801 { |
865 // On second round (all drives are about to cross warning level), check critical level |
802 if( (err = fs.CharToDrive( drives[i], drive )) == KErrNone ) |
866 // When crossing warning level, user will see warning note regarding low disk space |
|
867 for( TInt j = 0; j < 2 && (err || !isSpace); ++j ) |
|
868 { |
|
869 #endif |
|
870 // drive letters are separated by semicolons |
|
871 for( TInt i = 0; i < drives.Length() && (err || !isSpace); i = i + 2 ) |
|
872 { |
803 { |
873 if( (err = fs.CharToDrive( drives[i], drive )) == KErrNone ) |
804 currentDownloadsLen = DMSrvEngine->AllDownloadsSizeInDriveL(iDownload, drive); |
874 { |
805 |
875 currentDownloadsLen = DMSrvEngine->AllDownloadsSizeInDriveL(iDownload, drive); |
806 // Check if there's enough memory in the phone |
876 // Check if there's enough memory in the phone |
807 bytesToWrite = iLength + currentDownloadsLen; |
877 bytesToWrite = iLength + currentDownloadsLen; |
808 if (bytesToWrite < 0) |
878 if (bytesToWrite < 0) |
809 bytesToWrite = 0; |
879 bytesToWrite = 0; |
810 |
880 //Music Store Warning Level Feature Flag |
811 TRAP( err, isSpace = !SysUtil::DiskSpaceBelowCriticalLevelL( |
881 #ifdef DOWNLOADMGR_WARNINGLEVEL_ENABLED_FF |
812 &fs, |
882 |
813 bytesToWrite, |
883 if ( !j ) // check warning level on first round |
814 drive )); |
884 { |
|
885 isSpace = CheckFreeSpaceWarningThreshold( fs, bytesToWrite, drive ); |
|
886 } |
|
887 else // check critical level when all drives are about to cross warning level |
|
888 { |
|
889 TRAP( err, isSpace = !SysUtil::DiskSpaceBelowCriticalLevelL( |
|
890 &fs, bytesToWrite, drive )); |
|
891 } |
|
892 CLOG_WRITE8_4( "Free space check type %d drive %d isSpace %d, bytesToWrite %d", |
|
893 j,drive,isSpace,bytesToWrite); |
|
894 #else if |
|
895 TRAP( err, isSpace = !SysUtil::DiskSpaceBelowCriticalLevelL( |
|
896 &fs, bytesToWrite, drive )); |
|
897 |
|
898 #endif |
|
899 } |
|
900 else |
|
901 { |
|
902 CLOG_WRITE8_1( "Bad drive letter [%c]", drives[i] ); |
|
903 } |
|
904 } |
815 } |
905 //Music Store Warning Level Feature Flag |
816 else |
906 #ifdef DOWNLOADMGR_WARNINGLEVEL_ENABLED_FF |
817 { |
907 } |
818 CLOG_WRITE8_1( "Bad drive letter [%c]", drives[i] ); |
908 #endif |
819 } |
|
820 } |
909 #ifdef RD_MULTIPLE_DRIVE |
821 #ifdef RD_MULTIPLE_DRIVE |
910 CleanupStack::PopAndDestroy( drivesDynList ); |
822 CleanupStack::PopAndDestroy( drivesDynList ); |
911 #endif |
823 #endif |
912 } |
824 } |
913 |
825 |
914 #ifdef RD_MULTIPLE_DRIVE |
|
915 TUint aStatus ; |
|
916 |
|
917 if( KErrNone == DriveInfo::GetDriveStatus( iDownload->ClientApp()->Engine()->Fs(), drive , aStatus )) |
|
918 { |
|
919 iRemovableStatus = (aStatus & DriveInfo::EDriveExternallyMountable) ? aStatus : 0 ; |
|
920 if( iRemovableStatus ) |
|
921 { |
|
922 iRemovableStatus = (aStatus & DriveInfo::EDriveRemovable) ? KDriveAttRemovable : KDriveAttInternal ; |
|
923 } |
|
924 else |
|
925 { |
|
926 iRemovableStatus = KDriveAttLocal ; |
|
927 } |
|
928 CLOG_WRITE_1( "Removable: [%d]", iRemovableStatus ); |
|
929 CLOG_WRITE_1( "DriveInfo Status [%d]", aStatus ); |
|
930 } |
|
931 else |
|
932 { |
|
933 CLOG_WRITE("DriveStatus failed"); |
|
934 } |
|
935 |
|
936 #else |
|
937 TDriveInfo driveInfo; |
826 TDriveInfo driveInfo; |
938 |
827 |
939 if( !iDownload->ClientApp()->Engine()->Fs().Drive( driveInfo, drive) ) |
828 if( !iDownload->ClientApp()->Engine()->Fs().Drive( driveInfo, drive) ) |
940 { |
829 { |
941 if (driveInfo.iDriveAtt & KDriveAttRemovable) |
830 iRemovableDest = (driveInfo.iDriveAtt & KDriveAttRemovable); |
942 iRemovableStatus = KDriveAttRemovable ; |
831 CLOG_WRITE_1( "Removable: [%d]", iRemovableDest ); |
943 else |
|
944 iRemovableStatus = KDriveAttInternal ; |
|
945 CLOG_WRITE_1( "Removable: [%d]", iRemovableStatus ); |
|
946 } |
832 } |
947 else |
833 else |
948 { |
834 { |
949 CLOG_WRITE("DriveInfo failed"); |
835 CLOG_WRITE("DriveInfo failed"); |
950 } |
836 } |
951 #endif |
837 |
952 |
|
953 if( err || !isSpace ) |
838 if( err || !isSpace ) |
954 { |
839 { |
955 CLOG_WRITE8( "OOD1" ); |
840 CLOG_WRITE8( "OOD1" ); |
956 iDownload->OnError( KErrDiskFull, EDiskFull ); |
841 iDownload->OnError( KErrDiskFull, EDiskFull ); |
957 User::Leave( KErrDiskFull ); |
842 User::Leave( KErrDiskFull ); |
1120 |
1005 |
1121 iDriveId = GetDestinationDriveId(); |
1006 iDriveId = GetDestinationDriveId(); |
1122 TInt drive; |
1007 TInt drive; |
1123 if( !iDownload->ClientApp()->Engine()->Fs().CharToDrive((*iDestFilename)[0], drive) ) |
1008 if( !iDownload->ClientApp()->Engine()->Fs().CharToDrive((*iDestFilename)[0], drive) ) |
1124 { |
1009 { |
1125 #ifdef RD_MULTIPLE_DRIVE |
1010 TDriveInfo driveInfo; |
1126 TUint aStatus ; |
1011 if( !iDownload->ClientApp()->Engine()->Fs().Drive( driveInfo, drive) ) |
1127 |
1012 { |
1128 if( KErrNone == DriveInfo::GetDriveStatus( iDownload->ClientApp()->Engine()->Fs(), drive , aStatus )) |
1013 iRemovableDest = (driveInfo.iDriveAtt & KDriveAttRemovable); |
1129 { |
1014 CLOG_WRITE_1( "Removable: [%d]", iRemovableDest ); |
1130 iRemovableStatus = (aStatus & DriveInfo::EDriveExternallyMountable) ? aStatus : 0 ; |
|
1131 if( iRemovableStatus ) |
|
1132 { |
|
1133 iRemovableStatus = (aStatus & DriveInfo::EDriveRemovable) ? KDriveAttRemovable : KDriveAttInternal ; |
|
1134 } |
|
1135 else |
|
1136 { |
|
1137 iRemovableStatus = KDriveAttLocal ; |
|
1138 } |
|
1139 CLOG_WRITE_1( "Removable: [%d]", iRemovableStatus ); |
|
1140 CLOG_WRITE_1( "DriveInfo Status [%d]", aStatus ); |
|
1141 } |
1015 } |
1142 else |
1016 else |
1143 { |
1017 { |
1144 CLOG_WRITE("DriveStatus failed"); |
|
1145 } |
|
1146 |
|
1147 #else |
|
1148 TDriveInfo driveInfo; |
|
1149 |
|
1150 if( !iDownload->ClientApp()->Engine()->Fs().Drive( driveInfo, drive) ) |
|
1151 { |
|
1152 if (driveInfo.iDriveAtt & KDriveAttRemovable) |
|
1153 iRemovableStatus = KDriveAttRemovable ; |
|
1154 else |
|
1155 iRemovableStatus = KDriveAttInternal ; |
|
1156 CLOG_WRITE_1( "Removable: [%d]", iRemovableStatus ); |
|
1157 } |
|
1158 else |
|
1159 { |
|
1160 CLOG_WRITE("DriveInfo failed"); |
1018 CLOG_WRITE("DriveInfo failed"); |
1161 } |
1019 } |
1162 #endif |
|
1163 } |
1020 } |
1164 else |
1021 else |
1165 { |
1022 { |
1166 CLOG_WRITE("CharToDrive failed"); |
1023 CLOG_WRITE("CharToDrive failed"); |
1167 } |
1024 } |
1184 APPEND_BUF_INT( aBuf, iStorageMethod ); |
1041 APPEND_BUF_INT( aBuf, iStorageMethod ); |
1185 APPEND_BUF_INT( aBuf, iProgressiveDownload); |
1042 APPEND_BUF_INT( aBuf, iProgressiveDownload); |
1186 APPEND_BUF_INT( aBuf, iDownloadedSize); |
1043 APPEND_BUF_INT( aBuf, iDownloadedSize); |
1187 AppendBufL( aBuf, iDdFilename ); |
1044 AppendBufL( aBuf, iDdFilename ); |
1188 APPEND_BUF_INT( aBuf, iDownload->iMoLength ); |
1045 APPEND_BUF_INT( aBuf, iDownload->iMoLength ); |
1189 APPEND_BUF_INT( aBuf, iRemovableStatus ); |
1046 APPEND_BUF_INT( aBuf, iRemovableDest ); |
1190 |
1047 |
1191 } |
1048 } |
1192 |
1049 |
1193 // ----------------------------------------------------------------------------- |
1050 // ----------------------------------------------------------------------------- |
1194 // CHttpStorage::SaveStorageInfoL |
1051 // CHttpStorage::SaveStorageInfoL |
1206 READ_INT_L( aInFile, iStorageMethod ); |
1063 READ_INT_L( aInFile, iStorageMethod ); |
1207 READ_INT_L( aInFile, iProgressiveDownload); |
1064 READ_INT_L( aInFile, iProgressiveDownload); |
1208 READ_INT_L( aInFile, iDownloadedSize ); |
1065 READ_INT_L( aInFile, iDownloadedSize ); |
1209 ReadHBufCL( aInFile, iDdFilename ); |
1066 ReadHBufCL( aInFile, iDdFilename ); |
1210 READ_INT_L( aInFile, iDownload->iMoLength ); |
1067 READ_INT_L( aInFile, iDownload->iMoLength ); |
1211 READ_INT_L( aInFile, iRemovableStatus ); |
1068 READ_INT_L( aInFile, iRemovableDest ); |
1212 |
1069 |
1213 } |
1070 } |
1214 |
1071 |
1215 // ----------------------------------------------------------------------------- |
1072 // ----------------------------------------------------------------------------- |
1216 // CHttpStorage::UpdateExtensionL |
1073 // CHttpStorage::UpdateExtensionL |