OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [configtool/] [standalone/] [wxwin/] [appsettings.cpp] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####                                        
2
// -------------------------------------------                              
3
// This file is part of the eCos host tools.                                
4
// Copyright (C) 1998, 1999, 2000, 2003, 2005, 2006, 2008 Free Software Foundation, Inc.
5
//
6
// This program is free software; you can redistribute it and/or modify     
7
// it under the terms of the GNU General Public License as published by     
8
// the Free Software Foundation; either version 2 or (at your option) any   
9
// later version.                                                           
10
//
11
// This program is distributed in the hope that it will be useful, but      
12
// WITHOUT ANY WARRANTY; without even the implied warranty of               
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        
14
// General Public License for more details.                                 
15
//
16
// You should have received a copy of the GNU General Public License        
17
// along with this program; if not, write to the                            
18
// Free Software Foundation, Inc., 51 Franklin Street,                      
19
// Fifth Floor, Boston, MA  02110-1301, USA.                                
20
// -------------------------------------------                              
21
// ####ECOSHOSTGPLCOPYRIGHTEND####                                          
22
// appsettings.cpp :
23
//
24
//===========================================================================
25
//#####DESCRIPTIONBEGIN####
26
//
27
// Author(s):   julians, jld
28
// Contact(s):  julians
29
// Date:        2000/08/29
30
// Version:     $Id: appsettings.cpp,v 1.27 2001/12/14 17:34:03 julians Exp $
31
// Purpose:
32
// Description: Implementation file for the ecSettings
33
// Requires:
34
// Provides:
35
// See also:
36
// Known bugs:
37
// Usage:
38
//
39
//####DESCRIPTIONEND####
40
//
41
//===========================================================================
42
 
43
// ============================================================================
44
// declarations
45
// ============================================================================
46
 
47
// ----------------------------------------------------------------------------
48
// headers
49
// ----------------------------------------------------------------------------
50
#ifdef __GNUG__
51
#pragma implementation "appsettings.h"
52
#endif
53
 
54
// Includes other headers for precompiled compilation
55
#include "ecpch.h"
56
 
57
#ifdef __BORLANDC__
58
#pragma hdrstop
59
#endif
60
 
61
#include "wx/config.h"
62
#include "wx/file.h"
63
 
64
#include "appsettings.h"
65
#include "configtree.h"
66
#include "outputwin.h"
67
#include "shortdescrwin.h"
68
#include "mainwin.h"
69
 
70
// For SystemInfo
71
#ifdef __WXMSW__
72
#include <windows.h>
73
#include "wx/msw/winundef.h"
74
#ifdef GetTempPath
75
#undef GetTempPath
76
#endif
77
#endif
78
 
79
/*
80
* User-changeable and other settings to be saved between sessions
81
*/
82
 
83
IMPLEMENT_DYNAMIC_CLASS(ecSettings, wxObject)
84
 
85
ecSettings::ecSettings()
86
{
87
    m_showToolBar = TRUE;
88
    m_frameSize = wxRect(0, 0, 600, 500);
89
    m_appName = _("eCos Configuration Tool");
90
    m_showSplashScreen = TRUE;
91
    m_userName = wxEmptyString;
92
    m_serialNumber = 0;
93
    m_frameStatus = ecSHOW_STATUS_NORMAL;
94
 
95
    m_treeSashSize = wxSize(400, 1000);
96
    m_conflictsSashSize = wxSize(1000, 80);
97
    m_propertiesSashSize = wxSize(1000, 80);
98
    m_shortDescrSashSize = wxSize(1000, 80);
99
    m_memorySashSize = wxSize(1000, 50);
100
    m_outputSashSize = wxSize(1000, 50);
101
    m_configPaneWidth = 200;
102
 
103
    m_showConflictsWindow = FALSE;
104
    m_showPropertiesWindow = TRUE;
105
    m_showShortDescrWindow = TRUE;
106
    m_showMemoryWindow = FALSE;
107
    m_showOutputWindow = TRUE;
108
 
109
    m_showMacroNames = FALSE;
110
 
111
    m_bUseCustomViewer = FALSE;
112
    m_bUseExternalBrowser = FALSE;
113
    m_eUseCustomBrowser = ecInternal;
114
    m_bHex = FALSE;
115
    m_nRuleChecking = Immediate|Deferred|SuggestFixes ;
116
 
117
#ifdef __WXMSW__
118
    m_strViewer = wxT("notepad");
119
#endif
120
 
121
    // Find dialog settings
122
    m_findText = wxEmptyString;
123
    m_findMatchWholeWord = FALSE;
124
    m_findMatchCase = FALSE;
125
    m_findDirection = TRUE; // Down is TRUE, Up is FALSE
126
    m_findSearchWhat = _("Macro names"); // Macro names, item names etc.
127
    m_findDialogPos = wxPoint(-1, -1);
128
 
129
    m_editSaveFileOnly = FALSE;
130
 
131
    // Packages dialog settings
132
    m_omitHardwarePackages = TRUE;
133
    m_matchPackageNamesExactly = FALSE;
134
}
135
 
136
// Copy constructor
137
ecSettings::ecSettings(const ecSettings& settings)
138
{
139
    Copy(settings);
140
}
141
 
