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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [tools/] [src/] [tools/] [configtool/] [standalone/] [wxwin/] [appsettings.cpp] - Blame information for rev 438

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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