BabylonDlg.cpp 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. // BabylonDlg.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "Babylon.h"
  22. #include "BabylonDlg.h"
  23. #include "VIEWDBSII.h"
  24. #include "verifydlg.h"
  25. #include "exportdlg.h"
  26. #include "report.h"
  27. #include "matchdlg.h"
  28. #include "retranslatedlg.h"
  29. #include "generatedlg.h"
  30. #include "DlgProxy.h"
  31. #include "xlstuff.h"
  32. #include "fileops.h"
  33. #include <time.h>
  34. #include "iff.h"
  35. #include "loadsave.h"
  36. #include "expimp.h"
  37. #include "proceeddlg.h"
  38. #include "transcs.h"
  39. #ifdef _DEBUG
  40. #define new DEBUG_NEW
  41. #undef THIS_FILE
  42. static char THIS_FILE[] = __FILE__;
  43. #endif
  44. static char buffer[100*1024];
  45. static char buffer2[100*1024];
  46. static char buffer3[100*1024];
  47. static const int INCREMENTS = 100;
  48. static const int MAX_INFO_LEN = 2*1024;
  49. static int found_error;
  50. static int cb_count;
  51. static CBabylonDlg *mainDlg;
  52. static void print_to_log ( const char *text )
  53. {
  54. if ( !found_error )
  55. {
  56. mainDlg->Log ("FAILED", SAME_LINE );
  57. found_error = TRUE;
  58. }
  59. sprintf ( buffer, "String %s", text);
  60. mainDlg->Log ( buffer );
  61. }
  62. static void print_to_log_and_update_progress ( const char *text )
  63. {
  64. print_to_log ( text );
  65. cb_count++;
  66. mainDlg->SetProgress ( cb_count );
  67. }
  68. static void cb_progress ( void )
  69. {
  70. cb_count++;
  71. mainDlg->SetProgress ( cb_count );
  72. }
  73. typedef struct
  74. {
  75. char comment[MAX_INFO_LEN+1];
  76. char context[MAX_INFO_LEN+1];
  77. char speaker[MAX_INFO_LEN+1];
  78. char listener[MAX_INFO_LEN+1];
  79. char wave[MAX_INFO_LEN+1];
  80. int maxlen;
  81. } INFO;
  82. static INFO global_info;
  83. static INFO local_info;
  84. static void init_info ( INFO *info )
  85. {
  86. info->comment[0] = 0;
  87. info->context[0] = 0;
  88. info->speaker[0] = 0;
  89. info->listener[0] = 0;
  90. info->wave[0] = 0;
  91. info->maxlen = 0;
  92. }
  93. static int progress_count;
  94. static void progress_cb ( void )
  95. {
  96. progress_count++;
  97. if ( MainDLG )
  98. {
  99. MainDLG->SetProgress ( progress_count );
  100. }
  101. }
  102. static void removeLeadingAndTrailing ( char *buffer )
  103. {
  104. char *first, *ptr;
  105. char ch;
  106. ptr = first = buffer;
  107. while ( (ch = *first) && iswspace ( ch ))
  108. {
  109. first++;
  110. }
  111. while ( *ptr++ = *first++ );
  112. ptr -= 2;;
  113. while ( (ptr > buffer) && (ch = *ptr) && iswspace ( ch ) )
  114. {
  115. ptr--;
  116. }
  117. ptr++;
  118. *ptr = 0;
  119. }
  120. /////////////////////////////////////////////////////////////////////////////
  121. // CAboutDlg dialog used for App About
  122. class CAboutDlg : public CDialog
  123. {
  124. public:
  125. CAboutDlg();
  126. // Dialog Data
  127. //{{AFX_DATA(CAboutDlg)
  128. enum { IDD = IDD_ABOUTBOX };
  129. //}}AFX_DATA
  130. // ClassWizard generated virtual function overrides
  131. //{{AFX_VIRTUAL(CAboutDlg)
  132. protected:
  133. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  134. //}}AFX_VIRTUAL
  135. // Implementation
  136. protected:
  137. //{{AFX_MSG(CAboutDlg)
  138. virtual BOOL OnInitDialog();
  139. afx_msg void OnButton1();
  140. //}}AFX_MSG
  141. DECLARE_MESSAGE_MAP()
  142. };
  143. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  144. {
  145. //{{AFX_DATA_INIT(CAboutDlg)
  146. //}}AFX_DATA_INIT
  147. }
  148. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  149. {
  150. CDialog::DoDataExchange(pDX);
  151. //{{AFX_DATA_MAP(CAboutDlg)
  152. //}}AFX_DATA_MAP
  153. }
  154. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  155. //{{AFX_MSG_MAP(CAboutDlg)
  156. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  157. //}}AFX_MSG_MAP
  158. END_MESSAGE_MAP()
  159. /////////////////////////////////////////////////////////////////////////////
  160. // CBabylonDlg dialog
  161. IMPLEMENT_DYNAMIC(CBabylonDlg, CDialog);
  162. CBabylonDlg::CBabylonDlg(CWnd* pParent /*=NULL*/)
  163. : CDialog(CBabylonDlg::IDD, pParent)
  164. {
  165. //{{AFX_DATA_INIT(CBabylonDlg)
  166. // NOTE: the ClassWizard will add member initialization here
  167. //}}AFX_DATA_INIT
  168. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  169. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  170. m_pAutoProxy = NULL;
  171. }
  172. CBabylonDlg::~CBabylonDlg()
  173. {
  174. // If there is an automation proxy for this dialog, set
  175. // its back pointer to this dialog to NULL, so it knows
  176. // the dialog has been deleted.
  177. if (m_pAutoProxy != NULL)
  178. m_pAutoProxy->m_pDialog = NULL;
  179. }
  180. void CBabylonDlg::DoDataExchange(CDataExchange* pDX)
  181. {
  182. CDialog::DoDataExchange(pDX);
  183. //{{AFX_DATA_MAP(CBabylonDlg)
  184. // NOTE: the ClassWizard will add DDX and DDV calls here
  185. //}}AFX_DATA_MAP
  186. }
  187. BEGIN_MESSAGE_MAP(CBabylonDlg, CDialog)
  188. //{{AFX_MSG_MAP(CBabylonDlg)
  189. ON_WM_SYSCOMMAND()
  190. ON_WM_PAINT()
  191. ON_WM_QUERYDRAGICON()
  192. ON_WM_CLOSE()
  193. ON_WM_DROPFILES()
  194. ON_BN_CLICKED(IDC_VIEWDBS, OnViewdbs)
  195. ON_BN_CLICKED(IDC_RELOAD, OnReload)
  196. ON_BN_CLICKED(IDC_UPDATE, OnUpdate)
  197. ON_BN_CLICKED(IDC_SAVE, OnSave)
  198. ON_BN_CLICKED(IDC_WARNINGS, OnWarnings)
  199. ON_BN_CLICKED(IDC_ERRORS, OnErrors)
  200. ON_BN_CLICKED(IDC_CHANGES, OnChanges)
  201. ON_BN_CLICKED(IDC_EXPORT, OnExport)
  202. ON_BN_CLICKED(IDC_IMPORT, OnImport)
  203. ON_BN_CLICKED(IDC_GENERATE, OnGenerate)
  204. ON_BN_CLICKED(IDC_DIALOG, OnVerifyDialog)
  205. ON_BN_CLICKED(IDC_TRANSLATIONS, OnTranslations)
  206. ON_CBN_SELCHANGE(IDC_COMBOLANG, OnSelchangeCombolang)
  207. ON_BN_CLICKED(IDC_REPORTS, OnReports)
  208. ON_CBN_DBLCLK(IDC_COMBOLANG, OnDblclkCombolang)
  209. ON_BN_CLICKED(IDC_RESET, OnReset)
  210. ON_BN_CLICKED(IDC_SENT, OnSent)
  211. //}}AFX_MSG_MAP
  212. END_MESSAGE_MAP()
  213. /////////////////////////////////////////////////////////////////////////////
  214. // CBabylonDlg message handlers
  215. BOOL CBabylonDlg::OnInitDialog()
  216. {
  217. CDialog::OnInitDialog();
  218. // Add "About..." menu item to system menu.
  219. // IDM_ABOUTBOX must be in the system command range.
  220. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  221. ASSERT(IDM_ABOUTBOX < 0xF000);
  222. CMenu* pSysMenu = GetSystemMenu(FALSE);
  223. if (pSysMenu != NULL)
  224. {
  225. CString strAboutMenu;
  226. strAboutMenu.LoadString(IDS_ABOUTBOX);
  227. if (!strAboutMenu.IsEmpty())
  228. {
  229. pSysMenu->AppendMenu(MF_SEPARATOR);
  230. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  231. }
  232. }
  233. // Set the icon for this dialog. The framework does this automatically
  234. // when the application's main window is not a dialog
  235. SetIcon(m_hIcon, TRUE); // Set big icon
  236. SetIcon(m_hIcon, FALSE); // Set small icon
  237. // TODO: Add extra initialization here
  238. progress = (CProgressCtrl *) GetDlgItem ( IDC_PROGRESS1 );
  239. percent = (CStatic *) GetDlgItem ( IDC_PERCENT );
  240. SetWindowText ( AppTitle );
  241. Log ( AppTitle );
  242. {
  243. char buffer[100];
  244. char date[50];
  245. char time[50];
  246. _strtime ( time );
  247. _strdate ( date );
  248. sprintf ( buffer, "Session Date: %s %s\n", date, time);
  249. Log ( buffer );
  250. }
  251. Status ("Initializing dialog");
  252. operate_always = FALSE;
  253. combo = ( CComboBox *)GetDlgItem ( IDC_COMBOLANG );
  254. int index = 0;
  255. int lang_index = 0;
  256. LANGINFO *info;
  257. while ( (info = GetLangInfo ( lang_index )) )
  258. {
  259. combo->InsertString ( index, info->name );
  260. combo->SetItemDataPtr ( index, info );
  261. index++;
  262. lang_index++;
  263. }
  264. max_index = index;
  265. combo->SetCurSel ( 0 );
  266. // do any initialization
  267. #if 0
  268. // initialize audio
  269. if ( !AIL_quick_startup ( TRUE, FALSE, 22050, 16, 2 ) )
  270. {
  271. sprintf ( buffer, "Falied to init audio.\n\nReason:%s\n", AIL_last_error ());
  272. AfxMessageBox ( buffer );
  273. }
  274. else
  275. {
  276. onexit ( (_onexit_t ) AIL_quick_shutdown );
  277. }
  278. #endif
  279. Ready();;
  280. PostMessage ( WM_COMMAND, MAKEWPARAM ( IDC_RELOAD, BN_CLICKED ));
  281. return TRUE; // return TRUE unless you set the focus to a control
  282. }
  283. void CBabylonDlg::OnSysCommand(UINT nID, LPARAM lParam)
  284. {
  285. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  286. {
  287. CAboutDlg dlgAbout;
  288. dlgAbout.DoModal();
  289. }
  290. else
  291. {
  292. CDialog::OnSysCommand(nID, lParam);
  293. }
  294. }
  295. // If you add a minimize button to your dialog, you will need the code below
  296. // to draw the icon. For MFC applications using the document/view model,
  297. // this is automatically done for you by the framework.
  298. void CBabylonDlg::OnPaint()
  299. {
  300. if (IsIconic())
  301. {
  302. CPaintDC dc(this); // device context for painting
  303. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  304. // Center icon in client rectangle
  305. int cxIcon = GetSystemMetrics(SM_CXICON);
  306. int cyIcon = GetSystemMetrics(SM_CYICON);
  307. CRect rect;
  308. GetClientRect(&rect);
  309. int x = (rect.Width() - cxIcon + 1) / 2;
  310. int y = (rect.Height() - cyIcon + 1) / 2;
  311. // Draw the icon
  312. dc.DrawIcon(x, y, m_hIcon);
  313. }
  314. else
  315. {
  316. CDialog::OnPaint();
  317. }
  318. }
  319. // The system calls this to obtain the cursor to display while the user drags
  320. // the minimized window.
  321. HCURSOR CBabylonDlg::OnQueryDragIcon()
  322. {
  323. return (HCURSOR) m_hIcon;
  324. }
  325. // Automation servers should not exit when a user closes the UI
  326. // if a controller still holds on to one of its objects. These
  327. // message handlers make sure that if the proxy is still in use,
  328. // then the UI is hidden but the dialog remains around if it
  329. // is dismissed.
  330. void CBabylonDlg::OnClose()
  331. {
  332. if (CanExit())
  333. {
  334. if ( !CanProceed ())
  335. {
  336. return ;
  337. }
  338. CDialog::OnOK();
  339. if ( !SaveLog () )
  340. {
  341. AfxMessageBox ("Failed to save log!\n\nMake sure babylon.log is writable");
  342. }
  343. }
  344. }
  345. //DEL void CBabylonDlg::OnOK()
  346. //DEL {
  347. //DEL if (CanExit())
  348. //DEL CDialog::OnOK();
  349. //DEL }
  350. //DEL void CBabylonDlg::OnCancel()
  351. //DEL {
  352. //DEL if (CanExit())
  353. //DEL CDialog::OnCancel();
  354. //DEL }
  355. BOOL CBabylonDlg::CanExit()
  356. {
  357. // If the proxy object is still around, then the automation
  358. // controller is still holding on to this application. Leave
  359. // the dialog around, but hide its UI.
  360. if (m_pAutoProxy != NULL)
  361. {
  362. ShowWindow(SW_HIDE);
  363. return FALSE;
  364. }
  365. return TRUE;
  366. }
  367. //DEL void CBabylonDlg::OnBrowse()
  368. //DEL {
  369. //DEL static char szFilter[] = "XL Files (*.XLS)\0*.xls\0\0\0";
  370. //DEL
  371. //DEL // TODO: Add your control notification handler code here
  372. //DEL CFileDialog *dlg = new CFileDialog ( TRUE, "xls", "*.xls", OFN_FILEMUSTEXIST, szFilter, this );
  373. //DEL if ( dlg )
  374. //DEL {
  375. //DEL dlg->DoModal ();
  376. //DEL if ( dlg->GetPathName() != "*.xls" )
  377. //DEL {
  378. //DEL SelectFile ( LPCTSTR ( dlg->GetPathName() ));
  379. //DEL }
  380. //DEL else
  381. //DEL {
  382. //DEL SelectFile ( NULL );
  383. //DEL }
  384. //DEL delete dlg;
  385. //DEL }
  386. //DEL }
  387. //DEL void CBabylonDlg::OnChangeXlFilename()
  388. //DEL {
  389. //DEL // TODO: If this is a RICHEDIT control, the control will not
  390. //DEL // send this notification unless you override the CDialog::OnInitDialog()
  391. //DEL // function and call CRichEditCtrl().SetEventMask()
  392. //DEL // with the ENM_CHANGE flag ORed into the mask.
  393. //DEL
  394. //DEL // TODO: Add your control notification handler code here
  395. //DEL
  396. //DEL }
  397. void CBabylonDlg::OnExport()
  398. {
  399. if ( CanOperate ())
  400. {
  401. CExportDlg dlg;
  402. if ( dlg.DoModal () == IDOK )
  403. {
  404. ExportTranslations ( MainDB, dlg.Filename (), dlg.Language(), dlg.Options(), this );
  405. }
  406. }
  407. }
  408. BOOL CAboutDlg::OnInitDialog()
  409. {
  410. CDialog::OnInitDialog();
  411. // TODO: Add extra initialization here
  412. char string[200];
  413. sprintf ( string, "Built: %s, %s", __DATE__, __TIME__ );
  414. SetDlgItemText ( IDC_BUILD, string );
  415. return TRUE; // return TRUE unless you set the focus to a control
  416. // EXCEPTION: OCX Property Pages should return FALSE
  417. }
  418. void CBabylonDlg::OnDropFiles(HDROP hDropInfo)
  419. {
  420. // TODO: Add your message handler code here and/or call default
  421. // char buffer[1024];
  422. //
  423. // if ( DragQueryFile(hDropInfo, 0, buffer, sizeof ( buffer )-1))
  424. // {
  425. //
  426. // if ( ConvertStrFile ( buffer ) )
  427. // {
  428. // return;
  429. // }
  430. //
  431. // if ( SelectFile ( buffer ) )
  432. // {
  433. // OnExport ();
  434. // }
  435. // }
  436. }
  437. //DEL int CBabylonDlg::SelectFile ( const char *buffer )
  438. //DEL {
  439. //DEL char *p;
  440. //DEL CWnd *wnd = GetDlgItem ( IDC_EXPORT );
  441. //DEL
  442. //DEL if ( buffer && (p = strchr ( buffer, '.' )) && !stricmp ( p, ".xls"))
  443. //DEL {
  444. //DEL SetDlgItemText ( IDC_XLFILE, buffer );
  445. //DEL SetDlgItemText ( IDC_STATUS, "File selected: Click 'convert' to start process");
  446. //DEL wnd->EnableWindow ( TRUE );
  447. //DEL return TRUE;
  448. //DEL }
  449. //DEL if ( buffer )
  450. //DEL {
  451. //DEL AfxMessageBox ("Must be an Excel file");
  452. //DEL }
  453. //DEL wnd->EnableWindow ( FALSE );
  454. //DEL SetDlgItemText ( IDC_STATUS, "Select excel file...");
  455. //DEL SetDlgItemText ( IDC_XLFILE, "Browse or drop excel file to be convertered" );
  456. //DEL
  457. //DEL return FALSE;
  458. //DEL }
  459. //DEL int CBabylonDlg::ConvertStrFile ( const char *buffer )
  460. //DEL {
  461. //DEL char *p;
  462. //DEL char filename[400];
  463. //DEL
  464. //DEL if ( buffer && (p = strchr ( buffer, '.' )) && !stricmp ( p, ".str"))
  465. //DEL {
  466. //DEL ParseDB db;
  467. //DEL SetDlgItemText ( IDC_XLFILE, buffer );
  468. //DEL EnableWindow ( FALSE );
  469. //DEL SetDlgItemText ( IDC_STATUS, "Parsing .str file");
  470. //DEL
  471. //DEL if ( db.ParseStrFile ( buffer, this ) )
  472. //DEL {
  473. //DEL SetDlgItemText ( IDC_STATUS, "Creating .xls file");
  474. //DEL strcpy ( filename, buffer );
  475. //DEL p = strchr ( filename, '.' );
  476. //DEL strcpy ( p, ".xls" );
  477. //DEL
  478. //DEL if ( db.CreateXLFile ( filename, this ) )
  479. //DEL {
  480. //DEL SetDlgItemText ( IDC_STATUS, "Created .xls file");
  481. //DEL }
  482. //DEL else
  483. //DEL {
  484. //DEL SetDlgItemText ( IDC_STATUS, "Falied to create .xls file");
  485. //DEL }
  486. //DEL
  487. //DEL }
  488. //DEL else
  489. //DEL {
  490. //DEL SetDlgItemText ( IDC_STATUS, "Failed to parse .str file");
  491. //DEL
  492. //DEL }
  493. //DEL
  494. //DEL EnableWindow ( TRUE );
  495. //DEL return TRUE;
  496. //DEL }
  497. //DEL return FALSE;
  498. //DEL }
  499. static int bytes_copied;
  500. static int done_copy;
  501. static int start_copy;
  502. static LogFormat cpy_format;
  503. static DWORD CALLBACK streamin_cb ( DWORD dwCookie, LPBYTE pbBuff, LONG bytes, LONG *transfered )
  504. {
  505. char *src = (char *) dwCookie;
  506. int count = 0;
  507. src += bytes_copied;
  508. if ( bytes && start_copy )
  509. {
  510. if ( cpy_format == NEW_LINE )
  511. {
  512. *pbBuff++ = '\n';
  513. count++;
  514. bytes--;
  515. }
  516. start_copy = FALSE;
  517. }
  518. while ( bytes-- )
  519. {
  520. if ( !*src )
  521. {
  522. done_copy = TRUE;
  523. break;
  524. }
  525. *pbBuff++ = *src++;
  526. bytes_copied++;
  527. count++;
  528. }
  529. *transfered = count;
  530. return 0;
  531. }
  532. static DWORD CALLBACK streamout_cb ( DWORD dwCookie, LPBYTE pbBuff, LONG bytes, LONG *transfered )
  533. {
  534. FILE *log = (FILE *) dwCookie;
  535. int count = 0;
  536. *transfered = fwrite ( pbBuff, 1, bytes, log );
  537. return *transfered == -1;
  538. }
  539. void CBabylonDlg::Log( const char *string, LogFormat format)
  540. {
  541. CRichEditCtrl *rec;
  542. EDITSTREAM es;
  543. int lines;
  544. int end_pos;
  545. rec = (CRichEditCtrl*)GetDlgItem ( IDC_LOG );
  546. lines = rec->GetLineCount ( );
  547. end_pos = rec->LineIndex ( lines );
  548. rec->SetSel ( end_pos, end_pos );
  549. //rec->SetReadOnly ( FALSE );
  550. es.dwCookie = (DWORD) string;
  551. es.dwError = 0;
  552. es.pfnCallback = streamin_cb;
  553. bytes_copied = 0;
  554. done_copy = FALSE;
  555. start_copy = TRUE;
  556. cpy_format = format;
  557. rec->StreamIn ( SF_TEXT | SFF_SELECTION, es );
  558. //rec->SetReadOnly ( TRUE );
  559. lines = rec->GetLineCount ( );
  560. rec->LineScroll ( -lines, 0 );
  561. rec->LineScroll ( lines - 10, 0 );
  562. }
  563. void CBabylonDlg::Status( const char *string, int log )
  564. {
  565. char buffer[200];
  566. int max_len;
  567. if ( log )
  568. {
  569. Log ( string );
  570. }
  571. max_len = sizeof ( buffer ) -1;
  572. strcpy ( buffer, "Status: ");
  573. max_len -= strlen ( buffer );
  574. strncat ( buffer, string, max_len );
  575. SetDlgItemText ( IDC_STATUS, buffer );
  576. }
  577. int CBabylonDlg::SaveLog()
  578. {
  579. FILE *log = NULL;
  580. EDITSTREAM es;
  581. CRichEditCtrl *rec = (CRichEditCtrl *) GetDlgItem ( IDC_LOG );
  582. int ok = FALSE;
  583. if ( ! (log = fopen ("babylon.log", "a+t" )))
  584. {
  585. goto error;
  586. }
  587. {
  588. char *buffer = "\nLOG START ******************\n\n";
  589. fwrite ( buffer, 1, strlen ( buffer ), log );
  590. }
  591. es.dwCookie = (DWORD) log;
  592. es.dwError = 0;
  593. es.pfnCallback = streamout_cb;
  594. bytes_copied = 0;
  595. done_copy = FALSE;
  596. rec->StreamOut ( SF_TEXT, es );
  597. if ( es.dwError )
  598. {
  599. goto error;
  600. }
  601. {
  602. char *buffer = "\nQuiting Babylon\n\nLOG END ******************\n\n";
  603. fwrite ( buffer, 1, strlen ( buffer ), log );
  604. }
  605. ok = TRUE;
  606. error:
  607. if ( log )
  608. {
  609. fclose ( log );
  610. }
  611. return ok;
  612. }
  613. void CBabylonDlg::OnViewdbs()
  614. {
  615. // TODO: Add your control notification handler code here
  616. VIEWDBSII dlg;
  617. ViewChanges = FALSE;
  618. dlg.DoModal ();
  619. }
  620. static int readToEndOfQuote( FILE *file, char *in, char *out, char *wavefile, int maxBufLen, int in_comment )
  621. {
  622. int slash = FALSE;
  623. int state = 0;
  624. int line_start = FALSE;
  625. char ch;
  626. int new_lines = 0;
  627. int ccount = 0;
  628. while ( maxBufLen )
  629. {
  630. // get next char
  631. if ( in )
  632. {
  633. if ( !(ch = *in++))
  634. {
  635. in = NULL; // have exhausted the input buffer
  636. ch = getc ( file );
  637. }
  638. }
  639. else
  640. {
  641. ch = getc ( file );
  642. }
  643. if ( ch == EOF )
  644. {
  645. AfxMessageBox ( "Missing terminating quote");
  646. return new_lines;
  647. }
  648. if ( ch == '\n' )
  649. {
  650. line_start = TRUE;
  651. if ( !in )
  652. {
  653. new_lines++;
  654. }
  655. slash = FALSE;
  656. ccount = 0;
  657. ch = ' ';
  658. }
  659. else if ( line_start && ( ch == '/' || iswspace ( ch )) )
  660. {
  661. continue;
  662. }
  663. else if ( ch == '\\' && !slash)
  664. {
  665. slash = TRUE;
  666. }
  667. else if ( ch == '\\' && slash)
  668. {
  669. slash = FALSE;
  670. }
  671. else if ( ch == '"' && !slash )
  672. {
  673. break; // done
  674. }
  675. else
  676. {
  677. slash = FALSE;
  678. }
  679. if ( iswspace ( ch ))
  680. {
  681. ch = ' ';
  682. }
  683. else
  684. {
  685. line_start = FALSE;
  686. }
  687. *out++ = ch;
  688. maxBufLen--;
  689. }
  690. *out = 0;
  691. if ( !wavefile )
  692. {
  693. return new_lines;
  694. }
  695. int len = 0;
  696. while ( TRUE )
  697. {
  698. // get next char
  699. if ( in )
  700. {
  701. if ( !(ch = *in++))
  702. {
  703. in = NULL; // have exhausted the input buffer
  704. ch = getc ( file );
  705. }
  706. }
  707. else
  708. {
  709. ch = getc ( file );
  710. }
  711. if ( ch == '\n' || ch == EOF )
  712. {
  713. if ( !in )
  714. {
  715. new_lines++;
  716. }
  717. break;
  718. }
  719. switch ( state )
  720. {
  721. case 0:
  722. if ( iswspace ( ch ) || ch == '=' )
  723. {
  724. break;
  725. }
  726. state = 1;
  727. case 1:
  728. if ( (( ch >= 'a' && ch <= 'z') || ( ch >= 'A' && ch <='Z') || (ch >= '0' && ch <= '9') || ch == '_') )
  729. {
  730. *wavefile++ = ch;
  731. len++;
  732. break;
  733. }
  734. state = 2;
  735. case 2:
  736. break;
  737. }
  738. }
  739. *wavefile = 0;
  740. if ( len )
  741. {
  742. if ( ( ch = *(wavefile-1)) < '0' || ch > '9' )
  743. {
  744. // remove last character
  745. *(wavefile-1) = 0;
  746. }
  747. }
  748. return new_lines;
  749. }
  750. enum
  751. {
  752. START,
  753. TOKEN,
  754. COLON,
  755. ARG
  756. };
  757. static int getString ( FILE *file, char *in, char *out )
  758. {
  759. int bytes = MAX_INFO_LEN;
  760. int new_lines = 0;
  761. char ch;
  762. char *ptr = out;
  763. {
  764. while ( (ch = *in++) && ch != '\n' && bytes )
  765. {
  766. *ptr++ = ch;
  767. bytes--;
  768. }
  769. }
  770. *ptr = 0;
  771. ConvertMetaChars ( out );
  772. StripSpaces ( out );
  773. return new_lines;
  774. }
  775. static char *getToken ( char *buffer, char *token, int bytes )
  776. {
  777. char ch;
  778. int state = START;
  779. *token = 0;
  780. while ( (ch = *buffer) && ch != '\n' && bytes )
  781. {
  782. switch ( state )
  783. {
  784. case START:
  785. if ( ch == '/' || iswspace ( ch ))
  786. {
  787. break;
  788. }
  789. state = TOKEN;
  790. case TOKEN:
  791. if ( !iswspace ( ch ) && ch !=':' )
  792. {
  793. *token++ = ch;
  794. bytes--;
  795. break;
  796. }
  797. *token = 0;
  798. state = COLON;
  799. case COLON:
  800. if ( ch != ':' )
  801. {
  802. break;
  803. }
  804. state = ARG;
  805. break;
  806. case ARG:
  807. if ( iswspace ( ch ) )
  808. {
  809. break;
  810. }
  811. return buffer;
  812. }
  813. buffer++;
  814. }
  815. *token = 0;
  816. return buffer;
  817. }
  818. static int parseComment ( FILE *file, char *buffer, INFO *info )
  819. {
  820. char token[256];
  821. int new_lines = 0;
  822. buffer = getToken ( buffer, token, sizeof (token) -1 );
  823. if ( !token )
  824. {
  825. return new_lines;
  826. }
  827. if ( !stricmp ( token, "COMMENT" ) )
  828. {
  829. new_lines += getString ( file, buffer, info->comment );
  830. }
  831. else if ( !stricmp ( token, "CONTEXT" ) )
  832. {
  833. new_lines += getString ( file, buffer, info->context );
  834. }
  835. else if ( !stricmp ( token, "SPEAKER" ) )
  836. {
  837. new_lines += getString ( file, buffer, info->speaker );
  838. }
  839. else if ( !stricmp ( token, "LISTENER" ) )
  840. {
  841. new_lines += getString ( file, buffer, info->listener );
  842. }
  843. else if ( !stricmp ( token, "MAXLEN" ) )
  844. {
  845. info->maxlen = atoi ( buffer );
  846. }
  847. else if ( !stricmp ( token, "WAVE" ) )
  848. {
  849. new_lines += getString ( file, buffer, info->wave );
  850. }
  851. return new_lines;
  852. }
  853. static int getLabelCount( char *filename )
  854. {
  855. int count = 0;
  856. FILE *fp;
  857. if ( ! ( fp = fopen ( filename, "rt" )))
  858. {
  859. return 0;
  860. }
  861. while(TRUE)
  862. {
  863. if( fscanf( fp, "%s", buffer ) == EOF )
  864. break;
  865. if ( !stricmp( buffer, "END" ) )
  866. {
  867. count++;
  868. }
  869. }
  870. fclose ( fp );
  871. return count;
  872. }
  873. int CBabylonDlg::LoadStrFile ( TransDB *db, const char *filename, void (*cb) ( void ) )
  874. {
  875. FILE *file = NULL;
  876. BabylonLabel *label = NULL;
  877. int status = FALSE;
  878. int line_number = 0;
  879. int label_count = 0;
  880. int text_dup_count = 0;
  881. int label_dup_count = 0;
  882. init_info ( &global_info );
  883. if ( !(file = fopen ( filename, "rt" ) ))
  884. {
  885. goto exit;
  886. }
  887. while ( fgets ( buffer, sizeof(buffer)-1, file ) )
  888. {
  889. line_number++;
  890. removeLeadingAndTrailing ( buffer );
  891. if ( !buffer[0] || (buffer[0] == '/' && buffer[1] == '/') )
  892. {
  893. line_number += parseComment ( file, buffer, &global_info );
  894. continue;
  895. }
  896. label = new BabylonLabel ( );
  897. label->SetName ( buffer );
  898. label->LockName ();
  899. label->SetLineNumber ( line_number );
  900. db->AddLabel ( label );
  901. local_info = global_info;
  902. local_info.wave[0] = 0; // wave file name is only locally set
  903. while( TRUE )
  904. {
  905. if ( !fgets ( buffer, sizeof(buffer)-1, file ))
  906. {
  907. AfxMessageBox ( "Unexpected end of file" );
  908. goto exit;
  909. }
  910. line_number++;
  911. removeLeadingAndTrailing ( buffer );
  912. if ( !stricmp ( buffer, "END" ) )
  913. {
  914. break;
  915. }
  916. if ( !buffer[0] || (buffer[0] == '/' && buffer[1] == '/') )
  917. {
  918. line_number += parseComment ( file, buffer, &local_info );
  919. continue;
  920. }
  921. if ( buffer[0] == '"' )
  922. {
  923. int line = line_number;
  924. strcat ( buffer, "\n" );
  925. line_number += readToEndOfQuote( file, &buffer[1], buffer2, buffer3, sizeof(buffer2)-1, FALSE );
  926. BabylonText *text = new BabylonText ( );
  927. text->Set ( buffer2 );
  928. text->FormatMetaString ();
  929. text->LockText ();
  930. if ( buffer3[0] )
  931. {
  932. text->SetWave ( buffer3 );
  933. }
  934. else
  935. {
  936. text->SetWave ( local_info.wave );
  937. }
  938. text->SetLineNumber ( line );
  939. label->AddText ( text );
  940. }
  941. }
  942. label->SetComment ( local_info.comment );
  943. label->SetContext ( local_info.context );
  944. label->SetSpeaker ( local_info.speaker );
  945. label->SetListener ( local_info.listener );
  946. label->SetMaxLen ( local_info.maxlen );
  947. if ( cb )
  948. {
  949. cb ();
  950. }
  951. label = NULL;
  952. }
  953. status = TRUE;
  954. exit:
  955. db->ClearChanges ();
  956. if ( label )
  957. {
  958. delete label;
  959. }
  960. if ( file )
  961. {
  962. fclose ( file );
  963. }
  964. return status;
  965. }
  966. int CBabylonDlg::CanProceed ( void )
  967. {
  968. if ( MainDB->IsChanged ())
  969. {
  970. retry:
  971. int result = AfxMessageBox ( "Main database has changed!\n\n Do you wish to save it before proceeding?", MB_YESNOCANCEL );
  972. if ( result == IDCANCEL )
  973. {
  974. return FALSE;
  975. }
  976. else if ( result == IDYES )
  977. {
  978. if ( !SaveMainDB () )
  979. {
  980. AfxMessageBox ("Save failed!\n\nCanceling operation");
  981. return FALSE;
  982. }
  983. }
  984. else
  985. {
  986. int result = AfxMessageBox ( "Are you sure you don't want to save?\n\nAll current changes will be lost", MB_YESNO );
  987. if ( result == IDNO )
  988. {
  989. goto retry;
  990. }
  991. }
  992. }
  993. return TRUE;
  994. }
  995. int CBabylonDlg::CanOperate ( void )
  996. {
  997. if ( operate_always )
  998. {
  999. return TRUE;
  1000. }
  1001. if ( BabylonstrDB->IsChanged() || BabylonstrDB->HasErrors () )
  1002. {
  1003. char *string = "Unknown problem!\n\n\nProceed anyway?";
  1004. if ( BabylonstrDB->HasErrors ())
  1005. {
  1006. string = "Generals.str has errors! As a result the translation database is not up to date!\n\nRecommend you fix problems in Generals.str before proceeding.\n\n\n\nDo you wish to continue anyway?";
  1007. }
  1008. if ( BabylonstrDB->IsChanged ())
  1009. {
  1010. string = "The translation database is not up to date! Generals.str has changed since the last time the database was updated.\n\nRecommend you update the database before proceeding.\n\n\n\nDo you wish to continue anyway?";
  1011. }
  1012. ProceedDlg dlg ( string );
  1013. int result = dlg.DoModal ();
  1014. if ( result == IDALWAYS )
  1015. {
  1016. operate_always = TRUE;
  1017. }
  1018. return result != IDNO;
  1019. }
  1020. return TRUE;
  1021. }
  1022. void CBabylonDlg::OnReload()
  1023. {
  1024. int num_errors;
  1025. int num_warnings;
  1026. int count = 0;
  1027. int str_loaded = FALSE;
  1028. int db_loaded = FALSE;
  1029. int db_readonly = FALSE;
  1030. int db_error = FALSE;
  1031. int do_update = FALSE;
  1032. int errors;
  1033. CWnd *win;
  1034. // TODO: Add your control notification handler code here
  1035. if ( !CanProceed ())
  1036. {
  1037. return;
  1038. }
  1039. BabylonstrDB->Clear ();
  1040. BabylonstrDB->ClearChanges ();
  1041. MainDB->Clear ();
  1042. MainDB->ClearChanges ();
  1043. count += getLabelCount ( BabylonstrFilename );
  1044. count += GetLabelCountDB ( MainXLSFilename );
  1045. progress_count = 0;
  1046. win = GetDlgItem ( IDC_ERRORS );
  1047. win->EnableWindow ( FALSE );
  1048. win = GetDlgItem ( IDC_WARNINGS );
  1049. win->EnableWindow ( FALSE );
  1050. win = GetDlgItem ( IDC_UPDATE );
  1051. win->EnableWindow ( TRUE);
  1052. win = GetDlgItem ( IDC_SAVE );
  1053. win->EnableWindow ( TRUE);
  1054. win = GetDlgItem ( IDC_IMPORT );
  1055. win->EnableWindow ( TRUE);
  1056. win = GetDlgItem ( IDC_EXPORT );
  1057. win->EnableWindow ( TRUE);
  1058. InitProgress ( count );
  1059. Log ("" );
  1060. if ( FileExists ( BabylonstrFilename ))
  1061. {
  1062. if ( (errors = ValidateStrFile ( BabylonstrFilename )) )
  1063. {
  1064. if ( errors == -1 )
  1065. {
  1066. if ( AfxMessageBox ( "Unable to verify string file!\n\nMake sure \"strcheck.exe\" is in your path and \"strcheck.rst\" is writeable.\n\nDo you wish to continue loading? \n\nWarning: Any errors in the string file could cause inappropiate updates to the database.", MB_YESNO ) == IDYES )
  1067. {
  1068. errors = 0;
  1069. }
  1070. }
  1071. else
  1072. {
  1073. sprintf ( buffer, "\"%s\" has %d formating error%s!\n\nFile will not be loaded.", BabylonstrFilename, errors, errors == 1 ? "" : "s" );
  1074. AfxMessageBox ( buffer );
  1075. }
  1076. }
  1077. if ( !errors )
  1078. {
  1079. sprintf ( buffer, "Loading \"%s\"...", BabylonstrFilename );
  1080. Status ( buffer );
  1081. if ( !(str_loaded = LoadStrFile ( BabylonstrDB, BabylonstrFilename, progress_cb )) )
  1082. {
  1083. Log ( "FAILED", SAME_LINE );
  1084. BabylonstrDB->Clear ();
  1085. BabylonstrDB->ClearChanges ();
  1086. }
  1087. }
  1088. else
  1089. {
  1090. sprintf ( buffer, "Loading \"%s\"...NOT LOADED", BabylonstrFilename );
  1091. Log ( buffer );
  1092. }
  1093. }
  1094. else
  1095. {
  1096. sprintf ( buffer, "Loading \"%s\"...", BabylonstrFilename );
  1097. Status ( buffer );
  1098. Log ( "FILE NOT FOUND", SAME_LINE );
  1099. }
  1100. if ( str_loaded )
  1101. {
  1102. sprintf ( buffer, "Validating \"%s\"...", BabylonstrFilename );
  1103. Status ( buffer, FALSE );
  1104. if ( (num_errors = BabylonstrDB->Errors ( )))
  1105. {
  1106. sprintf ( buffer, "Generals.str has %d error(s):\n\nClick \"Errors\" for a detailed list.\n\nAll errors must be fixed before \"Update\" will be enabled.", num_errors );
  1107. AfxMessageBox ( buffer );
  1108. win = GetDlgItem ( IDC_UPDATE );
  1109. win->EnableWindow ( FALSE);
  1110. win = GetDlgItem ( IDC_ERRORS );
  1111. win->EnableWindow ( TRUE );
  1112. }
  1113. if ( (num_warnings = BabylonstrDB->Warnings()))
  1114. {
  1115. win = GetDlgItem ( IDC_WARNINGS );
  1116. win->EnableWindow ( TRUE );
  1117. }
  1118. if ( !num_errors && !num_warnings )
  1119. {
  1120. Log ( "OK", SAME_LINE );
  1121. }
  1122. else
  1123. {
  1124. sprintf ( buffer, "%d errors, %d warnings OK", num_errors, num_warnings );
  1125. Log ( buffer, SAME_LINE );
  1126. }
  1127. }
  1128. sprintf ( buffer, "Loading \"%s\"...", MainXLSFilename );
  1129. Status ( buffer );
  1130. if ( FileExists ( MainXLSFilename ))
  1131. {
  1132. if ( !(db_loaded = LoadMainDB ( MainDB, MainXLSFilename, progress_cb )) )
  1133. {
  1134. Log ( "FAILED", SAME_LINE );
  1135. MainDB->Clear ();
  1136. MainDB->ClearChanges ();
  1137. db_error = TRUE;
  1138. win = GetDlgItem ( IDC_UPDATE );
  1139. win->EnableWindow ( FALSE);
  1140. win = GetDlgItem ( IDC_SAVE );
  1141. win->EnableWindow ( FALSE);
  1142. win = GetDlgItem ( IDC_EXPORT );
  1143. win->EnableWindow ( FALSE);
  1144. win = GetDlgItem ( IDC_IMPORT );
  1145. win->EnableWindow ( FALSE);
  1146. }
  1147. else
  1148. {
  1149. if ( FileAttribs ( MainXLSFilename ) & FA_READONLY )
  1150. {
  1151. AfxMessageBox ( "Database file is readonly!\n\nNo updates will be allowed.\n\nCheckout the database file and reload.");
  1152. db_readonly = TRUE;
  1153. win = GetDlgItem ( IDC_UPDATE );
  1154. win->EnableWindow ( FALSE);
  1155. win = GetDlgItem ( IDC_SAVE );
  1156. win->EnableWindow ( FALSE);
  1157. win = GetDlgItem ( IDC_IMPORT );
  1158. win->EnableWindow ( FALSE);
  1159. Log ( "READONLY", SAME_LINE );
  1160. }
  1161. else
  1162. {
  1163. Log ( "OK", SAME_LINE );
  1164. }
  1165. }
  1166. }
  1167. else
  1168. {
  1169. Log ( "FILE NOT FOUND", SAME_LINE );
  1170. }
  1171. if ( str_loaded && !db_error && !num_errors )
  1172. {
  1173. if ( UpdateDB ( BabylonstrDB, MainDB, FALSE ) )
  1174. {
  1175. BabylonstrDB->Changed ();
  1176. if ( db_loaded )
  1177. {
  1178. if ( db_readonly )
  1179. {
  1180. sprintf ( buffer, "\"%s\" has changed!\n\nHowever, as the database is READ ONLY you cannot update the changes.", BabylonstrFilename);
  1181. }
  1182. else
  1183. {
  1184. sprintf ( buffer, "\"%s\" has changed!\n\nRecomended that you update the database with these new changes.\n\nDo you wish to update now?", BabylonstrFilename);
  1185. }
  1186. }
  1187. else
  1188. {
  1189. sprintf ( buffer, "New Database!\n\nRecomended that you update the new database.\n\nDo you wish to update now?", BabylonstrFilename);
  1190. }
  1191. if ( db_readonly )
  1192. {
  1193. do_update = FALSE;
  1194. AfxMessageBox ( buffer );
  1195. }
  1196. else
  1197. {
  1198. do_update = (AfxMessageBox ( buffer, MB_YESNO ) == IDYES);
  1199. }
  1200. }
  1201. }
  1202. ProgressComplete ();
  1203. Ready ();
  1204. if ( do_update )
  1205. {
  1206. OnUpdate ();
  1207. }
  1208. }
  1209. void CBabylonDlg::InitProgress(int range)
  1210. {
  1211. if ( (progress_range = range) <= 0 )
  1212. {
  1213. progress_range = 1;
  1214. }
  1215. progress->SetRange ( 0, INCREMENTS );
  1216. progress_pos = -1;
  1217. progress->SetPos ( 0 );
  1218. }
  1219. void CBabylonDlg::SetProgress(int pos)
  1220. {
  1221. char string[20];
  1222. int new_pos = (pos * 100 ) / progress_range;
  1223. if ( new_pos > 100 )
  1224. {
  1225. new_pos = 100;
  1226. }
  1227. else if ( new_pos < 0 )
  1228. {
  1229. new_pos = 0;
  1230. }
  1231. if ( new_pos == progress_pos )
  1232. {
  1233. return;
  1234. }
  1235. progress->SetPos ( new_pos );
  1236. progress_pos = new_pos;
  1237. sprintf ( string, "%d%% ", progress_pos );
  1238. percent->SetWindowText ( string );
  1239. }
  1240. void CBabylonDlg::ProgressComplete()
  1241. {
  1242. progress->SetPos ( 100 );
  1243. percent->SetWindowText ( "100% ");
  1244. }
  1245. void CBabylonDlg::OnUpdate()
  1246. {
  1247. // TODO: Add your control notification handler code here
  1248. UpdateDB ( BabylonstrDB, MainDB );
  1249. }
  1250. #define MACRO_UPDATE(field,count) { if ( wcsicmp ( source->##field () , destination->##field ())) \
  1251. { \
  1252. if ( update ) \
  1253. { \
  1254. destination->Set##field ( source->##field () ); \
  1255. } \
  1256. label_modified = TRUE; \
  1257. info.changes++; \
  1258. (count)++; \
  1259. } \
  1260. }
  1261. int CBabylonDlg::UpdateLabel( BabylonLabel *source, BabylonLabel *destination, UPDATEINFO &info, int update, int skip )
  1262. {
  1263. BabylonText *stext, *dtext;
  1264. ListSearch sh;
  1265. TransDB *destDB, *srcDB;
  1266. int label_modified = FALSE;
  1267. destination->ClearMatched ();
  1268. source->ClearMatched ();
  1269. destDB = destination->DB();
  1270. srcDB = source->DB ();
  1271. // first go through and match up as many strings as possible
  1272. stext = source->FirstText ( sh );
  1273. while ( stext )
  1274. {
  1275. dtext = destDB->FindText ( stext->Get ());
  1276. // remember FindText() spans labels so keep looking till we find
  1277. // one that belongs to the label we are checking
  1278. while ( dtext && (dtext->Label () != destination) )
  1279. {
  1280. dtext = destDB->FindNextText ();
  1281. }
  1282. if ( dtext && dtext->Matched ())
  1283. {
  1284. AfxMessageBox ( "Fatal error: substring already matched" );
  1285. return FALSE;
  1286. }
  1287. if ( dtext )
  1288. {
  1289. // we have a matching string so mark it
  1290. dtext->Match ( stext );
  1291. stext->Match ( dtext );
  1292. }
  1293. stext = source->NextText ( sh );
  1294. }
  1295. // ask the user to resolve remaing unmatched strings
  1296. {
  1297. stext = source->FirstText ( sh );
  1298. while ( stext )
  1299. {
  1300. if ( destination->AllMatched ())
  1301. {
  1302. // no point trying to match anymore
  1303. break;
  1304. }
  1305. if ( !stext->Matched () )
  1306. {
  1307. int result;
  1308. BabylonText *match = NULL;
  1309. if ( update && !skip )
  1310. {
  1311. if ( destination->DB()->MultiTextAllowed())
  1312. {
  1313. result = MatchText ( stext, destination, &match );
  1314. }
  1315. else
  1316. {
  1317. ListSearch tsh;
  1318. BabylonText *oldtext = destination->FirstText ( tsh );
  1319. if ( !oldtext )
  1320. {
  1321. break;
  1322. }
  1323. result = RetranslateText ( stext, oldtext );
  1324. match = oldtext;
  1325. }
  1326. }
  1327. else
  1328. {
  1329. result = IDSKIP;
  1330. }
  1331. if ( result == IDCANCEL || result == IDSKIP)
  1332. {
  1333. return result;
  1334. }
  1335. if ( match )
  1336. {
  1337. stext->Match ( match );
  1338. match->Match ( stext );
  1339. }
  1340. stext->Processed ();
  1341. }
  1342. stext = source->NextText ( sh );
  1343. }
  1344. }
  1345. // go through all matched strings and update them accordingly
  1346. dtext = destination->FirstText ( sh );
  1347. while ( dtext )
  1348. {
  1349. if ( (stext = (BabylonText *) dtext->Matched ()) )
  1350. {
  1351. // stext is the newer version;
  1352. if ( wcscmp ( dtext->Get (), stext->Get ()))
  1353. {
  1354. if ( update )
  1355. {
  1356. dtext->Set ( stext->Get ());
  1357. }
  1358. info.modified_strings++;
  1359. label_modified = TRUE;
  1360. info.changes ++;
  1361. }
  1362. if ( wcsicmp ( dtext->Wave (), stext->Wave ()))
  1363. {
  1364. if ( update )
  1365. {
  1366. dtext->SetWave ( stext->Wave ());
  1367. }
  1368. info.updated_waves++;
  1369. label_modified = TRUE;
  1370. info.changes ++;
  1371. }
  1372. if ( dtext->Retranslate ())
  1373. {
  1374. if ( update )
  1375. {
  1376. dtext->IncRevision ();
  1377. }
  1378. label_modified = TRUE;
  1379. }
  1380. dtext->SetRetranslate ( FALSE );
  1381. }
  1382. dtext = destination->NextText ( sh );
  1383. }
  1384. // any remaining umatched text in the source are new strings
  1385. // any remaining umatched text in the destination are now obsolete
  1386. // delete old strings from destination
  1387. dtext = destination->FirstText ( sh );
  1388. while ( dtext )
  1389. {
  1390. BabylonText *next = destination->NextText ( sh );
  1391. if ( !dtext->Matched ())
  1392. {
  1393. if ( update )
  1394. {
  1395. dtext->Remove ();
  1396. destDB->AddObsolete ( dtext );
  1397. }
  1398. info.deleted_strings++;
  1399. label_modified = TRUE;
  1400. info.changes ++;
  1401. }
  1402. dtext = next;
  1403. }
  1404. // add new strings from source
  1405. stext = source->FirstText ( sh );
  1406. while ( stext )
  1407. {
  1408. if ( !stext->Matched ())
  1409. {
  1410. if ( update )
  1411. {
  1412. dtext = stext->Clone ();
  1413. destination->AddText ( dtext );
  1414. }
  1415. info.new_strings++;
  1416. label_modified = TRUE;
  1417. info.changes ++;
  1418. }
  1419. stext = source->NextText ( sh );
  1420. }
  1421. // finally update label info
  1422. MACRO_UPDATE(Comment, info.updated_comments);
  1423. MACRO_UPDATE(Context, info.updated_contexts);
  1424. MACRO_UPDATE(Speaker, info.updated_speakers);
  1425. MACRO_UPDATE(Listener, info.updated_listeners);
  1426. if ( destination->MaxLen () != source->MaxLen ())
  1427. {
  1428. if ( update )
  1429. {
  1430. destination->SetMaxLen ( source->MaxLen ());
  1431. }
  1432. label_modified = TRUE;
  1433. info.updated_maxlen++;
  1434. info.changes ++;
  1435. }
  1436. if ( label_modified )
  1437. {
  1438. if ( update )
  1439. {
  1440. source->ClearChanges ();
  1441. }
  1442. else
  1443. {
  1444. source->Changed ();
  1445. }
  1446. info.modified_labels ++;
  1447. }
  1448. return IDOK;
  1449. }
  1450. int CBabylonDlg::UpdateDB(TransDB *source, TransDB *destination, int update )
  1451. {
  1452. BabylonLabel *slabel;
  1453. BabylonLabel *dlabel;
  1454. ListSearch sh;
  1455. int count = 0;
  1456. int result = IDOK;
  1457. UPDATEINFO info;
  1458. int changes = FALSE;
  1459. int diffs = 0;
  1460. int skip_all = FALSE;
  1461. memset ( &info, 0, sizeof ( info ));
  1462. if ( update )
  1463. {
  1464. sprintf ( buffer, "Updating \"%s\" from \"%s\"...", destination->Name(), source->Name());
  1465. Log("");
  1466. Status ( buffer );
  1467. }
  1468. else
  1469. {
  1470. Status ("Checking for changes...", FALSE );
  1471. }
  1472. source->ClearProcessed ();
  1473. destination->ClearProcessed ();
  1474. if ( update )
  1475. {
  1476. InitProgress ( source->NumLabels() );
  1477. }
  1478. slabel = source->FirstLabel ( sh );
  1479. while ( slabel )
  1480. {
  1481. if ( (dlabel = destination->FindLabel ( slabel->Name ())))
  1482. {
  1483. dlabel->Processed ();
  1484. result = UpdateLabel ( slabel, dlabel, info, update, skip_all );
  1485. if ( result == IDCANCEL )
  1486. {
  1487. skip_all = TRUE;
  1488. }
  1489. if ( result == IDOK )
  1490. {
  1491. if ( update )
  1492. {
  1493. slabel->ClearChanges ();
  1494. }
  1495. }
  1496. else
  1497. {
  1498. info.skipped_labels ++;
  1499. info.changes ++;
  1500. if ( !update )
  1501. {
  1502. slabel->Changed();
  1503. }
  1504. }
  1505. }
  1506. else
  1507. {
  1508. BabylonLabel *clone;
  1509. if ( update )
  1510. {
  1511. clone = slabel->Clone ();
  1512. destination->AddLabel ( clone );
  1513. clone->Processed ();
  1514. slabel->ClearChanges ();
  1515. }
  1516. else
  1517. {
  1518. slabel->Changed ();
  1519. }
  1520. info.new_strings += slabel->NumStrings ();
  1521. info.changes += slabel->NumStrings ();
  1522. info.new_labels++;
  1523. info.changes++;
  1524. }
  1525. count++;
  1526. if ( update )
  1527. {
  1528. SetProgress ( count );
  1529. }
  1530. slabel->Processed ();
  1531. slabel = source->NextLabel ( sh );
  1532. }
  1533. // go through all unprocessed labels in the destination database and remove them.
  1534. dlabel = destination->FirstLabel ( sh );
  1535. while ( dlabel )
  1536. {
  1537. BabylonLabel *next_label = destination->NextLabel ( sh );
  1538. if ( !dlabel->IsProcessed ())
  1539. {
  1540. // this label was not matched so is obsolete
  1541. ListSearch sh_text;
  1542. BabylonText *dtext = dlabel->FirstText ( sh_text);
  1543. while ( dtext )
  1544. {
  1545. BabylonText *next = dlabel->NextText ( sh_text );
  1546. if ( update )
  1547. {
  1548. dtext->Remove ();
  1549. destination->AddObsolete ( dtext );
  1550. }
  1551. info.deleted_strings++;
  1552. info.changes ++;
  1553. dtext = next;
  1554. }
  1555. if ( update )
  1556. {
  1557. dlabel->Remove ();
  1558. delete dlabel;
  1559. }
  1560. info.deleted_labels++;
  1561. }
  1562. dlabel = next_label;
  1563. }
  1564. if ( update )
  1565. {
  1566. if ( info.new_labels )
  1567. {
  1568. sprintf ( buffer, "Added %d new label%c", info.new_labels, info.new_labels==1?' ':'s' );
  1569. Log ( buffer );
  1570. changes = TRUE;
  1571. }
  1572. if ( info.deleted_labels )
  1573. {
  1574. sprintf ( buffer, "Deleted %d label%c", info.deleted_labels, info.deleted_labels==1?' ':'s' );
  1575. Log ( buffer );
  1576. changes = TRUE;
  1577. }
  1578. if ( info.modified_labels )
  1579. {
  1580. sprintf ( buffer, "Modified %d label%c", info.modified_labels, info.modified_labels==1?' ':'s' );
  1581. Log ( buffer );
  1582. changes = TRUE;
  1583. }
  1584. if ( info.new_strings )
  1585. {
  1586. sprintf ( buffer, "Added %d new string%c", info.new_strings, info.new_strings==1?' ':'s' );
  1587. Log ( buffer );
  1588. changes = TRUE;
  1589. }
  1590. if ( info.deleted_strings )
  1591. {
  1592. sprintf ( buffer, "Deleted %d string%c", info.deleted_strings, info.deleted_strings==1?' ':'s' );
  1593. Log ( buffer );
  1594. changes = TRUE;
  1595. }
  1596. if ( info.modified_strings )
  1597. {
  1598. sprintf ( buffer, "Modified %d string%c", info.modified_strings, info.modified_strings==1?' ':'s' );
  1599. Log ( buffer );
  1600. changes = TRUE;
  1601. }
  1602. if ( info.skipped_labels )
  1603. {
  1604. sprintf ( buffer, "Skipped %d label%c", info.skipped_labels, info.skipped_labels==1?' ':'s' );
  1605. Log ( buffer );
  1606. changes = TRUE;
  1607. }
  1608. if ( info.updated_comments )
  1609. {
  1610. sprintf ( buffer, "Updated %d comment%c", info.updated_comments, info.updated_comments==1?' ':'s' );
  1611. Log ( buffer );
  1612. changes = TRUE;
  1613. }
  1614. if ( info.updated_contexts )
  1615. {
  1616. sprintf ( buffer, "Updated %d context%c", info.updated_contexts, info.updated_contexts==1?' ':'s' );
  1617. Log ( buffer );
  1618. changes = TRUE;
  1619. }
  1620. if ( info.updated_speakers )
  1621. {
  1622. sprintf ( buffer, "Updated %d speaker%c", info.updated_speakers, info.updated_speakers==1?' ':'s' );
  1623. Log ( buffer );
  1624. changes = TRUE;
  1625. }
  1626. if ( info.updated_listeners )
  1627. {
  1628. sprintf ( buffer, "Updated %d listener%c", info.updated_listeners, info.updated_listeners==1?' ':'s' );
  1629. Log ( buffer );
  1630. changes = TRUE;
  1631. }
  1632. if ( info.updated_maxlen )
  1633. {
  1634. sprintf ( buffer, "Updated %d max length%c", info.updated_maxlen, info.updated_maxlen==1?' ':'s' );
  1635. Log ( buffer );
  1636. changes = TRUE;
  1637. }
  1638. if ( info.updated_waves )
  1639. {
  1640. sprintf ( buffer, "Updated %d speech file%c", info.updated_waves, info.updated_waves==1?' ':'s' );
  1641. Log ( buffer );
  1642. changes = TRUE;
  1643. }
  1644. if ( !changes )
  1645. {
  1646. if ( !slabel && !info.skipped_labels)
  1647. {
  1648. Log ( "No differences found" );
  1649. }
  1650. else
  1651. {
  1652. Log ( "No changes made" );
  1653. }
  1654. }
  1655. if ( result == IDCANCEL )
  1656. {
  1657. Log ("Update aborted by user!" );
  1658. InitProgress ( 100 );
  1659. }
  1660. else
  1661. {
  1662. if ( !info.skipped_labels )
  1663. {
  1664. source->ClearChanges ();
  1665. }
  1666. }
  1667. } // update
  1668. Ready ();
  1669. return info.changes;
  1670. }
  1671. void CBabylonDlg::OnSave()
  1672. {
  1673. if ( CanOperate ())
  1674. {
  1675. SaveMainDB ( );
  1676. }
  1677. }
  1678. int CBabylonDlg::SaveMainDB( )
  1679. {
  1680. TransDB *db = MainDB;
  1681. const char *filename = MainXLSFilename;
  1682. int attribs;
  1683. if ( !db )
  1684. {
  1685. return TRUE;
  1686. }
  1687. if ( !db->IsChanged ())
  1688. {
  1689. return TRUE;
  1690. }
  1691. attribs = FileAttribs ( filename );
  1692. if ( attribs & FA_READONLY )
  1693. {
  1694. char buffer[100];
  1695. sprintf ( buffer, "Cannot save changes!\n\nFile \"%s\" is read only", filename );
  1696. AfxMessageBox ( buffer );
  1697. sprintf ( buffer, "Cannot save to \"%s\". File is read only", filename );
  1698. Log ( buffer );
  1699. Status ("Save failed", FALSE );
  1700. return FALSE;
  1701. }
  1702. Log("");
  1703. Status ( "Saving main database..." );
  1704. if ( attribs != FA_NOFILE )
  1705. {
  1706. MakeBackupFile ( filename );
  1707. }
  1708. if ( !WriteMainDB ( db, filename, this ) )
  1709. {
  1710. RestoreBackupFile ( filename );
  1711. Log ("FAILED", SAME_LINE );
  1712. Status ("Save failed", FALSE );
  1713. return FALSE;
  1714. }
  1715. else
  1716. {
  1717. Log ("OK", SAME_LINE );
  1718. }
  1719. Ready();
  1720. return TRUE;
  1721. }
  1722. void CBabylonDlg::OnWarnings()
  1723. {
  1724. // TODO: Add your control notification handler code here
  1725. if ( BabylonstrDB )
  1726. {
  1727. BabylonstrDB->Warnings ( this );
  1728. }
  1729. }
  1730. void CBabylonDlg::OnErrors()
  1731. {
  1732. // TODO: Add your control notification handler code here
  1733. if ( BabylonstrDB )
  1734. {
  1735. BabylonstrDB->Errors ( this );
  1736. }
  1737. }
  1738. int CBabylonDlg::MatchText ( BabylonText *text, BabylonLabel *label, BabylonText **match )
  1739. {
  1740. CMatchDlg dlg;
  1741. int result;
  1742. *match = NULL;
  1743. sprintf ( buffer, "Text: %s\n\nLabel:%s\n", text->GetSB (), label->NameSB () );
  1744. // TODO: Add your control notification handler code here
  1745. MatchOriginalText = text;
  1746. MatchLabel = label;
  1747. result = dlg.DoModal ();
  1748. if ( result != IDCANCEL )
  1749. {
  1750. *match = MatchingBabylonText;
  1751. }
  1752. return result;
  1753. }
  1754. int CBabylonDlg::RetranslateText ( BabylonText *newtext, BabylonText *oldtext )
  1755. {
  1756. RetranslateDlg dlg;
  1757. int result;
  1758. // TODO: Add your control notification handler code here
  1759. dlg.newtext = newtext;
  1760. dlg.oldtext = oldtext;
  1761. result = dlg.DoModal ( );
  1762. return result;
  1763. }
  1764. void CBabylonDlg::OnChanges()
  1765. {
  1766. // TODO: Add your control notification handler code here
  1767. VIEWDBSII dlg;
  1768. ViewChanges = TRUE;
  1769. dlg.DoModal ();
  1770. }
  1771. void CBabylonDlg::OnImport()
  1772. {
  1773. if ( CanOperate ())
  1774. {
  1775. CFileDialog fd ( TRUE , NULL, "*.xls", OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR );
  1776. if ( fd.DoModal () == IDOK )
  1777. {
  1778. if (ImportTranslations ( MainDB, (LPCSTR ) fd.GetPathName (), this ) == -1 )
  1779. {
  1780. // ProcessWaves ( BabylonstrDB, fd.GetPathName (), this );
  1781. }
  1782. }
  1783. }
  1784. }
  1785. void CBabylonDlg::OnGenerate()
  1786. {
  1787. if ( CanOperate ())
  1788. {
  1789. CGenerateDlg dlg;
  1790. if ( dlg.DoModal () == IDOK )
  1791. {
  1792. GenerateGameFiles ( MainDB, dlg.FilePrefix(), dlg.Options(), dlg.Langauges(), this );
  1793. }
  1794. }
  1795. }
  1796. int CBabylonDlg::ValidateStrFile( const char *filename)
  1797. {
  1798. STARTUPINFO StartupInfo = { 0 };
  1799. PROCESS_INFORMATION ProcessInfo;
  1800. char *results = "strcheck.rst";
  1801. int errors = 0;
  1802. FILE *file = NULL;
  1803. StartupInfo.cb = sizeof(STARTUPINFO);
  1804. StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
  1805. StartupInfo.wShowWindow = SW_SHOWMINNOACTIVE;
  1806. Log ("");
  1807. sprintf ( buffer, "Verifying \"%s\"...", filename );
  1808. Status ( buffer );
  1809. if ( FileExists ( results ))
  1810. {
  1811. DeleteFile ( results );
  1812. }
  1813. sprintf ( buffer, "strcheck %s %s", filename, results );
  1814. if (!CreateProcess(
  1815. NULL,
  1816. buffer,
  1817. NULL,
  1818. NULL,
  1819. FALSE,
  1820. 0,
  1821. NULL,
  1822. NULL,
  1823. &StartupInfo,
  1824. &ProcessInfo))
  1825. {
  1826. goto error;
  1827. }
  1828. WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
  1829. //this->SetForegroundWindow ();
  1830. //this->RedrawWindow ();
  1831. if ( !(file = fopen ( results, "rt" )))
  1832. {
  1833. goto error;
  1834. }
  1835. while ( fgets ( buffer, sizeof(buffer), file ) )
  1836. {
  1837. strlwr ( buffer );
  1838. if ( strstr ( buffer, "error") || strstr ( buffer, "warning" ))
  1839. {
  1840. errors++;
  1841. }
  1842. }
  1843. if ( errors )
  1844. {
  1845. sprintf ( buffer, "%d ERROR%s", errors, errors == 1 ? "" : "S" );
  1846. Log (buffer, SAME_LINE );
  1847. fseek ( file, 0, SEEK_SET );
  1848. while ( fgets ( buffer, sizeof(buffer), file ) )
  1849. {
  1850. sprintf ( buffer2, " strcheck> %s", buffer );
  1851. strlwr ( buffer );
  1852. if ( strstr ( buffer2, "error") || strstr ( buffer, "warning" ) )
  1853. {
  1854. int len = strlen ( buffer2 );
  1855. if ( buffer2[len-1] == '\n' )
  1856. {
  1857. buffer2[len-1] = 0;
  1858. }
  1859. Log ( buffer2 );
  1860. }
  1861. }
  1862. }
  1863. else
  1864. {
  1865. Log ("OK", SAME_LINE );
  1866. }
  1867. done:
  1868. if ( FileExists ( results ))
  1869. {
  1870. DeleteFile ( results );
  1871. }
  1872. if (file )
  1873. {
  1874. fclose (file );
  1875. }
  1876. return errors;
  1877. error:
  1878. Log ( "UNABLE TO VERIFY", SAME_LINE );
  1879. errors = -1;
  1880. goto done;
  1881. }
  1882. void CBabylonDlg::OnVerifyDialog()
  1883. {
  1884. if ( MainDB && CanOperate () )
  1885. {
  1886. VerifyDialog ( MainDB, CurrentLanguage );
  1887. }
  1888. }
  1889. void CBabylonDlg::VerifyDialog( TransDB *db, LangID langid )
  1890. {
  1891. BabylonLabel *label;
  1892. ListSearch sh_label;
  1893. int count = 0;
  1894. DLGREPORT _info;
  1895. DLGREPORT *info = &_info;
  1896. Log ("");
  1897. sprintf ( buffer, "Verifying %s dialog...", GetLangName ( langid ) );
  1898. Status ( buffer );
  1899. InitProgress ( db->NumLabels () );
  1900. cb_count = 0;
  1901. mainDlg = this;
  1902. db->VerifyDialog ( langid, cb_progress );
  1903. db->ReportDialog ( info, langid);
  1904. if ( info->unresolved )
  1905. {
  1906. Status ( "Verification", FALSE);
  1907. InitProgress ( info->unresolved );
  1908. label = db->FirstLabel ( sh_label );
  1909. while ( label )
  1910. {
  1911. BabylonText *text;
  1912. ListSearch sh_text;
  1913. text = label->FirstText ( sh_text );
  1914. while ( text )
  1915. {
  1916. if ( text->IsDialog ())
  1917. {
  1918. if ( text->DialogIsPresent ( DialogPath, langid ))
  1919. {
  1920. if ( !text->DialogIsValid ( DialogPath, langid, FALSE ) )
  1921. {
  1922. VerifyDlg dlg(text, langid, DialogPath);
  1923. int result;
  1924. result = dlg.DoModal ();
  1925. if ( result == IDCANCEL )
  1926. {
  1927. goto done;
  1928. }
  1929. if ( result == IDOK )
  1930. {
  1931. text->ValidateDialog ( DialogPath, langid );
  1932. }
  1933. count++;
  1934. SetProgress ( count );
  1935. }
  1936. }
  1937. }
  1938. text = label->NextText ( sh_text );
  1939. }
  1940. label = db->NextLabel ( sh_label );
  1941. }
  1942. }
  1943. done:
  1944. Ready ();
  1945. Status ( "Collecting stats...", FALSE );
  1946. count = db->ReportDialog ( info, langid );
  1947. if ( count < 100 )
  1948. {
  1949. InitProgress ( count );
  1950. cb_count = 0;
  1951. found_error = FALSE;
  1952. mainDlg = this;
  1953. db->ReportDialog ( info, langid, print_to_log_and_update_progress );
  1954. }
  1955. if ( info->numdialog )
  1956. {
  1957. if ( info->errors || info->missing || info->unresolved )
  1958. {
  1959. if ( !found_error )
  1960. {
  1961. Log ( "FAILED", SAME_LINE );
  1962. }
  1963. if ( info->errors )
  1964. {
  1965. sprintf ( buffer, "Errors : %d", info->errors );
  1966. Log ( buffer );
  1967. }
  1968. if ( info->missing )
  1969. {
  1970. sprintf ( buffer, "Missing dialog : %d", info->missing );
  1971. Log ( buffer );
  1972. }
  1973. if ( info->unresolved )
  1974. {
  1975. sprintf ( buffer, "Unverified dialog: %d", info->unresolved );
  1976. Log ( buffer );
  1977. }
  1978. if ( info->resolved )
  1979. {
  1980. sprintf ( buffer, "Verified dialog : %d", info->resolved );
  1981. Log ( buffer );
  1982. }
  1983. }
  1984. else
  1985. {
  1986. Log ( "OK", SAME_LINE );
  1987. if ( info->resolved )
  1988. {
  1989. sprintf ( buffer, "Verified dialog : %d", info->resolved );
  1990. Log ( buffer );
  1991. }
  1992. }
  1993. sprintf ( buffer, "Total dialog : %d", info->numdialog );
  1994. Log ( buffer );
  1995. }
  1996. else
  1997. {
  1998. Log ( "NO DIALOG FOUND", SAME_LINE );
  1999. }
  2000. Ready();
  2001. }
  2002. void CBabylonDlg::VerifyTranslations( TransDB *db, LangID langid )
  2003. {
  2004. int count = 0;
  2005. TRNREPORT _info;
  2006. TRNREPORT *info = &_info;
  2007. Log ("");
  2008. sprintf ( buffer, "Verifying %s text...", GetLangName ( langid ) );
  2009. Status ( buffer );
  2010. count = db->ReportTranslations ( info, langid );
  2011. if ( count < 100 )
  2012. {
  2013. InitProgress ( count);
  2014. cb_count = 0;
  2015. found_error = FALSE;
  2016. mainDlg = this;
  2017. db->ReportTranslations ( info, langid, print_to_log_and_update_progress );
  2018. }
  2019. if ( info->numstrings )
  2020. {
  2021. if ( info->too_big || info->missing || info->retranslate || info->bad_format )
  2022. {
  2023. if ( info->missing )
  2024. {
  2025. sprintf ( buffer, "Missing translations: %d", info->missing );
  2026. Log ( buffer );
  2027. }
  2028. if ( info->too_big )
  2029. {
  2030. sprintf ( buffer, "Oversized strings : %d", info->too_big );
  2031. Log ( buffer );
  2032. }
  2033. if ( info->retranslate )
  2034. {
  2035. sprintf ( buffer, "Retranslations : %d", info->retranslate);
  2036. Log ( buffer );
  2037. }
  2038. if ( info->bad_format )
  2039. {
  2040. sprintf ( buffer, "Badly formated translations: %d", info->bad_format);
  2041. Log ( buffer );
  2042. }
  2043. if ( langid == LANGID_US )
  2044. {
  2045. sprintf ( buffer, "Recommemd editing \"%s\" to fix problems and reload", BabylonstrFilename );
  2046. }
  2047. else
  2048. {
  2049. sprintf ( buffer, "Recommemd exporting translations for update and re-import" );
  2050. }
  2051. Log ( buffer );
  2052. }
  2053. else
  2054. {
  2055. Log ( "OK", SAME_LINE );
  2056. }
  2057. }
  2058. else
  2059. {
  2060. Log ( "NO TEXT", SAME_LINE );
  2061. }
  2062. Ready();
  2063. }
  2064. void CBabylonDlg::OnTranslations()
  2065. {
  2066. if ( MainDB && CanOperate () )
  2067. {
  2068. VerifyTranslations ( MainDB, CurrentLanguage );
  2069. }
  2070. }
  2071. void CBabylonDlg::OnSelchangeCombolang()
  2072. {
  2073. LANGINFO *info = NULL;
  2074. int index;
  2075. index = combo->GetCurSel ();
  2076. if ( index >= 0 && index < max_index )
  2077. {
  2078. info = (LANGINFO *) combo->GetItemDataPtr ( index );
  2079. }
  2080. if ( info )
  2081. {
  2082. CurrentLanguage = info->langid;
  2083. }
  2084. else
  2085. {
  2086. CurrentLanguage = LANGID_UNKNOWN;
  2087. }
  2088. }
  2089. void CBabylonDlg::OnReports()
  2090. {
  2091. // TODO: Add your control notification handler code here
  2092. if ( CanOperate ())
  2093. {
  2094. CReport dlg;
  2095. if ( dlg.DoModal () == IDOK )
  2096. {
  2097. GenerateReport ( MainDB, dlg.Filename(), dlg.Options(), dlg.Langauges(), this );
  2098. }
  2099. }
  2100. }
  2101. void CBabylonDlg::OnDblclkCombolang()
  2102. {
  2103. // TODO: Add your control notification handler code here
  2104. }
  2105. void CBabylonDlg::OnReset()
  2106. {
  2107. // TODO: Add your control notification handler code here
  2108. if ( CurrentLanguage != LANGID_UNKNOWN )
  2109. {
  2110. sprintf ( buffer, "Are you sure you want to invalidate all %s dialog?", GetLangName ( CurrentLanguage ));
  2111. if ( AfxMessageBox ( buffer, MB_YESNO) == IDYES )
  2112. {
  2113. MainDB->InvalidateDialog ( CurrentLanguage );
  2114. }
  2115. }
  2116. }
  2117. void CBabylonDlg::OnSent()
  2118. {
  2119. // TODO: Add your control notification handler code here
  2120. if ( CanOperate ())
  2121. {
  2122. CFileDialog fd ( TRUE , NULL, "*.xls", OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR );
  2123. if ( fd.DoModal () == IDOK )
  2124. {
  2125. UpdateSentTranslations ( MainDB, (LPCSTR ) fd.GetPathName (), this );
  2126. }
  2127. }
  2128. }
  2129. void CAboutDlg::OnButton1()
  2130. {
  2131. // TODO: Add your control notification handler code here
  2132. CreateTranslationTable ( );
  2133. }