142
void ecSettings::Copy(const ecSettings& settings)
143
{
144
    m_showToolBar = settings.m_showToolBar;
145
    m_frameSize = settings.m_frameSize;
146
    m_showSplashScreen = settings.m_showSplashScreen;
147
    m_userName = settings.m_userName;
148
    m_serialNumber = settings.m_serialNumber;
149
 
150
    m_treeSashSize = settings.m_treeSashSize;
151
    m_conflictsSashSize = settings.m_conflictsSashSize;
152
    m_propertiesSashSize = settings.m_propertiesSashSize;
153
    m_memorySashSize = settings.m_memorySashSize;
154
    m_outputSashSize = settings.m_outputSashSize;
155
    m_configPaneWidth = settings.m_configPaneWidth;
156
    m_showMacroNames = settings.m_showMacroNames;
157
 
158
    m_bUseCustomViewer = settings.m_bUseCustomViewer;
159
    m_bUseExternalBrowser = settings.m_bUseExternalBrowser;
160
    m_eUseCustomBrowser = settings.m_eUseCustomBrowser;
161
    m_bHex = settings.m_bHex;
162
    m_nRuleChecking = settings.m_nRuleChecking;
163
 
164
    // Find dialog settings
165
    m_findText = settings.m_findText;
166
    m_findMatchWholeWord = settings.m_findMatchWholeWord;
167
    m_findMatchCase = settings.m_findMatchCase;
168
    m_findDirection = settings.m_findDirection; // Down is TRUE, Up is FALSE
169
    m_findSearchWhat = settings.m_findSearchWhat;
170
    m_findDialogPos = settings.m_findDialogPos;
171
 
172
    // Run tests settings
173
    m_runTestsSettings = settings.m_runTestsSettings;
174
 
175
    m_userToolsDir = settings.m_userToolsDir;
176
    m_buildToolsDir = settings.m_buildToolsDir;
177
 
178
    m_editSaveFileOnly = settings.m_editSaveFileOnly;
179
 
180
    // Packages dialog settings
181
    m_omitHardwarePackages = settings.m_omitHardwarePackages;
182
    m_matchPackageNamesExactly = settings.m_matchPackageNamesExactly;
183
}
184
 
185
ecSettings::~ecSettings()
186
{
187
}
188
 
189
// Do some initialisation within ecApp::OnInit
190
bool ecSettings::Init()
191
{
192
    return TRUE;
193
}
194
 
195
// Get a name suitable for the configuration file on all platforms:
196
// e.g. eCos Configuration Tool on Windows, .eCosConfigTool on Unix
197
wxString ecSettings::GetConfigAppName() const
198
{
199
#ifdef __WXGTK__
200
    return wxString(wxT("eCosConfigTool"));
201
#else
202
    return GetAppName();
203
#endif
204
}
205
 
206
 
207
// Create new filename
208
wxString ecSettings::GenerateFilename(const wxString& rootName)
209
{
210
    wxString path;
211
    if (!m_lastFilename.IsEmpty())
212
        path = wxPathOnly(m_lastFilename);
213
    else
214
        //        path = wxGetApp().GetAppDir();
215
        path = wxGetCwd();
216
 
217
    wxString filename(path);
218
    if (filename.Last() != wxFILE_SEP_PATH )
219
        filename += wxFILE_SEP_PATH;
220
    filename += rootName;
221
 
222
    wxString fullFilename = filename + wxT(".ecc");
223
    int i = 0;
224
    wxString postfixStr;
225
    while (wxFileExists(fullFilename))
226
    {
227
        i ++;
228
        postfixStr.Printf("%d", i);
229
        fullFilename = filename + postfixStr + wxT(".ecc");
230
    }
231
 
232
    m_lastFilename = fullFilename;
233
    return fullFilename;
234
}
235
 
