~svn/ubuntu/raring/subversion/ppa

« back to all changes in this revision

Viewing changes to packages/win32-innosetup/tools/svnpath/main.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-12-05 01:26:14 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051205012614-qom4xfypgtsqc2xq
Tags: 1.2.3dfsg1-3ubuntu1
Merge with the final Debian release of 1.2.3dfsg1-3, bringing in
fixes to the clean target, better documentation of the libdb4.3
upgrade and build fixes to work with swig1.3_1.3.27.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * main.c: svnpath - Edit system path for Inno Setup Windows installer.
 
3
 *
 
4
 * USAGE:
 
5
 *     svnpath --help
 
6
 *
 
7
 * ====================================================================
 
8
 * Copyright (c) 2000-2004 CollabNet.  All rights reserved.
 
9
 *
 
10
 * This software is licensed as described in the file COPYING, which
 
11
 * you should have received as part of this distribution.  The terms
 
12
 * are also available at http://subversion.tigris.org/license-1.html.
 
13
 * If newer versions of this license are posted there, you may use a
 
14
 * newer version instead, at your option.
 
15
 *
 
16
 * This software consists of voluntary contributions made by many
 
17
 * individuals.  For exact contribution history, see the revision
 
18
 * history and logs, available at http://subversion.tigris.org/.
 
19
 * ====================================================================
 
20
 
 
21
 * Compiling with MinGW (use version 2.x with gcc 3.2 or better):
 
22
 *   Make sure that MinGW/bin is in your path and type:
 
23
 *     windres.exe -i svnpath.rc -I rc -o svnpath.res -O coff 
 
24
 *     gcc -s -Os -Wall -mwindows -march=i386 -o svnpath.exe svnpath.res main.c
 
25
 * Compiling with MS Visual C (use VC 5.x.):
 
26
 *   Make a new Win32 Console Application project with the name svnpath
 
27
 *   and add this file to your project.
 
28
 *   NOTE: Do not even think about using something newer than VC 5.x. This is
 
29
 *         an installation program and the required runtime files are newer
 
30
 *         than some of the targed OS's (Win 2000 and older). 
 
31
 * Compiling with the free Borland compiler bcc55:
 
32
 *   Make sure that the bcc bin directory is in your path and type:
 
33
 *     bcc32.exe -WC -O1 -fp -esvnpath main.c
 
34
 *
 
35
 * NOTES:
 
36
 *   * Some Win32 API equivalents are used in stead of the standard C functions
 
37
 *     in order to reduce executable size (when compiled with VC).
 
38
 *     This functions as: lstrcpy, lstrcat.
 
39
 *   * Keep away from Cygwin and pre MinGW 2.x. This app must run on all Win32
 
40
 *     OS's independed of any extra dll's.
 
41
 */
 
42
 
 
43
/* ==================================================================== */
 
44
 
 
45
 
 
46
/*** Includes. ***/
 
47
#include <stdio.h>
 
48
#include <stdlib.h>
 
49
#include <string.h>
 
50
#include <windows.h>
 
51
#include <io.h>
 
52
#include <sys\stat.h>
 
53
 
 
54
/*** Constants ***/
 
55
#define BUFSIZE 4000
 
56
 
 
57
/*** Global variables ***/
 
58
static char g_AuExBatFile[17] = "C:\\Autoexec.bat";
 
59
static char g_AuExSvnFile[17] = "C:\\Autoexec.svn";
 
60
 
 
61
char g_cSvnLineRem1[80];    /* Look at the svn_set_auexlines routine */
 
62
char g_cSvnLineRem2[80];    /* for setting the values                */
 
63
char g_cSvnLinePath[256];   /*                                       */
 
64
 
 
65
/*** Prototypes ***/
 
66
int svn_add9x (char cPath[255]);
 
67
int svn_addnt (char cPath[BUFSIZE]);
 
68
void svn_error_msg(char cMsg[255]);
 
69
int svn_os_is_nt();
 
70
int svn_print_help();
 
71
int svn_read_regval (HKEY hKey, char cValue[10], char cKey[BUFSIZE],
 
72
                     char *pcPathCur[BUFSIZE], DWORD *lpType);
 
73
int svn_remove9x (char cPath[255]);
 
74
int svn_removent (char cPath[255]);
 
75
int svn_run_cmd (char cAction[10], char cPath[255]);
 
