Clone
ixen <ixen@copyhandler.com>
committed
on 28 Jan 09
Changed default line endings for source files to a consistent state with svn properties.
LoggerImprovements + 5 more
src/libictranslate/ResourceManager.cpp (+18 -2)
4 4         Copyright (C) 2001-2003 Ixen Gerthannes (ixen@interia.pl)
5 5
6 6         This program is free software; you can redistribute it and/or modify
7 7         it under the terms of the GNU General Public License as published by
8 8         the Free Software Foundation; either version 2 of the License, or
9 9         (at your option) any later version.
10 10
11 11         This program is distributed in the hope that it will be useful,
12 12         but WITHOUT ANY WARRANTY; without even the implied warranty of
13 13         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 14         GNU General Public License for more details.
15 15
16 16         You should have received a copy of the GNU General Public License
17 17         along with this program; if not, write to the Free Software
18 18         Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 19 *************************************************************************/
20 20 #include "stdafx.h"
21 21 #include "ResourceManager.h"
22 22 #include "../libicpf/cfg.h"
23 23 #include <assert.h>
24   #include "messages.h"
25 24
26 25 #ifdef _DEBUG
27 26 #define new DEBUG_NEW
28 27 #endif
29 28
30 29 BEGIN_ICTRANSLATE_NAMESPACE
31 30
32 31 #define EMPTY_STRING _t("")
33 32
34 33 CLangData::CLangData() :
35 34         m_pszFilename(NULL),
36 35         m_pszLngName(NULL),
37 36         m_pszBaseFile(NULL),
38 37         m_pszFontFace(NULL),
39 38         m_pszHelpName(NULL),
40 39         m_pszAuthor(NULL),
41 40         m_pszVersion(NULL),
42 41         m_uiSectionID(0)
43 42 {
44 43 }
 
379 378                 else
380 379                         return m_pszFilename;
381 380         }
382 381 }
383 382
384 383 void CLangData::SetFnameData(PTSTR *ppszDst, PCTSTR pszSrc)
385 384 {
386 385         if (*ppszDst)
387 386                 delete [] (*ppszDst);
388 387         const TCHAR* pszLast=NULL;
389 388         if ( (pszLast=_tcsrchr(pszSrc, _T('\\'))) != NULL)
390 389                 pszLast++;
391 390         else
392 391                 pszLast=pszSrc;
393 392
394 393         // copy
395 394         *ppszDst=new TCHAR[_tcslen(pszLast)+1];
396 395         _tcscpy(*ppszDst, pszLast);
397 396 }
398 397
  398 CResourceManager::CResourceManager() :
  399         m_pfnCallback(NULL),
  400         m_hRes(NULL)
  401 {
  402         InitializeCriticalSection(&m_cs);
  403 }
  404
  405 CResourceManager::~CResourceManager()
  406 {
  407         DeleteCriticalSection(&m_cs);
  408 }
  409
  410 void CResourceManager::Init(HMODULE hrc)
  411 {
  412         m_hRes=hrc;
  413 }
  414
399 415 // requires the param with ending '\\'
400 416 void CResourceManager::Scan(LPCTSTR pszFolder, vector<CLangData>* pvData)
401 417 {
402 418         assert(pszFolder);
403 419         assert(pvData);
404 420         if(!pszFolder || !pvData)
405 421                 return;
406 422
407 423         TCHAR szPath[_MAX_PATH];
408 424         _tcscpy(szPath, pszFolder);
409 425         _tcscat(szPath, _T("*.lng"));
410 426         
411 427         WIN32_FIND_DATA wfd;
412 428         HANDLE hFind=::FindFirstFile(szPath, &wfd);
413 429         BOOL bFound=TRUE;
414 430         CLangData ld;
415 431         while (bFound && hFind != INVALID_HANDLE_VALUE)
416 432         {
417 433                 if (!(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
418 434                 {
 
433 449 {
434 450         EnterCriticalSection(&m_cs);
435 451         WORD wOldLang=m_ld.GetLangCode();
436 452         bool bRet=m_ld.ReadTranslation(pszPath);
437 453         WORD wNewLang=m_ld.GetLangCode();
438 454         LeaveCriticalSection(&m_cs);
439 455         if (!bRet)
440 456                 return false;
441 457         
442 458         // update registered dialog boxes
443 459         list<CWnd*>::iterator it=m_lhDialogs.begin();
444 460         while (it != m_lhDialogs.end())
445 461         {
446 462                 if (::IsWindow((*it)->m_hWnd))
447 463                         (*it)->PostMessage(WM_RMNOTIFY, RMNT_LANGCHANGE, (LPARAM)(wOldLang << 16 | wNewLang));
448 464                 it++;
449 465         }
450 466                                 
451 467         // send the notification stuff to the others
452 468         if (m_pfnCallback)
453                   (*m_pfnCallback)(ROT_EVERYWHERE, WM_RMNOTIFY, RMNT_LANGCHANGE, (LPARAM)(wOldLang << 16 | wNewLang));
  469                 (*m_pfnCallback)(RMNT_LANGCHANGE, (wOldLang << 16 | wNewLang));
454 470
455 471         return bRet;
456 472 }
457 473
458 474 HGLOBAL CResourceManager::LoadResource(LPCTSTR pszType, LPCTSTR pszName)
459 475 {
460 476         EnterCriticalSection(&m_cs);
461 477
462 478         // find resource
463 479         HGLOBAL hRet=NULL;
464 480         HRSRC hr=FindResource(m_hRes, pszName, pszType);
465 481         if (hr)
466 482                 hRet=::LoadResource(m_hRes, hr);
467 483
468 484         LeaveCriticalSection(&m_cs);
469 485         return hRet;
470 486 }
471 487
472 488 HACCEL CResourceManager::LoadAccelerators(LPCTSTR pszName)
473 489 {