236
// Load config info
237
bool ecSettings::LoadConfig()
238
{
239
    wxConfig config(wxGetApp().GetSettings().GetConfigAppName());
240
 
241
    config.Read(_("/Window Status/FrameStatus"), & m_frameStatus);
242
    config.Read(_("/Window Status/ShowToolBar"), (bool*) & m_showToolBar);
243
    config.Read(_("/Window Status/ShowSplashScreen"), (bool*) & m_showSplashScreen);
244
    config.Read(_("/Window Status/ShowConflictsWindow"), (bool*) & m_showConflictsWindow);
245
    config.Read(_("/Window Status/ShowPropertiesWindow"), (bool*) & m_showPropertiesWindow);
246
    config.Read(_("/Window Status/ShowShortDescrWindow"), (bool*) & m_showShortDescrWindow);
247
    config.Read(_("/Window Status/ShowMemoryWindow"), (bool*) & m_showMemoryWindow);
248
    config.Read(_("/Window Status/ShowOutputWindow"), (bool*) & m_showOutputWindow);
249
 
250
    config.Read(_("/Files/LastFile"), & m_lastFilename);
251
 
252
    config.Read(_("/Window Size/WindowX"), & m_frameSize.x);
253
    config.Read(_("/Window Size/WindowY"), & m_frameSize.y);
254
    config.Read(_("/Window Size/WindowWidth"), & m_frameSize.width);
255
    config.Read(_("/Window Size/WindowHeight"), & m_frameSize.height);
256
 
257
    config.Read(_("/Window Size/TreeSashWidth"), & m_treeSashSize.x);
258
    config.Read(_("/Window Size/TreeSashHeight"), & m_treeSashSize.y);
259
    config.Read(_("/Window Size/ConfigPaneWidth"), & m_configPaneWidth);
260
    config.Read(_("/Window Size/ConflictsWidth"), & m_conflictsSashSize.x);
261
    config.Read(_("/Window Size/ConflictsHeight"), & m_conflictsSashSize.y);
262
    config.Read(_("/Window Size/PropertiesWidth"), & m_propertiesSashSize.x);
263
    config.Read(_("/Window Size/PropertiesHeight"), & m_propertiesSashSize.y);
264
    config.Read(_("/Window Size/ShortDescrWidth"), & m_shortDescrSashSize.x);
265
    config.Read(_("/Window Size/ShortDescrHeight"), & m_shortDescrSashSize.y);
266
    config.Read(_("/Window Size/OutputWidth"), & m_outputSashSize.x);
267
    config.Read(_("/Window Size/OutputHeight"), & m_outputSashSize.y);
268
    config.Read(_("/Window Size/MemoryWidth"), & m_memorySashSize.x);
269
    config.Read(_("/Window Size/MemoryHeight"), & m_memorySashSize.y);
270
 
271
    config.Read(_("/Options/ShowMacroNames"), (bool*) & m_showMacroNames);
272
    config.Read(_("/Options/UseCustomViewer"), (bool*) & m_bUseCustomViewer);
273
    config.Read(_("/Options/UseExternalBrowser"), (bool*) & m_bUseExternalBrowser);
274
 
275
    int tmp = (int) m_eUseCustomBrowser;
276
    config.Read(_("/Options/UseCustomBrowser"), & tmp);
277
    m_eUseCustomBrowser = (ecBrowserType) tmp;
278
 
279
    config.Read(_("/Options/Browser"), & m_strBrowser);
280
    config.Read(_("/Options/Viewer"), & m_strViewer);
281
    config.Read(_("/Options/HexDisplay"), (bool*) & m_bHex);
282
    config.Read(_("/Options/UseDefaultFonts"), (bool*) & m_windowSettings.m_useDefaults);
283
    config.Read(_("/Rule/Checking"), & m_nRuleChecking);
284
 
285
    // Find dialog settings
286
    config.Read(_("/Find/Text"), & m_findText);
287
    config.Read(_("/Find/MatchWholeWord"), (bool*) & m_findMatchWholeWord);
288
    config.Read(_("/Find/MatchCase"), & m_findMatchCase);
289
    config.Read(_("/Find/Direction"), (bool*) & m_findDirection);
290
    config.Read(_("/Find/SearchWhat"), & m_findSearchWhat);
291
    config.Read(_("/Find/DialogX"), & m_findDialogPos.x);
292
    config.Read(_("/Find/DialogY"), & m_findDialogPos.y);
293
 
294
    // Package dialog settings
295
    config.Read(_("/Packages/OmitHardwarePackages"), & m_omitHardwarePackages);
296
    config.Read(_("/Packages/MatchPackageNamesExactly"), & m_matchPackageNamesExactly);
297
 
298
    // Run tests settings
299
    m_runTestsSettings.LoadConfig(config);
300
 
301
    // Fonts
302
    m_windowSettings.LoadConfig(config);
303
 
304
    if (!config.Read(_("/Paths/UserToolsDir"), & m_userToolsDir))
305
    {
306
        // Use the default provided by the installer
307
        config.Read(_("Default User Tools Path"), & m_userToolsDir);
308
    }
309
 
310
    // Only to be used if we fail to find the information installed
311
    // with the Configuration Tool.
312
    config.Read(_("/Paths/BuildToolsDir"), & m_buildToolsDir);
313
    if (m_buildToolsDir.IsEmpty()) // first invocation by this user
314
    {
315
        // we have no clues as to the location of the build tools so
316
        // test for ../../../gnutools relative to the configtool location
317
        wxFileName gnutools = wxFileName (wxGetApp().GetAppDir(), wxEmptyString);
318
        gnutools.Normalize(); // remove trailing "./" if present
319
                if (2 < gnutools.GetDirCount())
320
        {
321
            gnutools.RemoveDir (gnutools.GetDirCount()-1);
322
            gnutools.RemoveDir (gnutools.GetDirCount()-1);
323
            gnutools.RemoveDir (gnutools.GetDirCount()-1);
324
            gnutools.AppendDir (wxT("gnutools"));
325
            if (gnutools.DirExists()) // we've found the gnutools
326
                m_buildToolsDir = gnutools.GetFullPath();
327
        }
328
    }
329
 
330
    // look for *objcopy in and under the build tools directory
331
    if (! m_buildToolsDir.IsEmpty())
332
    {
333
        wxArrayString objcopyFiles;
334
        wxString objcopyFileSpec(wxT("objcopy"));
335
#ifdef __WXMSW__
336
        objcopyFileSpec += wxT(".exe");
337
#endif
338
        size_t objcopyCount = wxDir::GetAllFiles(m_buildToolsDir, &objcopyFiles, wxT("*") + objcopyFileSpec, wxDIR_FILES | wxDIR_DIRS);
339
        for (int count=0; count < objcopyCount; count++)
340
        {
341
            wxFileName file (objcopyFiles [count]);
342
            wxString new_prefix (file.GetFullName().Left (file.GetFullName().Find(objcopyFileSpec)));
343
            if ((! new_prefix.IsEmpty()) && ('-' == new_prefix.Last()))
344
                new_prefix = new_prefix.Left (new_prefix.Len() - 1); // strip off trailing hyphen
345
            m_arstrBinDirs.Set(new_prefix, file.GetPath(wxPATH_GET_VOLUME));
346
        }
347
    }
348
 
349
    if (!config.Read(_("/Build/Make Options"), & m_strMakeOptions))
350
    {
351
#ifdef __WXMSW__
352
        SYSTEM_INFO SystemInfo;
353
        GetSystemInfo(&SystemInfo);
354
        m_strMakeOptions.Printf(_T("-j%d"),SystemInfo.dwNumberOfProcessors);
355
#else
356
        long lProcessors;
357
        lProcessors = sysconf(_SC_NPROCESSORS_ONLN);
358
        m_strMakeOptions.Printf(_T("-j%ld"),lProcessors < 1 ? 1l : lProcessors);
359
#endif
360
    }
361
 
362
    // Set default build tools binary directories as specified by the installer
363
    ecFileName strDefaultBuildToolsPath;
364
 
365
#ifdef __WXMSW__
366
    {
367
        // This should look in HKEY_LOCAL_MACHINE
368
 
369
        wxConfig config2(wxT("eCos"), wxEmptyString, wxEmptyString, wxEmptyString, wxCONFIG_USE_GLOBAL_FILE|wxCONFIG_USE_LOCAL_FILE);
370
 
371
        wxString versionKey = GetInstallVersionKey();
372
        wxConfigPathChanger path(& config2, wxString(wxT("/")) + versionKey + wxT("/"));
373
 
374
        if (!versionKey.IsEmpty() && config2.Read(wxT("Default Build Tools Path"), & strDefaultBuildToolsPath))
375
        {
376
#ifdef __WXMSW__
377
            wxString gccExe(wxT("*-gcc.exe"));
378
#else
379
            wxString gccExe(wxT("*-gcc"));
380
#endif
381
 
382
            // Note that this is not a recursive search. Compilers for
383
            // different targets may be in the same directory. This finds all targets.
384
 
385
            // look for *-gcc[.exe] in the default build tools directory
386
            wxLogNull log;
387
            wxDir finder(strDefaultBuildToolsPath);
388
            wxString filename;
389
 
390
            if (finder.IsOpened())
391
            {
392
                bool bMore = finder.GetFirst(& filename, gccExe);
393
                while (bMore)
394
                {
395
                    wxString targetName = filename.Left(filename.Find(wxT("-gcc")));
396
                    m_arstrBinDirs.Set(targetName, strDefaultBuildToolsPath);
397
 
398
                    bMore = finder.GetNext(& filename);
399
                }
400
            }
401
        }
402
    }
403
#endif
404
 
405
#ifndef __WXMSW__
406
    // Look in the PATH for build tools, under Unix
407
    {
408
        wxString strPath;
409
        if (wxGetEnv(wxT("PATH"), & strPath))
410
        {
411
            wxString gccExe(wxT("*-gcc"));
412
 
413
            wxArrayString arstrPath;
414
            ecUtils::Chop(strPath, arstrPath, wxT(':'));
415
 
416
            for (int i = arstrPath.GetCount()-1;i >= 0; --i)
417
            { // Reverse order is important to treat path correctly
418
                if (wxT(".") != arstrPath[i] && !arstrPath[i].IsEmpty())
419
                {
420
                    wxLogNull log;
421
                    wxDir finder(arstrPath[i]);
422
                    wxString filename;
423
 
424
                    if (finder.IsOpened())
425
                    {
426
                        bool bMore = finder.GetFirst(& filename, gccExe);
427
                        while (bMore)
428
                        {
429
                            wxString targetName = filename.Left(filename.Find(wxT("-gcc")));
430
                            m_arstrBinDirs.Set(targetName, arstrPath[i]);
431
 
432
                            bMore = finder.GetNext(& filename);
433
                        }
434
                    }
435
                }
436
            }
437
        }
438
    }
439
#endif
440
 
441
    // Read build tools directories (current user)
442
 
443
    {
444
        wxConfigPathChanger path(& config, wxT("/Build Tools/"));
445
        //config.SetPath(wxT("/Build Tools"));
446
        wxString key(wxT(""));
447
        long index;
448
        bool bMore = config.GetFirstEntry(key, index);
449
        while (bMore)
450
        {
451
            wxString value;
452
            if (config.Read(key, & value))
453
            {
454
                m_arstrBinDirs.Set(key, value);
455
            }
456
            bMore = config.GetNextEntry(key, index);
457
        }
458
    }
459
 
460
    // Read toolchain paths (local machine again)
461
#ifdef __WXMSW__    
462
    wxArrayString arstrToolChainPaths;
463
 
464
    // Use eCos just as a test.
465
    //GetRepositoryRegistryClues(arstrToolChainPaths,_T("eCos"));
466
    GetRepositoryRegistryClues(arstrToolChainPaths,_T("GNUPro eCos"));
467
 
468
    size_t i;
469
    for (i = (size_t) 0; i < arstrToolChainPaths.GetCount(); i++)
470
    {
471
        ecFileName strDir(arstrToolChainPaths[i]);
472
        strDir += wxT("H-i686-cygwin32\\bin");
473
 
474
        if (strDir.IsDir())
475
        {
476
            // This is a potential toolchain location. Look for *-gcc.exe
477
            wxLogNull log;
478
            wxDir finder(strDefaultBuildToolsPath);
479
            wxString filename;
480
 
481
            if (finder.IsOpened())
482
            {
483
                bool bMore = finder.GetFirst(& filename, wxT("*-gcc.exe"));
484
                while (bMore)
485
                {
486
                    // TODO: if there is more than one path, we will have to
487
                    // check the existance of this target name in m_arstrBinDirs and
488
                    // append to the end, or something.
489
                    wxString targetName = filename.Left(filename.Find(wxT("-gcc")));
490
                    m_arstrBinDirs.Set(targetName, strDefaultBuildToolsPath);
491
 
492
                    bMore = finder.GetNext(& filename);
493
                }
494
            }
495
        }
496
    }
497
 
498
    // The official user tools are now Cygwin 00r1. If you can't find these,
499
    // try GNUPro unsupported.
500
    GetRepositoryRegistryClues(m_userToolPaths, wxT("GNUPro 00r1"));
501
    if (m_userToolPaths.GetCount() == 0)
502
    {
503
        GetRepositoryRegistryClues(m_userToolPaths, wxT("Cygwin 00r1"));
504
    }
505
 
506
    if (m_userToolPaths.GetCount() > 0)
507
    {
508
        for ( i = (size_t) 0 ; i < m_userToolPaths.GetCount(); i++)
509
        {
510
            ecFileName str(m_userToolPaths[i]);
511
            str += "H-i686-cygwin32\\bin";
512
            if(str.IsDir())
513
            {
514
                m_userToolPaths[i] = str;
515
            } else
516
            {
517
#if wxCHECK_VERSION(2, 6, 0)
518
                m_userToolPaths.RemoveAt(i);
519
#else
520
                m_userToolPaths.Remove(i);
521
#endif
522
                i--;
523
            }
524
        }
525
    }
526
    else
527
    {
528
        GetRepositoryRegistryClues(m_userToolPaths, wxT("GNUPro unsupported"));
529
 
530
        for ( i = (size_t) 0 ; i < m_userToolPaths.GetCount(); i++)
531
        {
532
            ecFileName str(m_userToolPaths[i]);
533
            str += "H-i686-cygwin32\\bin";
534
            if(str.IsDir())
535
            {
536
                m_userToolPaths[i] = str;
537
            } else
538
            {
539
#if wxCHECK_VERSION(2, 6, 0)
540
                m_userToolPaths.RemoveAt(i);
541
#else
542
                m_userToolPaths.Remove(i);
543
#endif
544
                i--;
545
            }
546
        }
547
    }
548
#endif
549
 
550
    // Include the path in the set of potential user paths
551
    {
552
        wxString strPath;
553
        if (wxGetEnv(wxT("PATH"), & strPath))
554
        {
555
            wxArrayString arstrPath;
556
            ecUtils::Chop(strPath, arstrPath, wxT(';'));
557
 
558
            for (int i = arstrPath.GetCount()-1;i >= 0; --i)
559
            { // Reverse order is important to treat path correctly
560
 
561
                const ecFileName &strFolder = arstrPath[i];
562
                if (wxT(".") != strFolder && !strFolder.IsEmpty())
563
                {
564
                    ecFileName strFile(strFolder);
565
                    strFile += wxT("ls.exe");
566
                    if ( strFile.Exists() )
567
                    {
568
                        if (!wxArrayStringIsMember(m_userToolPaths, strFolder))
569
                        {
570
                            m_userToolPaths.Add(strFolder);
571
                        }
572
 
573
                        if ( m_userToolsDir.IsEmpty() )
574
                        {
575
                            m_userToolsDir = strFolder;
576
                        }
577
                    }
578
                }
579
            }
580
        }
581
    }
582
 
583
    // Load current repository from eCos Configuration Tool/Paths/RepositoryDir
584
    {
585
        wxConfig eCosConfig(wxGetApp().GetSettings().GetConfigAppName(), wxEmptyString, wxEmptyString, wxEmptyString, wxCONFIG_USE_GLOBAL_FILE|wxCONFIG_USE_LOCAL_FILE);
586
        wxConfigPathChanger path(& config, wxT("/Repository/"));
587
 
588
        //if (!eCosConfig.Read(wxT("Folder"), & m_strRepository))
589
        if (!eCosConfig.Read(wxT("/Paths/RepositoryDir"), & m_strRepository))
590
        {
591
#ifdef __WXMSW__
592
            // If we can't find the current folder, look for clues in the registry.
593
            wxArrayString arstr;
594
            switch (GetRepositoryRegistryClues(arstr, wxT("eCos")))
595
            {
596
            case 0:
597
                break;
598
            case 1:
599
            default:
600
                m_strRepository = arstr[0];
601
                break;
602
            }
603
#elif defined(__WXGTK__)
604
            // If we can't find the current folder, look for the latest version
605
            // in /opt/ecos
606
            m_strRepository = FindLatestVersion();
607
#else
608
            // Unsupported platform
609
            m_strRepositor = wxEmptyString;
610
#endif
611
        }
612
 
613
        // If we have set ECOS_REPOSITORY, this overrides whatever we have
614
        // read or found.
615
        wxString envVarValue = wxGetenv(wxT("ECOS_REPOSITORY"));
616
        if (!envVarValue.IsEmpty())
617
        {
618
            // Note that ECOS_REPOSITORY has the packages (or ecc) folder in the name.
619
            // In order to be in the form that is compatible with configtool operation,
620
            // it needs to have that stripped off.
621
            envVarValue = ecUtils::PosixToNativePath(envVarValue); // accommodate posix-style ECOS_REPOSITORY value under Cygwin
622
            wxString packagesName = wxFileNameFromPath(envVarValue);
623
            if (packagesName == wxT("ecc") || packagesName == wxT("packages"))
624
                envVarValue = wxPathOnly(envVarValue);
625
 
626
            m_strRepository = envVarValue;
627
        }
628
    }
629
 
630
#ifdef __WXMSW__
631
    if (m_userToolsDir.IsEmpty())
632
        m_userToolsDir = GetCygwinInstallPath() + wxT("\\bin");
633
#else
634
    if (m_userToolsDir.IsEmpty())
635
        m_userToolsDir = wxT("/bin");
636
#endif
637
 
638
    return TRUE;
639
}
640
 