76
int svn_set_auexlines (char cPath[255]);
 
77
int svn_svnpath_exists (char cPath[255]);
 
78
 
 
79
/*** Main. ***/
 
80
/*
 
81
 * Initial program flow
 
82
 */
 
83
int
 
84
main (int argc, char *argv[])
 
85
{
 
86
    int counter=0, iCmdArgError=1, iRetVal=1;
 
87
    char cMsg[150];
 
88
 
 
89
    switch (argc)
 
90
      {
 
91
        case 1: /* missing arguments */
 
92
            lstrcpy ( cMsg, "Missing arguments.");
 
93
            svn_error_msg(cMsg);
 
94
            iRetVal = 65;
 
95
            iCmdArgError=0;
 
96
            break;
 
97
        case 2: /* help */
 
98
            if (! strcmp(argv[1], "--help") || ! strcmp(argv[1], "-h"))
 
99
              {
 
100
                iRetVal=svn_print_help();
 
101
                iCmdArgError=0;
 
102
              }
 
103
            break;
 
104
        case 3: /* add|remove path */
 
105
            if (! strcmp(argv[1], "add") || ! strcmp(argv[1], "remove"))
 
106
              {
 
107
                iRetVal=svn_run_cmd(argv[1], argv[2]);
 
108
                iCmdArgError=0;
 
109
              }
 
110
            break;
 
111
        default:
 
112
              iRetVal = 1;
 
113
      }
 
114
 
 
115
    if (iCmdArgError)
 
116
      {
 
117
        /* It's still hope to run a command when another program (IS) has
 
118
         * started svnpath, so we will try to resolve it. */
 
119
 
 
120
        lstrcpy ( cMsg, "Argument Error: Wrong arguments\n\n");
 
121
        lstrcat ( cMsg, "This program received the following arguments:");
 
122
        
 
123
        for (counter=1; counter<argc; counter++)
 
124
          {
 
125
            lstrcat ( cMsg, "\n    '");
 
126
            lstrcat ( cMsg, argv[counter]);
 
127
            lstrcat ( cMsg, "'");
 
128
          }
 
129
 
 
130
        if ((!strcmp(argv[1], "add") || !strcmp(argv[1], "remove")) && (argc > 3))
 
131
          {
 
132
            iRetVal=svn_run_cmd(argv[1], argv[2]);
 
133
            iCmdArgError=0;              
 
134
          }
 
135
        else
 
136
          {  
 
137
            svn_error_msg(cMsg);
 
138
            iRetVal = 1;
 
139
          }
 
140
      }
 
141
    return (iRetVal);
 
142
}
 
143
 
 
144
/*** svn_add9x ***/
 
145
/*
 
146
 * Adding the path to the %PATH% environment in Autoexec.bat for Win9x
 
147
 */
 
148
int
 
149
svn_add9x (char cPath[255])
 
150
{
 
151
    char cSvnCnt[1024];
 
152
    int iAutoBatRo=0;
 
153
    FILE *FH_AUBAT;
 
154
 
 
155
    /* Fill up cSvnPath with the svn contents of Autoexec.bat */
 
156
    svn_set_auexlines(cPath);
 
157
    lstrcpy (cSvnCnt, g_cSvnLineRem1);
 
158
    lstrcat (cSvnCnt, g_cSvnLineRem2);
 
159
    lstrcat (cSvnCnt, g_cSvnLinePath);
 
160
 
 
161
    /* Make a backup of Autoexec.bat to Autoexec.svn if it exists, write the
 
162
     * svn stuff to Autoexec.bat */
 
163
    if( _access(g_AuExBatFile, 0 ) != -1)
 
164
      {
 
165
        /* The file exists, so we make sure that we have write permission before
 
166
         * we continue*/
 
167
        if((_access(g_AuExBatFile, 2)) == -1)
 
168
          {
 
169
            _chmod(g_AuExBatFile, _S_IWRITE);
 
170
            iAutoBatRo=1;
 
171
          }
 
172
 
 
173
        /* Make the backup */
 
174
        CopyFileA(g_AuExBatFile, g_AuExSvnFile, FALSE);
 
175
      }
 
176
 
 
177
    /* Write the svn stuff to the file */
 
178
    FH_AUBAT = fopen(g_AuExBatFile, "a+t");
 
179
        fputs(cSvnCnt, FH_AUBAT);
 
180
    fclose(FH_AUBAT);
 
181
 
 
182
    /* Turn back to Read only if that was the original state */
 
183
    if (iAutoBatRo)
 
184
      {
 
185
        _chmod(g_AuExBatFile, _S_IREAD);
 
186
      }
 
187
 
 
188
    return 0;
 
189
}
 
