uint32 CKademlia::CalculateKadUsersNew(){ // the idea of calculating the user count with this method is simple: // whenever we do search for any NodeID (except in certain cases were the result is not usable), // we remember the distance of the closest node we found. Because we assume all NodeIDs are distributed // equally, we can calcualte based on this distance how "filled" the possible NodesID room is and by this // calculate how many users there are. Of course this only works if we have enough samples, because // each single sample will be wrong, but the average of them should produce a usable number. To avoid // drifts caused by a a single (or more) really close or really far away hits, we do use median-average instead through // doesnt works well if we have no files to index and nothing to download and the numbers seems to be a bit too low // compared to out other method. So lets stay with the old one for now, but keeps this here as alternative if (m_liStatsEstUsersProbes.GetCount() < 10) return 0; uint32 nMedian = 0; CList<uint32, uint32> liMedian; for (POSITION pos1 = m_liStatsEstUsersProbes.GetHeadPosition(); pos1 != NULL; ) { uint32 nProbe = m_liStatsEstUsersProbes.GetNext(pos1); bool bInserted = false; for (POSITION pos2 = liMedian.GetHeadPosition(); pos2 != NULL; liMedian.GetNext(pos2)){ if (liMedian.GetAt(pos2) > nProbe){ liMedian.InsertBefore(pos2, nProbe); bInserted = true; break; } } if (!bInserted) liMedian.AddTail(nProbe); } // cut away 1/3 of the values - 1/6 of the top and 1/6 of the bottom to avoid spikes having too much influence, build the average of the rest sint32 nCut = liMedian.GetCount() / 6; for (int i = 0; i != nCut; i++){ liMedian.RemoveHead(); liMedian.RemoveTail(); } uint64 nAverage = 0; for (POSITION pos1 = liMedian.GetHeadPosition(); pos1 != NULL; ) nAverage += liMedian.GetNext(pos1); nMedian = (uint32)(nAverage / liMedian.GetCount()); // LowIDModififier // Modify count by assuming 20% of the users are firewalled and can't be a contact for < 0.49b nodes // Modify count by actual statistics of Firewalled ratio for >= 0.49b if we are not firewalled ourself // Modify count by 40% for >= 0.49b if we are firewalled outself (the actual Firewalled count at this date on kad is 35-55%) const float fFirewalledModifyOld = 1.20F; float fFirewalledModifyNew = 0; if (CUDPFirewallTester::IsFirewalledUDP(true)) fFirewalledModifyNew = 1.40F; // we are firewalled and get get the real statistic, assume 40% firewalled >=0.49b nodes else if (GetPrefs()->StatsGetFirewalledRatio(true) > 0) { fFirewalledModifyNew = 1.0F + (CKademlia::GetPrefs()->StatsGetFirewalledRatio(true)); // apply the firewalled ratio to the modify ASSERT( fFirewalledModifyNew > 1.0F && fFirewalledModifyNew < 1.90F ); } float fNewRatio = CKademlia::GetPrefs()->StatsGetKadV8Ratio(); float fFirewalledModifyTotal = 0; if (fNewRatio > 0 && fFirewalledModifyNew > 0) // weigth the old and the new modifier based on how many new contacts we have fFirewalledModifyTotal = (fNewRatio * fFirewalledModifyNew) + ((1 - fNewRatio) * fFirewalledModifyOld); else fFirewalledModifyTotal = fFirewalledModifyOld; ASSERT( fFirewalledModifyTotal > 1.0F && fFirewalledModifyTotal < 1.90F ); return (uint32)((float)nMedian*fFirewalledModifyTotal); }
//********************************************************************************* int CBCGPVisualManagerVS2005::CreateAutoHideButtonRegion (CRect rect, DWORD dwAlignment, LPPOINT& points) { switch (dwAlignment & CBRS_ALIGN_ANY) { case CBRS_ALIGN_LEFT: rect.right--; break; case CBRS_ALIGN_TOP: rect.bottom--; break; } CRect rectOrign = rect; DWORD dwAlignmentOrign = dwAlignment; if ((dwAlignment & CBRS_ALIGN_ANY) == CBRS_ALIGN_LEFT || (dwAlignment & CBRS_ALIGN_ANY) == CBRS_ALIGN_RIGHT) { rect = CRect (0, 0, rectOrign.Height (), rectOrign.Width ()); dwAlignment = (dwAlignment == CBRS_ALIGN_LEFT) ? CBRS_ALIGN_TOP : CBRS_ALIGN_BOTTOM; } CList<POINT, POINT> pts; if (!m_bRoundedAutohideButtons) { rect.right--; pts.AddHead (CPoint (rect.left, rect.top)); pts.AddHead (CPoint (rect.left, rect.bottom - 2)); pts.AddHead (CPoint (rect.left + 2, rect.bottom)); pts.AddHead (CPoint (rect.right - 2, rect.bottom)); pts.AddHead (CPoint (rect.right, rect.bottom - 2)); pts.AddHead (CPoint (rect.right, rect.top)); } else { POSITION posLeft = pts.AddHead (CPoint (rect.left, rect.top)); posLeft = pts.InsertAfter (posLeft, CPoint (rect.left, rect.top + 2)); POSITION posRight = pts.AddTail (CPoint (rect.right, rect.top)); posRight = pts.InsertBefore (posRight, CPoint (rect.right, rect.top + 2)); int xLeft = rect.left + 1; int xRight = rect.right - 1; int y = 0; BOOL bIsHorz = (dwAlignmentOrign & CBRS_ALIGN_ANY) == CBRS_ALIGN_LEFT || (dwAlignmentOrign & CBRS_ALIGN_ANY) == CBRS_ALIGN_RIGHT; for (y = rect.top + 2; y < rect.bottom - 4; y += 2) { posLeft = pts.InsertAfter (posLeft, CPoint (xLeft, y)); posLeft = pts.InsertAfter (posLeft, CPoint (xLeft, y + 2)); posRight = pts.InsertBefore (posRight, CPoint (xRight, y)); posRight = pts.InsertBefore (posRight, CPoint (xRight, y + 2)); xLeft++; xRight--; } if ((dwAlignmentOrign & CBRS_ALIGN_ANY) == CBRS_ALIGN_BOTTOM && !bIsHorz) { xLeft--; xRight++; } if (bIsHorz) { xRight++; } for (;y < rect.bottom - 1; y++) { posLeft = pts.InsertAfter (posLeft, CPoint (xLeft, y)); posLeft = pts.InsertAfter (posLeft, CPoint (xLeft + 1, y + 1)); posRight = pts.InsertBefore (posRight, CPoint (xRight, y)); posRight = pts.InsertBefore (posRight, CPoint (xRight - 1, y + 1)); if (y == rect.bottom - 2) { posLeft = pts.InsertAfter (posLeft, CPoint (xLeft + 1, y + 1)); posLeft = pts.InsertAfter (posLeft, CPoint (xLeft + 3, y + 1)); posRight = pts.InsertBefore (posRight, CPoint (xRight, y + 1)); posRight = pts.InsertBefore (posRight, CPoint (xRight - 2, y + 1)); } xLeft++; xRight--; } posLeft = pts.InsertAfter (posLeft, CPoint (xLeft + 2, rect.bottom)); posRight = pts.InsertBefore (posRight, CPoint (xRight - 2, rect.bottom)); } points = new POINT [pts.GetCount ()]; int i = 0; for (POSITION pos = pts.GetHeadPosition (); pos != NULL; i++) { points [i] = pts.GetNext (pos); switch (dwAlignmentOrign & CBRS_ALIGN_ANY) { case CBRS_ALIGN_BOTTOM: points [i].y = rect.bottom - (points [i].y - rect.top); break; case CBRS_ALIGN_RIGHT: { int x = rectOrign.right - points [i].y; int y = rectOrign.top + points [i].x; points [i] = CPoint (x, y); } break; case CBRS_ALIGN_LEFT: { int x = rectOrign.left + points [i].y; int y = rectOrign.top + points [i].x; points [i] = CPoint (x, y); } break; } } return (int) pts.GetCount (); }
int CAICHSyncThread::Run() { //MORPH START SLUGFILLER: SafeHash CReadWriteLock lock(&theApp.m_threadlock); if (!lock.ReadLock(0)) return 0; // MORPH END SLUGFILLER: SafeHash if ( !theApp.emuledlg->IsRunning() ) return 0; // we need to keep a lock on this file while the thread is running CSingleLock lockKnown2Met(&CAICHRecoveryHashSet::m_mutKnown2File); lockKnown2Met.Lock(); CSafeFile file; bool bJustCreated = ConvertToKnown2ToKnown264(&file); // we collect all masterhashs which we find in the known2.met and store them in a list CList<CAICHHash> liKnown2Hashs; CString fullpath = thePrefs.GetMuleDirectory(EMULE_CONFIGDIR); fullpath.Append(KNOWN2_MET_FILENAME); CFileException fexp; uint32 nLastVerifiedPos = 0; if (!bJustCreated && !file.Open(fullpath,CFile::modeCreate|CFile::modeReadWrite|CFile::modeNoTruncate|CFile::osSequentialScan|CFile::typeBinary|CFile::shareDenyNone, &fexp)){ if (fexp.m_cause != CFileException::fileNotFound){ CString strError(_T("Failed to load ") KNOWN2_MET_FILENAME _T(" file")); TCHAR szError[MAX_CFEXP_ERRORMSG]; if (fexp.GetErrorMessage(szError, ARRSIZE(szError))){ strError += _T(" - "); strError += szError; } LogError(LOG_STATUSBAR, _T("%s"), strError); } return false; } try { if (file.GetLength() >= 1){ uint8 header = file.ReadUInt8(); if (header != KNOWN2_MET_VERSION){ AfxThrowFileException(CFileException::endOfFile, 0, file.GetFileName()); } //setvbuf(file.m_pStream, NULL, _IOFBF, 16384); uint32 nExistingSize = (UINT)file.GetLength(); uint32 nHashCount; while (file.GetPosition() < nExistingSize){ liKnown2Hashs.AddTail(CAICHHash(&file)); nHashCount = file.ReadUInt32(); if (file.GetPosition() + nHashCount*CAICHHash::GetHashSize() > nExistingSize){ AfxThrowFileException(CFileException::endOfFile, 0, file.GetFileName()); } // skip the rest of this hashset file.Seek(nHashCount*CAICHHash::GetHashSize(), CFile::current); nLastVerifiedPos = (UINT)file.GetPosition(); } } else file.WriteUInt8(KNOWN2_MET_VERSION); } catch(CFileException* error){ if (error->m_cause == CFileException::endOfFile){ LogError(LOG_STATUSBAR,GetResString(IDS_ERR_MET_BAD), KNOWN2_MET_FILENAME); // truncate the file to the size to the last verified valid pos try{ file.SetLength(nLastVerifiedPos); if (file.GetLength() == 0){ file.SeekToBegin(); file.WriteUInt8(KNOWN2_MET_VERSION); } } catch(CFileException* error2){ error2->Delete(); } } else{ TCHAR buffer[MAX_CFEXP_ERRORMSG]; error->GetErrorMessage(buffer, ARRSIZE(buffer)); LogError(LOG_STATUSBAR,GetResString(IDS_ERR_SERVERMET_UNKNOWN),buffer); } error->Delete(); return false; } // now we check that all files which are in the sharedfilelist have a corresponding hash in out list // those who don'T are added to the hashinglist CList<CAICHHash> liUsedHashs; CSingleLock sharelock(&theApp.sharedfiles->m_mutWriteList); sharelock.Lock(); bool bDbgMsgCreatingPartHashs = true; for (int i = 0; i < theApp.sharedfiles->GetCount(); i++){ CKnownFile* pCurFile = theApp.sharedfiles->GetFileByIndex(i); if (pCurFile != NULL && !pCurFile->IsPartFile() ) { if (theApp.emuledlg==NULL || !theApp.emuledlg->IsRunning()) // in case of shutdown while still hashing return 0; if (pCurFile->GetFileIdentifier().HasAICHHash()){ bool bFound = false; for (POSITION pos = liKnown2Hashs.GetHeadPosition();pos != 0;) { CAICHHash current_hash = liKnown2Hashs.GetNext(pos); if (current_hash == pCurFile->GetFileIdentifier().GetAICHHash()){ bFound = true; liUsedHashs.AddTail(current_hash); pCurFile->SetAICHRecoverHashSetAvailable(true); // Has the file the proper AICH Parthashset? If not probably upgrading, create it if (!pCurFile->GetFileIdentifier().HasExpectedAICHHashCount()) { if (bDbgMsgCreatingPartHashs) { bDbgMsgCreatingPartHashs = false; DebugLogWarning(_T("Missing AICH Part Hashsets for known files - maybe upgrading from earlier version. Creating them out of full AICH Recovery Hashsets, shouldn't take too long")); } CAICHRecoveryHashSet tempHashSet(pCurFile, pCurFile->GetFileSize()); tempHashSet.SetMasterHash(pCurFile->GetFileIdentifier().GetAICHHash(), AICH_HASHSETCOMPLETE); if (!tempHashSet.LoadHashSet()) { ASSERT( false ); DebugLogError(_T("Failed to load full AICH Recovery Hashset - known2.met might be corrupt. Unable to create AICH Part Hashset - %s"), pCurFile->GetFileName()); } else { if (!pCurFile->GetFileIdentifier().SetAICHHashSet(tempHashSet)) { DebugLogError(_T("Failed to create AICH Part Hashset out of full AICH Recovery Hashset - %s"), pCurFile->GetFileName()); ASSERT( false ); } ASSERT(pCurFile->GetFileIdentifier().HasExpectedAICHHashCount()); } } //theApp.QueueDebugLogLine(false, _T("%s - %s"), current_hash.GetString(), pCurFile->GetFileName()); /*#ifdef _DEBUG // in debugmode we load and verify all hashsets CAICHRecoveryHashSet* pTempHashSet = new CAICHRecoveryHashSet(pCurFile); pTempHashSet->SetFileSize(pCurFile->GetFileSize()); pTempHashSet->SetMasterHash(pCurFile->GetFileIdentifier().GetAICHHash(), AICH_HASHSETCOMPLETE) ASSERT( pTempHashSet->LoadHashSet() ); delete pTempHashSet; #endif*/ break; } } if (bFound) // hashset is available, everything fine with this file continue; } pCurFile->SetAICHRecoverHashSetAvailable(false); m_liToHash.AddTail(pCurFile); } } sharelock.Unlock(); // removed all unused AICH hashsets from known2.met if (liUsedHashs.GetCount() != liKnown2Hashs.GetCount() && // EastShare START - Added by TAHO, .met file control /* (!thePrefs.IsRememberingDownloadedFiles() || thePrefs.DoPartiallyPurgeOldKnownFiles())) */ (!thePrefs.IsRememberingDownloadedFiles() || thePrefs.DoPartiallyPurgeOldKnownFiles() || thePrefs.DoCompletlyPurgeOldKnownFiles() || thePrefs.DoRemoveAichImmediatly() ) ) // EastShare END - Added by TAHO, .met file control { file.SeekToBegin(); try { uint8 header = file.ReadUInt8(); if (header != KNOWN2_MET_VERSION){ AfxThrowFileException(CFileException::endOfFile, 0, file.GetFileName()); } uint32 nExistingSize = (UINT)file.GetLength(); uint32 nHashCount; ULONGLONG posWritePos = file.GetPosition(); ULONGLONG posReadPos = file.GetPosition(); uint32 nPurgeCount = 0; uint32 nPurgeBecauseOld = 0; while (file.GetPosition() < nExistingSize){ CAICHHash aichHash(&file); nHashCount = file.ReadUInt32(); if (file.GetPosition() + nHashCount*CAICHHash::GetHashSize() > nExistingSize){ AfxThrowFileException(CFileException::endOfFile, 0, file.GetFileName()); } if (!thePrefs.IsRememberingDownloadedFiles() && liUsedHashs.Find(aichHash) == NULL) { // unused hashset skip the rest of this hashset file.Seek(nHashCount*CAICHHash::GetHashSize(), CFile::current); nPurgeCount++; } else if (thePrefs.IsRememberingDownloadedFiles() && theApp.knownfiles->ShouldPurgeAICHHashset(aichHash)) { // EastShare START - Added by TAHO, .met file control /* ASSERT( thePrefs.DoPartiallyPurgeOldKnownFiles() ); */ ASSERT( thePrefs.DoPartiallyPurgeOldKnownFiles() || thePrefs.DoRemoveAichImmediatly()); // EastShare END - Added by TAHO, .met file control // also unused (purged) hashset skip the rest of this hashset file.Seek(nHashCount*CAICHHash::GetHashSize(), CFile::current); nPurgeCount++; nPurgeBecauseOld++; } else if(nPurgeCount == 0){ // used Hashset, but it does not need to be moved as nothing changed yet file.Seek(nHashCount*CAICHHash::GetHashSize(), CFile::current); posWritePos = file.GetPosition(); CAICHRecoveryHashSet::AddStoredAICHHash(aichHash); } else{ // used Hashset, move position in file BYTE* buffer = new BYTE[nHashCount*CAICHHash::GetHashSize()]; file.Read(buffer, nHashCount*CAICHHash::GetHashSize()); posReadPos = file.GetPosition(); file.Seek(posWritePos, CFile::begin); file.Write(aichHash.GetRawHash(), CAICHHash::GetHashSize()); file.WriteUInt32(nHashCount); file.Write(buffer, nHashCount*CAICHHash::GetHashSize()); delete[] buffer; posWritePos = file.GetPosition(); file.Seek(posReadPos, CFile::begin); CAICHRecoveryHashSet::AddStoredAICHHash(aichHash); } } posReadPos = file.GetPosition(); file.SetLength(posWritePos); theApp.QueueDebugLogLine(false, _T("Cleaned up known2.met, removed %u hashsets and purged %u hashsets of old known files (%s)") , nPurgeCount - nPurgeBecauseOld, nPurgeBecauseOld, CastItoXBytes(posReadPos-posWritePos)); file.Flush(); file.Close(); } catch(CFileException* error){ if (error->m_cause == CFileException::endOfFile){ // we just parsed this files some ms ago, should never happen here ASSERT( false ); } else{ TCHAR buffer[MAX_CFEXP_ERRORMSG]; error->GetErrorMessage(buffer, ARRSIZE(buffer)); LogError(LOG_STATUSBAR,GetResString(IDS_ERR_SERVERMET_UNKNOWN),buffer); } error->Delete(); return false; } } else { // remember (/index) all hashs which are stored in the file for faster checking lateron for (POSITION pos = liKnown2Hashs.GetHeadPosition();pos != 0;) { CAICHRecoveryHashSet::AddStoredAICHHash(liKnown2Hashs.GetNext(pos)); } } lockKnown2Met.Unlock(); // warn the user if he just upgraded if (thePrefs.IsFirstStart() && !m_liToHash.IsEmpty() && !bJustCreated){ LogWarning(GetResString(IDS_AICH_WARNUSER)); } if (!m_liToHash.IsEmpty()){ theApp.QueueLogLine(true, GetResString(IDS_AICH_SYNCTOTAL), m_liToHash.GetCount() ); theApp.emuledlg->sharedfileswnd->sharedfilesctrl.SetAICHHashing(m_liToHash.GetCount()); // let first all normal hashing be done before starting out synchashing CSingleLock sLock1(&theApp.hashing_mut); // only one filehash at a time while (theApp.sharedfiles->GetHashingCount() != 0){ Sleep(100); if (!CemuleDlg::IsRunning()) return 0; } sLock1.Lock(); uint32 cDone = 0; for (POSITION pos = m_liToHash.GetHeadPosition();pos != 0; cDone++) { if (!CemuleDlg::IsRunning()){ // in case of shutdown while still hashing return 0; } theApp.emuledlg->sharedfileswnd->sharedfilesctrl.SetAICHHashing(m_liToHash.GetCount()-cDone); if (theApp.emuledlg->sharedfileswnd->sharedfilesctrl.m_hWnd != NULL) theApp.emuledlg->sharedfileswnd->sharedfilesctrl.ShowFilesCount(); CKnownFile* pCurFile = m_liToHash.GetNext(pos); // just to be sure that the file hasnt been deleted lately if (!(theApp.knownfiles->IsKnownFile(pCurFile) && theApp.sharedfiles->GetFileByID(pCurFile->GetFileHash())) ) continue; theApp.QueueLogLine(false, GetResString(IDS_AICH_CALCFILE), pCurFile->GetFileName()); if(!pCurFile->CreateAICHHashSetOnly()) theApp.QueueDebugLogLine(false, _T("Failed to create AICH Hashset while sync. for file %s"), pCurFile->GetFileName()); } theApp.emuledlg->sharedfileswnd->sharedfilesctrl.SetAICHHashing(0); if (theApp.emuledlg->sharedfileswnd->sharedfilesctrl.m_hWnd != NULL) theApp.emuledlg->sharedfileswnd->sharedfilesctrl.ShowFilesCount(); sLock1.Unlock(); } theApp.QueueDebugLogLine(false, _T("AICHSyncThread finished")); return 0; }
// Define myList. CList<CString,CString&> myList; // Add two elements to the list. myList.AddHead(CString(_T("ABC"))); myList.AddHead(CString(_T("123"))); // Remove the head element and verify the list. // NOTE: once the head is removed, the number of // elements in the list will be one. CString strHead = myList.RemoveHead(); ASSERT((CString(_T("123")) == strHead) && (myList.GetCount() == 1) && (CString(_T("ABC")) == myList.GetHead()));
int CFileSizeFilter::FilterDuplicateList( CList<CFileInfo*,CFileInfo*> & FileList) { int Count = 0; bool FilterIt = false; int Iteration = 0; POSITION xPos; // update status and log g_DupeFileFind.m_DuffStatus.Lock(); g_DupeFileFind.m_DuffStatus.CurrentTaskInfo = m_sName; g_DupeFileFind.m_DuffStatus.SubProgress2.Min = 0; g_DupeFileFind.m_DuffStatus.SubProgress2.Max = FileList.GetCount(); g_DupeFileFind.m_DuffStatus.Unlock(); // //for (i = 0; i < FileList.GetSize(); i++) xPos = FileList.GetHeadPosition(); while (xPos) { switch(m_FilterType) { case FT_NOT_EQUAL: // not equal FilterIt = ( FileList.GetAt(xPos)->Size == m_Value1 ); break; case FT_EQUAL: // equal FilterIt = ( FileList.GetAt(xPos)->Size != m_Value1 ); break; case FT_GREATER_THAN: // greater FilterIt = ( FileList.GetAt(xPos)->Size <= m_Value1 ); break; case FT_LESS_THAN: // less FilterIt = ( FileList.GetAt(xPos)->Size >= m_Value1 ); break; case FT_BETWEEN: // between FilterIt = ( FileList.GetAt(xPos)->Size < m_Value1 || FileList.GetAt(xPos)->Size > m_Value2 ); break; case FT_NOT_BETWEEN: // not between FilterIt = ( FileList.GetAt(xPos)->Size >= m_Value1 && FileList.GetAt(xPos)->Size <= m_Value2 ); break; default: return 0; } if (FilterIt) { //FileList.ElementAt(i)->Unaccessible = true; POSITION Pos2 = xPos; FileList.GetNext(Pos2); delete FileList.GetAt(xPos); FileList.RemoveAt(xPos); //i--; xPos = Pos2; Count++; } else { FileList.GetNext(xPos); } Iteration ++; // update status and log if ( g_DupeFileFind.m_DuffStatus.LockIfUnlocked() ) { g_DupeFileFind.m_DuffStatus.SubProgress2.Pos = Iteration; g_DupeFileFind.m_DuffStatus.Unlock(); } // } return Count; }
void CFileMoveProcess::ProcessFiles ( CList<CFileInfo *, CFileInfo *> & FileList) { CString Msg; SHFILEOPSTRUCT fos; TCHAR pDirBuffer[MAX_PATH]; TCHAR pFilenameBuffer[MAX_PATH]; CFileInfo * pFileInfo; POSITION ListPos; // setup to directory buffer // pDirBuffer = new TCHAR[m_Dir.GetLength()+2]; strcpy( pDirBuffer, (LPCSTR) m_Dir); pDirBuffer[m_Dir.GetLength()] = '\0'; pDirBuffer[m_Dir.GetLength()+1] = '\0'; // // setup struct fos.hwnd = AfxGetMainWnd()->m_hWnd; fos.wFunc= FO_MOVE; fos.pTo = pDirBuffer; fos.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI; fos.lpszProgressTitle = "NULL"; // // set confirmation flag if ( m_YesToAll ) fos.fFlags |= FOF_NOCONFIRMATION; // /* for ( int i = 0; i < FileList.GetSize(); i++) { //if ( ((CDuffDlg*)GetParent()->GetParent())->m_DuplicatePage.m_DupeList.GetCheck(i) == BST_CHECKED ) //{ Temp = FileList.ElementAt(i).m_Filename; //TotalLength += Temp.GetLength() +1; FilesToDelete.Add(Temp); //} } */ // update progress information pDuffStatus->Lock(); pDuffStatus->CurrentTaskStr = "Moving selected duplicate files..."; pDuffStatus->CurrentTaskInfo = ""; pDuffStatus->SubProgress1.Min = 0; pDuffStatus->SubProgress1.Pos = 0; pDuffStatus->SubProgress1.Max = FileList.GetCount(); pDuffStatus->Unlock(); // ListPos = FileList.GetHeadPosition(); while (ListPos) { pFileInfo = FileList.GetAt(ListPos); // process only the selected files if ( pFileInfo->Selected) { if ( ! (pFileInfo->Attributes & FILE_ATTRIBUTE_READONLY) || m_MoveReadOnly ) { /* // remove read-only attribute if ( FileList.ElementAt(i)->ReadOnly ) { DWORD FileAttributes; FileAttributes = GetFileAttributes( FileList.ElementAt(i)->Filename ) FileAttributes ^= FILE_ATTRIBUTE_READONLY; SetFileAttributes(FileList.ElementAt(i)->Filename,FileAttributes ); }*/ _tcscpy(pFilenameBuffer, pFileInfo->GetFullName() ); UINT Length = _tcslen( pFilenameBuffer ); // for (int x = 0; x < FileList.ElementAt(i)->Filename.GetLength(); x++) // { // pFilenameBuffer[x] = FileList.ElementAt(i)->Filename.GetAt(x); // } pFilenameBuffer[Length] = 0; pFilenameBuffer[Length+1] = 0; fos.pFrom = pFilenameBuffer; // g_DupeFileFind.GetDuffDlg()->m_CurrentTaskInfoText.SetWindowText(FileList.ElementAt(i)->GetFullName()); // g_DupeFileFind.GetDuffDlg()->m_CurrentTaskInfoText.RedrawWindow(); // update progress information pDuffStatus->Lock(); pDuffStatus->CurrentTaskInfo = pFileInfo->GetFullName(); pDuffStatus->SubProgress1.Pos++; pDuffStatus->Unlock(); // /* Msg.Format("Moving:\n%s\nto:\n%s",FileList.ElementAt(i)->m_Filename,fos.pTo); MessageBox(NULL,Msg,"FYI",MB_OK); */ if ( SHFileOperation(&fos) ) { Msg.Format("ERROR moving file: %s to %s",pFileInfo->GetFullName(),m_Dir); // g_DupeFileFind.GetDuffDlg()->Log(Msg); } else { Msg.Format("Moved file: %s to %s",pFileInfo->GetFullName(),m_Dir); // g_DupeFileFind.GetDuffDlg()->Log(Msg); } // g_DupeFileFind.GetDuffDlg()->m_ProgressEntire.StepIt(); // delete []pFilenameBuffer; } } FileList.GetNext(ListPos); } // delete[] pDirBuffer; }
void CExport::DoExport(bool previewMode, const CString& pathName, bool bApp, int layoutid) { // Progress dialog is going from 10% to 100% in this function // Make the DLL list CList<CString, CString&> dllList; CPath path; path.SetToCurrentDirectory(); // Allocate some initial space for the binary blocks imageBlock.allocate(20000); // 20kb initial image buffer eventBlock.allocate(5000); // 5kb initial event buffer LayoutBlock.allocate(5000); // 5kb initial frame buffer appBlock.allocate(1000); // 1kb initial app buffer hlslBlock.allocate(5000); // 5kb initial hlsl buffer menuBlock.allocate(1000); // Generate GenerateLayout(dllList); // also loads DLLs to dllList ProgressDlg.SetProgress(15); GenerateEvents(); ProgressDlg.SetProgress(20); GenerateApplicationData(layoutid); ProgressDlg.SetProgress(25); GenerateImages(); // Longest job, use 25-80% ProgressDlg.SetProgress(80); // Open the file for addition of file data in resource m_UpdateHandle = BeginUpdateResource(pathName, FALSE); // Do python GeneratePython(); // HLSL UpdateResource(m_UpdateHandle, "HLSL", MAKEINTRESOURCE(994), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), hlslBlock.ptr(), hlslBlock.size()); ProgressDlg.SetProgress(81); // Images UpdateResource(m_UpdateHandle, "IMAGEBLOCK", MAKEINTRESOURCE(995), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), imageBlock.ptr(), imageBlock.size()); ProgressDlg.SetProgress(82); // Application settings UpdateResource(m_UpdateHandle, "APPBLOCK", MAKEINTRESOURCE(997), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), appBlock.ptr(), appBlock.size()); ProgressDlg.SetProgress(83); // Layouts UpdateResource(m_UpdateHandle, "LEVELBLOCK", MAKEINTRESOURCE(998), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), LayoutBlock.ptr(), LayoutBlock.size()); ProgressDlg.SetProgress(84); // Events UpdateResource(m_UpdateHandle, "EVENTBLOCK", MAKEINTRESOURCE(999), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), eventBlock.ptr(), eventBlock.size()); ProgressDlg.SetProgress(85); // Number of DLLs long c = dllList.GetCount(); CString ibuf; long te = c; te += MvtLookup.size(); ibuf.Format("%d", te); int ilen = 0; // Make string of DLL count in to resource string format wchar_t* resString = AllocStringResourceFormat(ibuf, 1, &ilen); // String of DLL count is a string at resource 1 UpdateResource(m_UpdateHandle, RT_STRING, MAKEINTRESOURCE(1), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), resString, ilen); // AllocStringResourceFormat makes a new string delete [] resString; CString dll; POSITION pos4 = dllList.GetHeadPosition(); int d = 0; for (d = 1000; d < (1000 + c); d++) { // In preview mode, we only put the string of the plugin name in the resources if (previewMode) { dll = dllList.GetNext(pos4); ilen = 0; // Make string of DLL count in to resource string format wchar_t* resString = AllocStringResourceFormat(dll, 1, &ilen); UpdateResource(m_UpdateHandle, RT_STRING, MAKEINTRESOURCE(d), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), resString, ilen); delete [] resString; } // In export EXE mode, the actual DLL file must be dumped in resources else { CString dllPath; dllPath.Format("%sPlugins\\Runtime\\%s", path.GetFullPath(), dllList.GetNext(pos4)); // Get the DLL file binary FILE* f = fopen(dllPath, "rb"); fseek(f, 0, SEEK_END); int fsize = ftell(f); fseek(f, 0, SEEK_SET); BYTE* fdata = new BYTE[fsize]; fread(fdata, 1, fsize, f); fclose(f); UpdateResource(m_UpdateHandle, "DLLBLOCK", MAKEINTRESOURCE(d), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), fdata, fsize); delete [] fdata; } }//for ProgressDlg.SetProgress(88); // Behavior DLLs are added afterwards int iter = 0; for (int Mvt = d; Mvt < (d + MvtLookup.size()); Mvt++) { if (previewMode) { dll = MvtLookup[iter].Name; ilen = 0; // Make string of DLL count in to resource string format wchar_t* resString = AllocStringResourceFormat(dll, 1, &ilen); UpdateResource(m_UpdateHandle, RT_STRING, MAKEINTRESOURCE(Mvt), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), resString, ilen); delete [] resString; iter++; } // In EXE mode export actual DLL file else { CString dllPath; dllPath.Format("%sPlugins\\Runtime\\%s", path.GetFullPath(), MvtLookup[iter].Name); // Get the DLL file binary FILE* f = fopen(dllPath, "rb"); fseek(f, 0, SEEK_END); int fsize = ftell(f); fseek(f, 0, SEEK_SET); BYTE* fdata = new BYTE[fsize]; fread(fdata, 1, fsize, f); fclose(f); UpdateResource(m_UpdateHandle, "DLLBLOCK", MAKEINTRESOURCE(Mvt), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), fdata, fsize); delete [] fdata; iter++; } }//for ProgressDlg.SetProgress(90); ExportResources(previewMode); ProgressDlg.SetProgress(99); UpdateResource(m_UpdateHandle, "MENUBLOCK", MAKEINTRESOURCE(993), MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL), menuBlock.ptr(), menuBlock.size()); // Write DLL segment EndUpdateResource(m_UpdateHandle, FALSE); // Free the bin data imageBlock.free(); eventBlock.free(); appBlock.free(); LayoutBlock.free(); hlslBlock.free(); menuBlock.free(); if (m_bInstaller) { // Now create an installer if necessary CreateInstaller(); // Delete the old file DeleteFile(m_Out); // Transfer installer to path CPath Transfer; Transfer.SetPath(m_Out); CopyFile(m_InstallerOut, m_Out, FALSE); } // Now we're done ProgressDlg.SetProgress(100); }