641
#ifdef __WXMSW__
642
wxString ecSettings::GetCygwinInstallPath()
643
{
644
    HKEY hKey = 0;
645
    DWORD type;
646
    BYTE value[256];
647
    DWORD sz = sizeof(value);
648
    wxString strCygwinInstallPath;
649
 
650
    // look for the "/" mount point in the system registry settings
651
    if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Cygnus Solutions\\Cygwin\\mounts v2\\/", 0, KEY_READ, &hKey)) {
652
        if (ERROR_SUCCESS == RegQueryValueEx(hKey, "native", NULL, & type, value, & sz)) {
653
            strCygwinInstallPath = (const char*) value;
654
        }
655
        RegCloseKey(hKey);
656
    }
657
 
658
    // if not yet found, look for the "/" mount point in the user's registry settings
659
    hKey = 0;
660
    sz = sizeof(value);
661
    if (strCygwinInstallPath.IsEmpty() && (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Cygnus Solutions\\Cygwin\\mounts v2\\/", 0, KEY_READ, &hKey))) {
662
        if (ERROR_SUCCESS == RegQueryValueEx(hKey, "native", NULL, & type, value, & sz)) {
663
            strCygwinInstallPath = (const char*) value;
664
        }
665
        RegCloseKey(hKey);
666
    }
667
 
668
    return strCygwinInstallPath;
669
}
670
#endif
671
 