190
 
 
191
/*** svn_addnt ***/
 
192
/*
 
193
 * Adding the path to the %PATH% environment in the registry on Win-NT's
 
194
 */
 
195
int
 
196
svn_addnt (char cPathSvn[255])
 
197
{
 
198
    long lRet;
 
199
    char cPathTmp[BUFSIZE];
 
200
 
 
201
    HKEY hKey;
 
202
    char cKey[BUFSIZE], cPathNew[BUFSIZE], cPathCur[BUFSIZE];
 
203
    DWORD dwBufLen, lpType;
 
204
    char *pcPathCur[BUFSIZE];
 
205
    dwBufLen=BUFSIZE;
 
206
    *pcPathCur=cPathCur;
 
207
 
 
208
    lstrcpy (cPathTmp, cPathSvn);
 
209
 
 
210
    if (svn_svnpath_exists(cPathTmp))
 
211
      {
 
212
        exit (1);
 
213
      }
 
214
 
 
215
    lstrcpy(cKey, "SYSTEM\\CurrentControlSet\\");
 
216
    lstrcat(cKey, "Control\\Session Manager\\Environment");
 
217
 
 
218
    /* Get value, value type and current path from HKLM and try to append
 
219
     * the svnpath to it */
 
220
    svn_read_regval (HKEY_LOCAL_MACHINE, "Path", cKey, &*pcPathCur, &lpType);
 
221
 
 
222
    /* Reopen the key for writing */
 
223
    lRet = RegCreateKeyEx(
 
224
              HKEY_LOCAL_MACHINE, cKey, 0, NULL,
 
225
              REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
 
226
              &hKey, &dwBufLen);
 
227
 
 
228
    /* Add the subversion path to the path */
 
229
    lstrcpy(cPathNew, cPathCur);
 
230
    lstrcat(cPathNew, ";");
 
231
    lstrcat(cPathNew, cPathSvn);
 
232
 
 
233
    lRet = RegSetValueExA(hKey, "Path", 0, lpType,
 
234
                          (BYTE*)cPathNew, strlen(cPathNew)+1);
 
235
    RegCloseKey(hKey);
 
236
 
 
237
    /* If it went wrong to do it with HKLM, then try HKCU */
 
238
    if (lRet != 0)
 
239
      {
 
240
        strcpy (cPathCur, "");
 
241
 
 
242
        lRet = svn_read_regval(HKEY_CURRENT_USER, "Path",
 
243
                               "Environment", &*pcPathCur, &lpType);
 
244
 
 
245
        /* Current Path may be empty */
 
246
        cPathNew[0] = 0;
 
247
        if (strlen(cPathCur))
 
248
        {
 
249
          lstrcpy(cPathNew, cPathCur);
 
250
          lstrcat(cPathNew, ";");
 
251
        }
 
252
        else
 
253
          lpType = REG_EXPAND_SZ;
 
254
 
 
255
        lstrcat(cPathNew, cPathSvn);
 
256
 
 
257
        /* Reopen the key for writing */
 
258
        lRet = RegCreateKeyEx(
 
259
                  HKEY_CURRENT_USER, "Environment", 0, NULL,
 
260
                  REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
 
261
                  &hKey, &dwBufLen);
 
262
 
 
263
        lRet = RegSetValueExA(hKey, "Path", 0, lpType,
 
264
                              (LPBYTE)cPathNew, strlen(cPathNew)+1);
 
265
 
 
266
        RegCloseKey(hKey);
 
267
      }
 
268
 
 
269
    if (lRet != 0)
 
270
      {
 
271
        return (1);
 
272
      }
 
273
    else
 
274
      {
 
275
        long lRet;
 
276
 
 
277
        /* Tell the system about the new path */
 
278
        SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
 
279
                           (LPARAM) "Environment", SMTO_ABORTIFHUNG,
 
280
                           5000, &lRet);
 
281
        return (0);
 
282
      }
 
283
}
 
284
 
 
285
/*** svn_error_msg ***/
 
286
/*
 
287
 * Displays a message box with a error message
 
288
 */
 
