EXPORT_C void CSTPreferences::ResetSettingsL() { delete iDownloadPath; iDownloadPath = NULL; #ifdef __WINS__ iDownloadPath = _L("\\system\\apps\\symtorrent\\download\\").AllocL(); #else iDownloadPath = _L("E:\\BitTorrent\\").AllocL(); #endif delete iAccessPointName; iAccessPointName = NULL; iAccessPointName = KNullDesC().AllocL(); iAccessPointId = 0; iSTorrents->Reset(); _LIT(KLocalhost, "127.0.0.1"); SetProxyAddressL(KLocalhost); // SetProxyAddressL(_L("81.182.243.156")); SetProxyConnectionPort(10000); SetProxyServicePort(10001); SetIncomingPort(6881); SetStartupHashCheck(EFalse); // hash checking could take much time therefore it's disabled by default #ifdef EKA2 SetTrackerServicePort(10002); SetPieceSize(64); #ifdef USE_DHT SetDHTEnabled(ETrue); #else SetDHTEnabled(EFalse); #endif #endif SetUploadEnabled(ETrue); SetIncomingConnectionsMode(CNetworkManager::EEnabledWithoutProxy); SetSubpieceSize(0); SetRightSoftkeyMode(ESTSoftkeyExit); SetCloseConnectionAfterDownload(EFalse); }
bool CFile::Open(const std::string& filename, long size, int piecesize) { LOG_DEBUG("%s %d %d", filename.c_str(), size, piecesize); this->filename=filename; this->size=size; fileSystem->createSubdirs(CFileSystem::DirName(filename)); SetPieceSize(piecesize); if (handle!=NULL) { LOG_ERROR("file opened before old was closed"); return false; } struct stat sb; int res=stat(filename.c_str(), &sb); timestamp = 0; isnewfile=res!=0; if (isnewfile) { //if file is new, create it, if not, open the existing one without truncating it tmpfile = filename + ".tmp"; handle=fileSystem->propen(tmpfile, "wb+"); } else { handle=fileSystem->propen(filename, "rb+"); timestamp = sb.st_mtime; } if (handle==0) { LOG_ERROR("open(%s): %s",filename.c_str(), strerror(errno)); return false; } if((!isnewfile) && (size>0) && (size!=sb.st_size)) { //truncate file if real-size != excepted file size #ifdef _MSC_VER int ret = _chsize(fileno(handle), size); #else int ret = ftruncate(fileno(handle), size); #endif if (ret!=0) { LOG_ERROR("ftruncate failed"); } LOG_ERROR("File already exists but file-size missmatched"); } else if (size<=0) { //TODO: allocate disk space } LOG_INFO("opened %s", filename.c_str()); return true; }
EXPORT_C void CSTPreferences::LoadSettingsL() { if (iPreferencesFileName) { LWRITELN(iLog, _L("Loading settings")); RFs fs; User::LeaveIfError(fs.Connect()); CleanupClosePushL(fs); RFile file; if (file.Open(fs, *iPreferencesFileName, EFileRead|EFileShareReadersOnly) == KErrNone) { LWRITELN(iLog, _L("Settings file opened")); CleanupClosePushL(file); TBuf8<KMaxSettingNameLength> settingName; TInt settingLength; while (ReadSettingName(file, settingName, settingLength)) { if (settingName == KSettingDownloadPath) { HBufC* downloadPath = ReadAndConvertFromUtf8ToUnicodeL(file, settingLength); if (downloadPath) { delete iDownloadPath; iDownloadPath = downloadPath; } } else if (settingName == KSettingAccesPointId) { HBufC* iapIdBuf = ReadAndConvertFromUtf8ToUnicodeL(file, settingLength); if (iapIdBuf) { TLex lex(*iapIdBuf); lex.Mark(); TInt iapId = 0; if (lex.Val(iapId) == KErrNone) iAccessPointId = iapId; } delete iapIdBuf; } else if (settingName == KSettingAccesPointName) { HBufC* iapName = ReadAndConvertFromUtf8ToUnicodeL(file, settingLength); if (iapName) { delete iAccessPointName; iAccessPointName = iapName; } } else if (settingName == KSettingRightSoftkeyMode) { HBufC* rsmBuf = ReadAndConvertFromUtf8ToUnicodeL(file, settingLength); if (rsmBuf) { TLex lex(*rsmBuf); lex.Mark(); TInt rsm = 0; if (lex.Val(rsm) == KErrNone) SetRightSoftkeyMode(TSTSoftkeyMode(rsm)); } delete rsmBuf; } else if (settingName == KSettingSTorrent) { HBufC* sTorrent = ReadAndConvertFromUtf8ToUnicodeL(file, settingLength); CleanupStack::PushL(sTorrent); if (sTorrent) iSTorrents->AppendL(*sTorrent); CleanupStack::PopAndDestroy(); // sTorrent } else if (settingName == KSettingProxyServicePort) { HBufC* servicePortBuf = ReadAndConvertFromUtf8ToUnicodeL(file, settingLength); if (servicePortBuf) { TLex lex(*servicePortBuf); lex.Mark(); TInt servicePort = 0; if (lex.Val(servicePort) == KErrNone) SetProxyServicePort(servicePort); } delete servicePortBuf; } else if (settingName == KSettingProxyConnectionPort) { HBufC* connPortBuf = ReadAndConvertFromUtf8ToUnicodeL(file, settingLength); if (connPortBuf) { TLex lex(*connPortBuf); lex.Mark(); TInt connPort = 0; if (lex.Val(connPort) == KErrNone) SetProxyConnectionPort(connPort); } delete connPortBuf; } else if (settingName == KSettingProxyHostName) { HBufC* hostname = ReadAndConvertFromUtf8ToUnicodeL(file, settingLength); if (hostname) { CleanupStack::PushL(hostname); SetProxyAddressL(*hostname); CleanupStack::PopAndDestroy(hostname); } } else if (settingName == KSettingIncomingConnectionsMode) { HBufC* icmBuf = ReadAndConvertFromUtf8ToUnicodeL(file, settingLength); if (icmBuf) { TLex lex(*icmBuf); lex.Mark(); TInt icm = 0; if (lex.Val(icm) == KErrNone) SetIncomingConnectionsMode(CNetworkManager::TIncomingConnectionsMode(icm)); } delete icmBuf; } else if (settingName == KSettingUploadEnabled) { HBufC* upBuf = ReadAndConvertFromUtf8ToUnicodeL(file, settingLength); if (upBuf) { TLex lex(*upBuf); lex.Mark(); TInt uploadEnabled = 0; if (lex.Val(uploadEnabled) == KErrNone) if (uploadEnabled) SetUploadEnabled(ETrue); else SetUploadEnabled(EFalse); } delete upBuf; } else if (settingName == KSettingStartupHashCheck) { HBufC* hcBuf = ReadAndConvertFromUtf8ToUnicodeL(file, settingLength); CleanupStack::PushL(hcBuf); if (hcBuf) { TLex lex(*hcBuf); lex.Mark(); TInt hashCheck = 0; if (lex.Val(hashCheck) == KErrNone) if (hashCheck) SetStartupHashCheck(ETrue); else SetStartupHashCheck(EFalse); } CleanupStack::PopAndDestroy(); // hcBuf } else if (settingName == KSettingCloseConnectionAfterDownload) { HBufC* hcBuf = ReadAndConvertFromUtf8ToUnicodeL(file, settingLength); CleanupStack::PushL(hcBuf); //TODO test before releasing /*if (hcBuf) { TLex lex(*hcBuf); lex.Mark(); TInt closeConn = 0; if (lex.Val(closeConn) == KErrNone) if (closeConn) SetCloseConnectionAfterDownload(ETrue); else SetCloseConnectionAfterDownload(EFalse); }*/ CleanupStack::PopAndDestroy(); // hcBuf } else if (settingName == KSettingSubpieceSize) { HBufC* buf = ReadAndConvertFromUtf8ToUnicodeL(file, settingLength); if (buf) { TLex lex(*buf); lex.Mark(); TInt sps = 0; if (lex.Val(sps) == KErrNone) SetSubpieceSize(sps); } delete buf; } else #ifdef EKA2 if (settingName == KSettingTrackerServicePort) { HBufC* trackerServicePortBuf = ReadAndConvertFromUtf8ToUnicodeL(file, settingLength); if (trackerServicePortBuf) { TLex lex(*trackerServicePortBuf); lex.Mark(); TInt trackerServicePort = 0; if (lex.Val(trackerServicePort) == KErrNone) SetTrackerServicePort(trackerServicePort); } delete trackerServicePortBuf; } else if (settingName == KSettingDHTEnabled) { HBufC* buf = ReadAndConvertFromUtf8ToUnicodeL(file, settingLength); CleanupStack::PushL(buf); #ifdef USE_DHT if (buf) { TLex lex(*buf); lex.Mark(); TInt dhtEnabled = 0; if (lex.Val(dhtEnabled) == KErrNone) if (dhtEnabled) SetDHTEnabled(ETrue); else SetDHTEnabled(EFalse); } #else SetDHTEnabled(EFalse); #endif CleanupStack::PopAndDestroy(); // buf } else if (settingName == KSettingPieceSize) { HBufC* psBuf = ReadAndConvertFromUtf8ToUnicodeL(file, settingLength); if (psBuf) { TLex lex(*psBuf); lex.Mark(); TInt ps = 0; if (lex.Val(ps) == KErrNone) SetPieceSize(ps); } delete psBuf; } else #endif if (settingName == KSettingIncomingPort) { HBufC* portBuf = ReadAndConvertFromUtf8ToUnicodeL(file, settingLength); if (portBuf) { TLex lex(*portBuf); lex.Mark(); TInt port = 0; if (lex.Val(port) == KErrNone) SetIncomingPort(port); } delete portBuf; } else { HBufC* unknownSetting = ReadAndConvertFromUtf8ToUnicodeL(file, settingLength); delete unknownSetting; } } CleanupStack::PopAndDestroy(); // file } else LWRITELN(iLog, _L("Failed to open settings file")); CleanupStack::PopAndDestroy(); // fs } }