672
// Save config info
673
bool ecSettings::SaveConfig()
674
{
675
    wxConfig config(wxGetApp().GetSettings().GetConfigAppName());
676
 
677
    config.Write(_("/Files/LastFile"), m_lastFilename);
678
 
679
    config.Write(_("/Window Status/FrameStatus"), (long) m_frameStatus);
680
    config.Write(_("/Window Status/ShowToolBar"), m_showToolBar);
681
    config.Write(_("/Window Status/ShowSplashScreen"), m_showSplashScreen);
682
    config.Write(_("/Window Status/ShowConflictsWindow"), m_showConflictsWindow);
683
    config.Write(_("/Window Status/ShowPropertiesWindow"), m_showPropertiesWindow);
684
    config.Write(_("/Window Status/ShowShortDescrWindow"), m_showShortDescrWindow);
685
    config.Write(_("/Window Status/ShowMemoryWindow"), m_showMemoryWindow);
686
    config.Write(_("/Window Status/ShowOutputWindow"), m_showOutputWindow);
687
 
688
    config.Write(_("/Window Size/WindowX"), (long) m_frameSize.x);
689
    config.Write(_("/Window Size/WindowY"), (long) m_frameSize.y);
690
    config.Write(_("/Window Size/WindowWidth"), (long) m_frameSize.width);
691
    config.Write(_("/Window Size/WindowHeight"), (long) m_frameSize.height);
692
    config.Write(_("/Window Size/TreeSashWidth"), (long) m_treeSashSize.x);
693
    config.Write(_("/Window Size/TreeSashHeight"), (long) m_treeSashSize.y);
694
    config.Write(_("/Window Size/ConfigPaneWidth"), (long) m_configPaneWidth);
695
    config.Write(_("/Window Size/ConflictsWidth"), (long) m_conflictsSashSize.x);
696
    config.Write(_("/Window Size/ConflictsHeight"), (long) m_conflictsSashSize.y);
697
    config.Write(_("/Window Size/PropertiesWidth"), (long) m_propertiesSashSize.x);
698
    config.Write(_("/Window Size/PropertiesHeight"), (long) m_propertiesSashSize.y);
699
    config.Write(_("/Window Size/ShortDescrWidth"), (long) m_shortDescrSashSize.x);
700
    config.Write(_("/Window Size/ShortDescrHeight"), (long) m_shortDescrSashSize.y);
701
    config.Write(_("/Window Size/OutputWidth"), (long) m_outputSashSize.x);
702
    config.Write(_("/Window Size/OutputHeight"), (long) m_outputSashSize.y);
703
    config.Write(_("/Window Size/MemoryWidth"), (long) m_memorySashSize.x);
704
    config.Write(_("/Window Size/MemoryHeight"), (long) m_memorySashSize.y);
705
 
706
    config.Write(_("/Options/ShowMacroNames"), m_showMacroNames);
707
    config.Write(_("/Options/UseCustomViewer"), m_bUseCustomViewer);
708
    config.Write(_("/Options/UseExternalBrowser"), m_bUseExternalBrowser);
709
    config.Write(_("/Options/UseCustomBrowser"), (long) m_eUseCustomBrowser);
710
    config.Write(_("/Options/Browser"), m_strBrowser);
711
    config.Write(_("/Options/Viewer"), m_strViewer);
712
    config.Write(_("/Options/HexDisplay"), m_bHex);
713
    config.Write(_("/Options/UseDefaultFonts"), m_windowSettings.m_useDefaults);
714
 
715
    config.Write(_("/Rule/Checking"), (long) m_nRuleChecking);
716
 
717
    config.Write(_("/Paths/UserToolsDir"), m_userToolsDir);
718
    config.Write(_("/Paths/BuildToolsDir"), m_buildToolsDir);
719
 
720
    config.Write(_("/Build/Make Options"), m_strMakeOptions);
721
 
722
    // Find dialog settings
723
    config.Write(_("/Find/Text"), m_findText);
724
    config.Write(_("/Find/MatchWholeWord"), m_findMatchWholeWord);
725
    config.Write(_("/Find/MatchCase"), m_findMatchCase);
726
    config.Write(_("/Find/Direction"), m_findDirection);
727
    config.Write(_("/Find/SearchWhat"), m_findSearchWhat);
728
    config.Write(_("/Find/DialogX"), (long) m_findDialogPos.x);
729
    config.Write(_("/Find/DialogY"), (long) m_findDialogPos.y);
730
 
731
    // Package dialog settings
732
    config.Write(_("/Packages/OmitHardwarePackages"), m_omitHardwarePackages);
733
    config.Write(_("/Packages/MatchPackageNamesExactly"), m_matchPackageNamesExactly);
734
 
735
    // Save current repository to eCos Configuration Tool/Paths/RepositoryDir
736
    // UNLESS it was overridden by ECOS_REPOSITORY
737
    {
738
        wxString envVarValue = wxGetenv(wxT("ECOS_REPOSITORY"));
739
        if (m_strRepository == envVarValue)
740
        {
741
            // Don't override the value in the local settings
742
        }
743
        else
744
            config.Write(wxT("/Paths/RepositoryDir"), m_strRepository);
745
    }
746
 
747
    // Run tests settings
748
    m_runTestsSettings.SaveConfig(config);
749
 
750
    // Fonts
751
    m_windowSettings.SaveConfig(config);
752
 
753
    return TRUE;
754
}
755
 