289
void
 
290
svn_error_msg(char cMsg[150])
 
291
{
 
292
    long lRet;
 
293
    long lMsgBoxFlag=MB_YESNO+MB_ICONWARNING+MB_SETFOREGROUND+MB_TOPMOST;
 
294
 
 
295
    lstrcat(cMsg, "\n\nDo you want to read the help for svnpath?");
 
296
    
 
297
    lRet=MessageBox(0, cMsg, "svnpath - Error" , lMsgBoxFlag);
 
298
    
 
299
    if (lRet==IDYES)
 
300
    {
 
301
      svn_print_help();
 
302
    }
 
303
}
 
304
 
 
305
/*** svn_os_is_nt ***/
 
306
/*
 
307
 * Determing if the OS type is Windows NT or not. Returns 1 if true
 
308
 */
 
309
int
 
310
svn_os_is_nt()
 
311
{
 
312
    /* NOTE: Use OSVERSIONINFO and not OSVERSIONINFOEX, older VC's have bogus
 
313
     *       headers */
 
314
    int iRetVal=0;
 
315
 
 
316
    OSVERSIONINFO osvi;
 
317
    BOOL bOsVersionInfoEx;
 
318
    ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
 
319
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
 
320
 
 
321
    if( !(bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi)) )
 
322
      {
 
323
        osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
 
324
        if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) )
 
325
          {
 
326
            exit (1);
 
327
          }
 
328
      }
 
329
 
 
330
    if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT)
 
331
      {
 
332
        iRetVal=1;
 
333
      }
 
334
 
 
335
    return (iRetVal);
 
336
}
 
337
 
 
338
/*** svn_print_help ***/
 
339
/*
 
340
 * Printing out help on the console
 
341
 */
 
342
int
 
343
svn_print_help()
 
344
{
 
345
    char cMsgBoxCaption[80];
 
346
    char cMsgBoxMsg[1024];
 
347
    long lMsgBoxFlag=MB_OK+MB_ICONINFORMATION+MB_SETFOREGROUND;
 
348
 
 
349
    lstrcpy(cMsgBoxCaption, "Help for svnpath");
 
350
 
 
351
 
 
352
    lstrcpy(cMsgBoxMsg, "svnpath - Add/remove a path on the system's PATH environment variable\n\n");
 
353
 
 
354
    lstrcat(cMsgBoxMsg, "usage:\tsvnpath add|remove \"Path\"\n");
 
355
    lstrcat(cMsgBoxMsg, "\tsvnpath -h|--help\n\n");
 
356
 
 
357
    lstrcat(cMsgBoxMsg, "Example:\tsvnpath add \"C:\\Path\\to\\svn.exe\"\n\n");
 
358
 
 
359
 
 
360
    lstrcat(cMsgBoxMsg, "Command explanations:\n");
 
361
    lstrcat(cMsgBoxMsg, "    add <path>\n");
 
362
    lstrcat(cMsgBoxMsg, "        Adding the path to the system's PATH environment variable\n");
 
363
    lstrcat(cMsgBoxMsg, "    remove <path>,\n");
 
364
    lstrcat(cMsgBoxMsg, "        Removing the path from the system's PATH environment ");
 
365
    lstrcat(cMsgBoxMsg, "variable\n\n");
 
366
 
 
367
    lstrcat(cMsgBoxMsg, "        * On the Windows 9x variations, the Autoexec.bat file are ");
 
368
    lstrcat(cMsgBoxMsg, "edited\n");
 
369
    lstrcat(cMsgBoxMsg, "        * On the Windows NT variations, the registry are edited. The ");
 
370
    lstrcat(cMsgBoxMsg, "program tries\n");
 
371
    lstrcat(cMsgBoxMsg, "            to edit the Environment in HKLM first. If that fails, then ");
 
372
    lstrcat(cMsgBoxMsg, "the Environment\n            in HKCU are used.\n\n");
 
373
 
 
374
    lstrcat(cMsgBoxMsg, "    -h, --help:    Print help (this page)\n\n");
 
375
 
 
376
    lstrcat(cMsgBoxMsg, "Notes:\n");
 
377
    lstrcat(cMsgBoxMsg, "   * For playing safe: -Make sure that the given path allways is ");
 
378
    lstrcat(cMsgBoxMsg, "quoted between\n");
 
379
    lstrcat(cMsgBoxMsg, "      two \"'s wherewer the path contains spaces or not\n");
 
380
 
 
381
    MessageBox(0,cMsgBoxMsg, cMsgBoxCaption , lMsgBoxFlag);
 
382
 
 
383
    return 0;
 
384
}
 
