2 * Copyright (C) 2005 Casper S. Hornstrup
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 SysSetupGenerator::SysSetupGenerator ( const Project
& project
)
31 SysSetupGenerator::~SysSetupGenerator ()
36 SysSetupGenerator::Generate ()
39 unsigned long errorLine
;
41 string syssetupTemplate
= "media" + sSep
+ "inf" + sSep
+ "syssetup.inf.tpl";
42 string syssetup
= "media" + sSep
+ "inf" + sSep
+ "syssetup.inf";
44 if ( 0 != InfHostOpenFile ( &inf
, syssetupTemplate
.c_str (), &errorLine
) )
45 throw new FileNotFoundException ( syssetupTemplate
);
47 for ( size_t i
= 0; i
< project
.modules
.size (); i
++ )
49 const Module
& module
= *project
.modules
[i
];
50 if ( module
.autoRegister
!= NULL
)
51 Generate ( inf
, module
);
54 if ( 0 != InfHostWriteFile ( inf
, syssetup
.c_str (), "" ) )
56 InfHostCloseFile ( inf
);
57 throw new AccessDeniedException ( syssetup
);
60 InfHostCloseFile ( inf
);
63 #define DIRECTORYID_SYSTEM32 "11"
66 SysSetupGenerator::GetDirectoryId ( const Module
& module
)
68 if ( ToLower ( module
.installBase
) == "system32" )
69 return DIRECTORYID_SYSTEM32
;
70 throw InvalidOperationException ( __FILE__
,
74 #define FLG_REGSVR_DLLREGISTER "1"
75 #define FLG_REGSVR_DLLINSTALL "2"
76 #define FLG_REGSVR_BOTH "3"
79 SysSetupGenerator::GetFlags ( const Module
& module
)
81 if ( module
.autoRegister
->type
== DllRegisterServer
)
82 return FLG_REGSVR_DLLREGISTER
;
83 if ( module
.autoRegister
->type
== DllInstall
)
84 return FLG_REGSVR_DLLINSTALL
;
85 if ( module
.autoRegister
->type
== Both
)
86 return FLG_REGSVR_BOTH
;
87 throw InvalidOperationException ( __FILE__
,
92 SysSetupGenerator::Generate ( HINF inf
,
93 const Module
& module
)
97 string infSection
= module
.autoRegister
->infSection
;
98 if ( 0 != InfHostFindOrAddSection ( inf
, infSection
.c_str (), &context
) )
100 throw new Exception ( ".inf section '%s' not found", infSection
.c_str () );
101 InfHostCloseFile ( inf
);
104 if ( 0 != InfHostAddLine ( context
, NULL
) ||
105 0 != InfHostAddField ( context
, GetDirectoryId ( module
).c_str () ) ||
106 0 != InfHostAddField ( context
, "" ) ||
107 0 != InfHostAddField ( context
, module
.installName
.c_str () ) ||
108 0 != InfHostAddField ( context
, GetFlags ( module
).c_str () ) )
110 InfHostFreeContext ( context
);
111 InfHostCloseFile ( inf
);
112 throw InvalidOperationException ( __FILE__
,
116 InfHostFreeContext ( context
);