756
void ecSettings::ShowSettingsDialog(const wxString& page)
757
{
758
#if 0
759
    ecSettingsDialog* dialog = new ecSettingsDialog(wxGetApp().GetTopWindow());
760
    if (!page.IsEmpty())
761
        dialog->GetNotebook()->SetSelection(ecFindNotebookPage(dialog->GetNotebook(), page));
762
 
763
    int ret = dialog->ShowModal();
764
    dialog->Destroy();
765
#endif
766
}
767
 
768
#ifndef MAX_PATH
769
#define MAX_PATH 1024
770
#endif
771
 
772
// TODO for non-Windows platforms
773
const ecFileName& ecSettings::DefaultExternalBrowser()
774
{
775
#ifdef __WXMSW__
776
    static bool bFirstTime=TRUE;
777
    if(bFirstTime){
778
        const ecFileName strFile(ecFileName::EC_GetTempPath()+wxT("index.html"));
779
        wxFile f;
780
        if(f.Create(strFile, TRUE))
781
        {
782
            f.Close();
783
            bool rc=((int)  ::FindExecutable(strFile,wxT("."),m_strDefaultExternalBrowser.GetWriteBuf(MAX_PATH))>32);
784
            m_strDefaultExternalBrowser.UngetWriteBuf();
785
            if(!rc){
786
                m_strDefaultExternalBrowser=wxT("");
787
            }
788
            wxRemoveFile(strFile);
789
        }
790
        bFirstTime=FALSE;
791
    }
792
#endif
793
    return m_strDefaultExternalBrowser;
794
}
795
 