385
 
 
386
/*** svn_read_regval ***/
 
387
/*
 
388
 * Reading a registry value
 
389
 */
 
390
int
 
391
svn_read_regval (HKEY hKey, char cValue[10], char cKey[BUFSIZE],
 
392
                 char *pcPathCur[BUFSIZE], DWORD *lpType)
 
393
{
 
394
    long lRet;
 
395
    DWORD dwBufLen;
 
396
    dwBufLen=BUFSIZE;
 
397
 
 
398
    /* Get the key value and put in pcPathCur */
 
399
    lRet = RegOpenKeyExA(hKey, cKey,
 
400
                         0, KEY_READ, &hKey );
 
401
 
 
402
    lRet = RegQueryValueExA(hKey, cValue, NULL, &*lpType,
 
403
                             (LPBYTE) &**pcPathCur, &dwBufLen);
 
404
 
 
405
    RegCloseKey(hKey);
 
406
 
 
407
    if (lRet != 0)
 
408
      {
 
409
        return (1);
 
410
      }
 
411
    else
 
412
      {
 
413
        return (0);
 
414
      }
 
415
}
 
416
 
 
417
/*** svn_remove9x ***/
 
418
/*
 
419
 * Removing the path from the %PATH% environment in Autoexec.bat for Win-9x
 
420
 */
 
421
int
 
422
svn_remove9x (char cPath[255])
 
423
{
 
424
    char cPathTmp[255];
 
425
 
 
426
    FILE *FH_AUBAT, *FH_AUSVN;
 
427
    char cLineBuffer[255];
 
428
    char cSvnLineBuffer[255];
 
429
    int iCounter=0;
 
430
    int iAutoBatRo=0;
 
431
 
 
432
    lstrcpy (cPathTmp, cPath);
 
433
    if (! svn_svnpath_exists(cPathTmp))
 
434
      {
 
435
        exit(1);
 
436
      }
 
437
 
 
438
    /* Make a backup of Autoexec.bat to Autoexec.svn if it exists, write the
 
439
     * svn stuff to Autoexec.bat */
 
440
    if(_access(g_AuExBatFile, 0) != -1)
 
441
      {
 
442
        /* The file exists, so we make sure that we have write permission
 
443
         *  before we continue*/
 
444
        if((_access(g_AuExBatFile, 2 )) == -1)
 
445
          {
 
446
            _chmod(g_AuExBatFile, _S_IWRITE);
 
447
            iAutoBatRo=1;
 
448
          }
 
449
 
 
450
        /* Make the backup */
 
451
        CopyFileA(g_AuExBatFile, g_AuExSvnFile, FALSE);
 
452
      }
 
453
 
 
454
    /* Open Autoexec.svn and parse it line by line. Save the new contents
 
455
     * to Autoexec.bat */
 
456
    FH_AUSVN=fopen(g_AuExSvnFile, "rt");
 
457
    FH_AUBAT=fopen(g_AuExBatFile, "wt");
 
458
 
 
459
    /* Give cSvnLineBuffer the first line to remove from Autoexec.bat */
 
460
    svn_set_auexlines(cPath);
 
461
    lstrcpy (cSvnLineBuffer, g_cSvnLineRem1);
 
462
 
 
463
    while(fgets(cLineBuffer, 255, FH_AUSVN) != NULL)
 
464
      {
 
465
        if (strstr (cLineBuffer, cSvnLineBuffer) == NULL)
 
466
          {
 
467
            fputs(cLineBuffer, FH_AUBAT);
 
468
          }
 
469
        else
 
470
          {
 
471
            iCounter++;
 
472
            switch (iCounter)
 
473
              {
 
474
                case 1:
 
475
                  lstrcpy (cSvnLineBuffer, g_cSvnLineRem2);
 
476
                  break;
 
477
                case 2:
 
478
                  lstrcpy (cSvnLineBuffer, g_cSvnLinePath);
 
479
                  break;
 
480
              }
 
481
          }
 
482
      }
 
483
 
 
484
    fclose(FH_AUSVN);
 
485
    fclose(FH_AUBAT);
 
486
 
 
487
    /* Turn back to Read only if that was the original state */
 
488
    if (iAutoBatRo)
 
489
      {
 
490
        _chmod(g_AuExBatFile, _S_IREAD);
 
491
      }
 
492
 
 
493
    return 0;
 
494
}
 
