| 1154 | } |
| 1155 | |
| 1156 | void CPartFile::LoadSourceSeeds() |
| 1157 | { |
| 1158 | CMemFile sources_data; |
| 1159 | |
| 1160 | bool valid_sources = false; |
| 1161 | |
| 1162 | const CPath seedsPath = m_fullname.AppendExt(".seeds"); |
| 1163 | if (!seedsPath.FileExists()) { |
| 1164 | return; |
| 1165 | } |
| 1166 | |
| 1167 | CFile file(seedsPath, CFile::read); |
| 1168 | if (!file.IsOpened()) { |
| 1169 | // Exists but can't be opened. Should not happen. Probably permission problem, try to remove it. |
| 1170 | AddLogLineN(CFormat( _("Can't read seeds file for Partfile %s (%s)") ) |
| 1171 | % m_partmetfilename |
| 1172 | % GetFileName() ); |
| 1173 | CPath::RemoveFile(seedsPath); |
| 1174 | return; |
| 1175 | } |
| 1176 | |
| 1177 | bool badSeedsFile = false; |
| 1178 | try { |
| 1179 | uint8 src_count = file.ReadUInt8(); |
| 1180 | |
| 1181 | bool bUseSX2Format = (src_count == 0); |
| 1182 | |
| 1183 | if (bUseSX2Format) { |
| 1184 | // v3 sources seeds |
| 1185 | src_count = file.ReadUInt8(); |
| 1186 | } |
| 1187 | |
| 1188 | sources_data.WriteUInt16(src_count); |
| 1189 | |
| 1190 | for (int i = 0; i< src_count; ++i) { |
| 1191 | uint32 dwID = file.ReadUInt32(); |
| 1192 | uint16 nPort = file.ReadUInt16(); |
| 1193 | |
| 1194 | sources_data.WriteUInt32(bUseSX2Format ? dwID : wxUINT32_SWAP_ALWAYS(dwID)); |
| 1195 | sources_data.WriteUInt16(nPort); |
| 1196 | sources_data.WriteUInt32(0); |
| 1197 | sources_data.WriteUInt16(0); |
| 1198 | |
| 1199 | if (bUseSX2Format) { |
| 1200 | sources_data.WriteHash(file.ReadHash()); |
| 1201 | sources_data.WriteUInt8(file.ReadUInt8()); |
| 1202 | } |
| 1203 | |
| 1204 | } |
| 1205 | |
| 1206 | if (!file.Eof()) { |
| 1207 | |
| 1208 | // v2: Added to keep track of too old seeds |
| 1209 | time_t timeFromFile = (time_t)file.ReadUInt32(); |
| 1210 | |
| 1211 | // Time frame is 2 hours. More than enough to compile |
| 1212 | // your new aMule version!. |
| 1213 | if ((timeFromFile + MIN2S(120)) >= (uint32) time(NULL)) { |
no test coverage detected