796
ecFileName ecSettings::m_strDefaultExternalBrowser;
797
 
798
// Go looking for potential candidates in SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths
799
int ecSettings::GetRepositoryRegistryClues(wxArrayString& arstr, const wxString& pszPrefix)
800
{
801
    arstr.Clear();
802
 
803
#ifdef __WXMSW__
804
    wxConfig config(wxT("Windows"), wxT("Microsoft"), wxEmptyString, wxEmptyString, wxCONFIG_USE_GLOBAL_FILE);
805
    config.SetPath(wxT("/CurrentVersion/App Paths"));
806
 
807
    wxString key(wxT(""));
808
    long index;
809
    bool bMore = config.GetFirstGroup(key, index);
810
    while (bMore)
811
    {
812
        if (key.Find(pszPrefix) == 0)
813
        {
814
            wxString value;
815
            //wxString key2(wxString(wxT("/")) + key + wxString(wxT("/Path")));
816
            wxString key2(key + wxString(wxT("/Path")));
817
            if (config.Read(key2, & value))
818
            {
819
                arstr.Add(value);
820
            }
821
        }
822
        bMore = config.GetNextGroup(key, index);
823
    }
824
    return arstr.GetCount();
825
#else
826
    return 0;
827
#endif
828
}
829
 
830
// Finds the path of the latest installed eCos
831
wxString ecSettings::FindLatestVersion()
832
{
833
#ifdef __WXGTK__
834
    wxString ecosRoot(wxT("/opt/ecos"));
835
    wxLogNull log;
836
    wxDir dir(ecosRoot);
837
 
838
    wxString latestDir;
839
    wxString latestVersion;
840
 
841
    if (dir.IsOpened())
842
    {
843
        wxString filename;
844
        bool cont = dir.GetFirst(& filename, wxT("ecos-*"), wxDIR_DIRS);
845
        while (cont)
846
        {
847
            wxString ver(filename.Mid(5));
848
            if (latestVersion.IsEmpty() || latestVersion.CompareTo(ver) < 0)
849
            {
850
                latestVersion = ver;
851
                latestDir = ecosRoot + wxT("/") + filename;
852
            }
853
 
854
            cont = dir.GetNext(& filename);
855
        }
856
    }
857
//    if (latestDir.IsEmpty())
858
//        latestDir = wxGetCwd();
859
    return latestDir;
860
#else
861
    wxMessageBox(wxT("FindLatestVersion() is only implemented for Unix."));
862
    return wxEmptyString;
863
#endif
864
}
865
 
866
wxString ecSettings::GetInstallVersionKey ()
867
{
868
#ifdef __WXMSW__
869
 
870
#ifndef MAX_PATH
871
#define MAX_PATH 1024
872
#endif
873
 
874
    wxString strKey = wxT("SOFTWARE\\eCos");
875
    wxString strVersionKey = wxT("");
876
    wxString rc = wxT("");
877
    wxChar pszBuffer [MAX_PATH + 1];
878
    HKEY hKey;
879
 
880
    // get the greatest eCos version subkey
881
    if (ERROR_SUCCESS == RegOpenKeyEx (HKEY_LOCAL_MACHINE, strKey, 0L, KEY_READ, &hKey)) {
882
        DWORD dwIndex = 0;
883
        while (ERROR_SUCCESS == RegEnumKey (hKey, dwIndex++, (LPTSTR) pszBuffer, sizeof (pszBuffer))) {
884
            if (strVersionKey.CompareTo (pszBuffer) < 0) {
885
                strVersionKey = pszBuffer;
886
            }
887
        }
888
        RegCloseKey (hKey);
889
    }
890
    return strVersionKey;
891
#else
892
    wxMessageBox(wxT("GetInstallVersionKey() is only implemented for Windows."));
893
    return wxEmptyString;
894
#endif
895
}
896
 