495
 
 
496
/*** svn_removent ***/
 
497
/*
 
498
 * Removing the path from the %PATH% environment in the registry on Win-NT's
 
499
 */
 
500
int
 
501
svn_removent (char cPathSvn[255])
 
502
{
 
503
    long lRet;
 
504
    char cPathTmp[BUFSIZE];
 
505
 
 
506
    HKEY hKey;
 
507
    char cKey[BUFSIZE], cPathNew[BUFSIZE], cPathCur[BUFSIZE];
 
508
    DWORD dwBufLen, lpType;
 
509
    char *pcPathCur[BUFSIZE];
 
510
    
 
511
    char * pcSubPath;
 
512
    
 
513
    *pcPathCur=cPathCur;
 
514
    dwBufLen=BUFSIZE;
 
515
 
 
516
    lstrcpy (cPathTmp, cPathSvn);
 
517
 
 
518
    if (! svn_svnpath_exists(cPathTmp))
 
519
      {
 
520
        exit (1);
 
521
      }
 
522
 
 
523
    lstrcpy(cKey, "SYSTEM\\CurrentControlSet\\");
 
524
    lstrcat(cKey, "Control\\Session Manager\\Environment");
 
525
 
 
526
    /* Get value, value type and current path from HKLM and try to append
 
527
     * the svnpath to it */
 
528
    lRet = svn_read_regval(HKEY_LOCAL_MACHINE, "Path",
 
529
                           cKey, &*pcPathCur, &lpType);
 
530
 
 
531
    /* Reopen the key for writing */
 
532
    lRet = RegCreateKeyEx(
 
533
              HKEY_LOCAL_MACHINE, cKey, 0, NULL,
 
534
              REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
 
535
              &hKey, &dwBufLen);
 
536
 
 
537
    /* Remove the Subversion path from the system path and put the new path
 
538
     * on cPathNew*/
 
539
     
 
540
    pcSubPath = strtok (cPathCur,";");
 
541
    strcpy(cPathNew, "");
 
542
 
 
543
    while (pcSubPath != NULL)
 
544
      {
 
545
        if (strcmp(pcSubPath, cPathSvn))
 
546
          {
 
547
            if (strlen(cPathNew)==0)
 
548
              {
 
549
                lstrcpy(cPathNew, pcSubPath);
 
550
              }
 
551
            else
 
552
              {
 
553
                lstrcat(cPathNew, ";");
 
554
                lstrcat(cPathNew, pcSubPath);
 
555
              }
 
556
          }
 
557
        pcSubPath = strtok (NULL, ";");
 
558
      }
 
559
 
 
560
    lRet = RegSetValueExA(hKey, "Path", 0, lpType,
 
561
                          (BYTE*)cPathNew, strlen(cPathNew)+1);
 
562
    RegCloseKey(hKey);
 
563
 
 
564
    /* If it went wrong to do it with HKLM, then try HKCU */
 
565
    if (lRet != 0)
 
566
      {
 
567
        strcpy(cPathCur, "");
 
568
        lRet = svn_read_regval(HKEY_CURRENT_USER, "Path", "Environment",
 
569
                               &*pcPathCur, &lpType);
 
570
 
 
571
        pcSubPath = strtok (cPathCur,";");
 
572
        
 
573
        strcpy(cPathNew, "");
 
574
        while (pcSubPath != NULL)
 
575
          {
 
576
            if (strcmp(pcSubPath, cPathSvn))
 
577
              {
 
578
                if (strlen(cPathNew)==0)
 
579
                  {
 
580
                    lstrcpy(cPathNew, pcSubPath);
 
581
                  }
 
582
                else
 
583
                  {
 
584
                    lstrcat(cPathNew, ";");
 
585
                    lstrcat(cPathNew, pcSubPath);
 
586
                  }
 
587
              }
 
588
 
 
589
            pcSubPath = strtok (NULL, ";");
 
590
          }
 
591
 
 
592
        /* Reopen the key for writing */
 
593
        lRet = RegCreateKeyEx(
 
594
                  HKEY_CURRENT_USER, "Environment", 0, NULL,
 
595
                  REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,
 
596
                  &hKey, &dwBufLen);
 
597
 
 
598
        lRet = RegSetValueExA(hKey, "Path", 0, lpType,
 
599
                              (LPBYTE)cPathNew, strlen(cPathNew)+1);
 
600
        if (lRet != 0)
 
601
          {
 
602
            return (1);
 
603
          }
 
604
 
 
605
        RegCloseKey(hKey);
 
606
      }
 
607
 
 
608
    if (lRet != 0)
 
609
      {
 
610
        return (lRet);
 
611
      }
 
612
    else
 
613
      {
 
614
        /* Tell the system about the new path */
 
615
        SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
 
616
                           (LPARAM) "Environment", SMTO_ABORTIFHUNG,
 
617
                            5000, &lRet);
 
618
      }
 