897
/*
898
 * ecRunTestSettings
899
 * Settings relating to running tests
900
 */
901
 
902
IMPLEMENT_DYNAMIC_CLASS(ecRunTestsSettings, wxObject)
903
 
904
ecRunTestsSettings::ecRunTestsSettings():
905
    m_ep(CeCosTest::ExecutionParameters::RUN),
906
    m_nTimeout(900),
907
    m_nDownloadTimeout(120),
908
    m_nTimeoutType(TIMEOUT_AUTOMATIC),
909
    m_nDownloadTimeoutType(TIMEOUT_SPECIFIED),
910
    m_bRemote(FALSE),
911
    m_bSerial(TRUE),
912
    m_strPort(wxT("/dev/ttyS0")),
913
    m_nBaud(38400),
914
    m_nLocalTCPIPPort(9000),
915
    m_nReset(RESET_MANUAL),
916
    m_nResourcePort(1),
917
    m_nRemotePort(1),
918
    m_bFarmed(TRUE),
919
    m_strRemoteHost(wxT("")),
920
    m_strResourceHost(wxT("")),
921
    m_strLocalTCPIPHost(wxT("")),
922
    m_strReset(wxT(""))
923
{
924
}
925
 
926
ecRunTestsSettings::ecRunTestsSettings(const ecRunTestsSettings& settings)
927
{
928
    Copy(settings);
929
}
930
 
931
void ecRunTestsSettings::Copy(const ecRunTestsSettings& settings)
932
{
933
    m_nTimeoutType = settings.m_nTimeoutType;
934
    m_nDownloadTimeoutType = settings.m_nDownloadTimeoutType;
935
    m_bRemote = settings.m_bRemote;
936
    m_bSerial = settings.m_bSerial;
937
    m_strPort = settings.m_strPort;
938
    m_nBaud = settings.m_nBaud;
939
    m_nLocalTCPIPPort = settings.m_nLocalTCPIPPort;
940
    m_nReset = settings.m_nReset;
941
    m_nResourcePort = settings.m_nResourcePort;
942
    m_nRemotePort = settings.m_nRemotePort;
943
    m_bFarmed = settings.m_bFarmed;
944
    m_strTarget = settings.m_strTarget;
945
    m_strRemoteHost = settings.m_strRemoteHost;
946
    m_strResourceHost = settings.m_strResourceHost;
947
    m_strLocalTCPIPHost = settings.m_strLocalTCPIPHost;
948
    m_strReset = settings.m_strReset;
949
}
950
 
951
bool ecRunTestsSettings::LoadConfig(wxConfig& config)
952
{
953
    config.Read(_("/Run Tests/TimeoutType"), & m_nTimeoutType);
954
    config.Read(_("/Run Tests/DownloadTimeoutType"), & m_nDownloadTimeoutType);
955
    config.Read(_("/Run Tests/Remote"), (bool*) & m_bRemote);
956
    config.Read(_("/Run Tests/Serial"), (bool*) & m_bSerial);
957
    config.Read(_("/Run Tests/Port"), & m_strPort);
958
    config.Read(_("/Run Tests/Baud"), & m_nBaud);
959
    config.Read(_("/Run Tests/LocalTCPIPHost"), & m_strLocalTCPIPHost);
960
    config.Read(_("/Run Tests/LocalTCPIPPort"), & m_nLocalTCPIPPort);
961
//  Reset type is determined at run-time for standalone configtool
962
//    config.Read(_("/Run Tests/ResetType"), & m_nReset);
963
    config.Read(_("/Run Tests/ResetString"), & m_strReset);
964
    config.Read(_("/Run Tests/ResourceHost"), & m_strResourceHost);
965
    config.Read(_("/Run Tests/ResourcePort"), & m_nResourcePort);
966
    config.Read(_("/Run Tests/RemoteHost"), & m_strRemoteHost);
967
    config.Read(_("/Run Tests/RemotePort"), & m_nRemotePort);
968
    config.Read(_("/Run Tests/Farmed"), (bool*) & m_bFarmed);
969
 
970
    return TRUE;
971
}
972
 
973
bool ecRunTestsSettings::SaveConfig(wxConfig& config)
974
{
975
    config.Write(_("/Run Tests/TimeoutType"), (long) m_nTimeoutType);
976
    config.Write(_("/Run Tests/DownloadTimeoutType"), (long) m_nDownloadTimeoutType);
977
    config.Write(_("/Run Tests/Remote"), m_bRemote);
978
    config.Write(_("/Run Tests/Serial"), m_bSerial);
979
    config.Write(_("/Run Tests/Port"), m_strPort);
980
    config.Write(_("/Run Tests/Baud"), (long) m_nBaud);
981
    config.Write(_("/Run Tests/LocalTCPIPHost"), m_strLocalTCPIPHost);
982
    config.Write(_("/Run Tests/LocalTCPIPPort"), (long) m_nLocalTCPIPPort);
983
    config.Write(_("/Run Tests/ResetType"), (long) m_nReset);
984
    config.Write(_("/Run Tests/ResetString"), m_strReset);
985
    config.Write(_("/Run Tests/ResourceHost"), m_strResourceHost);
986
    config.Write(_("/Run Tests/ResourcePort"), (long) m_nResourcePort);
987
    config.Write(_("/Run Tests/RemoteHost"), m_strRemoteHost);
988
    config.Write(_("/Run Tests/RemotePort"), (long) m_nRemotePort);
989
    config.Write(_("/Run Tests/Farmed"), m_bFarmed);
990
 
991
    return TRUE;
992
}
993
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.