619
 
 
620
    return (0);
 
621
}
 
622
 
 
623
/*** svn_run_cmd ***/
 
624
/*
 
625
 * Running the ordinary command line when adding/removing a path
 
626
 */
 
627
int
 
628
svn_run_cmd (char cAction[10], char cPath[255])
 
629
{
 
630
    int iRetVal=1;
 
631
 
 
632
    if (svn_os_is_nt())
 
633
      {
 
634
        if (! strcmp(cAction, "add"))
 
635
          {
 
636
            iRetVal=svn_addnt(cPath);
 
637
          }
 
638
        else if (! strcmp(cAction, "remove"))
 
639
          {
 
640
            iRetVal=svn_removent(cPath);
 
641
          }
 
642
      }
 
643
    else
 
644
      {
 
645
        if (! strcmp(cAction, "add"))
 
646
          {
 
647
            iRetVal=svn_add9x(cPath);
 
648
          }
 
649
        else if (! strcmp(cAction, "remove"))
 
650
          {
 
651
            iRetVal=svn_remove9x(cPath);
 
652
          }      
 
653
      }
 
654
 
 
655
    return (iRetVal);
 
656
}
 
657
 
 
658
/*** svn_set_auexlines ***/
 
659
/*
 
660
 * Filling the g_cSvnLine* variables with the svn contents of Autoexec.bat
 
661
 */
 
662
int
 
663
svn_set_auexlines (char cPath[255])
 
664
{
 
665
    lstrcpy (g_cSvnLineRem1, "REM *** For Subversion: ");
 
666
    lstrcat (g_cSvnLineRem1, "Don't touch this and the two next lines ***\n");
 
667
 
 
668
    lstrcpy (g_cSvnLineRem2, "REM *** They will be removed when Subversion is ");
 
669
    lstrcat (g_cSvnLineRem2, "uninstalled     ***\n");
 
670
 
 
671
    lstrcat (g_cSvnLinePath, "PATH=%PATH%;\"");
 
672
    lstrcat (g_cSvnLinePath, cPath);
 
673
    lstrcat (g_cSvnLinePath, "\"\n");
 
674
 
 
675
    return 0;
 
676
}
 
677
 
 
678
/*** svn_svnpath_exists ***/
 
679
/*
 
680
 * Checking if the svn path is in the system's PATH. Returns 0 if not and 1 if
 
681
 * it already exists
 
682
 */
 
683
int
 
684
svn_svnpath_exists (char cPath[255])
 
685
{
 
686
    char cSysPath[1024];
 
687
    DWORD dwLenPath;
 
688
    int iRetVal=0;
 
689
    char * pcSubPath;
 
690
 
 
691
    dwLenPath = GetEnvironmentVariable("PATH", cSysPath, 1024);
 
692
 
 
693
    /* Split %PATH% to it's sub paths and compare each of them with cPath. */
 
694
    if (dwLenPath)
 
695
      {
 
696
        pcSubPath = strtok (cSysPath,";");
 
697
 
 
698
        while (pcSubPath != NULL)
 
699
          {
 
700
            if (! strcmp(strupr(pcSubPath), strupr(cPath)) &&
 
701
                strlen(pcSubPath) == strlen(cPath))
 
702
              {
 
703
                iRetVal = 1;
 
704
                break;
 
705
              }
 
706
            pcSubPath = strtok (NULL, ";");
 
707
          }
 
708
      }
 
709
    else
 
710
      {
 
711
        exit (1);
 
712
      }
 
713
    return iRetVal;
 
714
}
 
715