summaryrefslogtreecommitdiffstats
path: root/private/unimodem/new/mic/mic.cpp
blob: 9fa79d69579d5322842302db430a949f700d661d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
//						
//		Copyright (c) 1996 Microsoft Corporation
//
//
//		MIC.CPP		-- Modem INF Compiler -- basic version
//						
//		Copyright (c) 1996 Microsoft Corporation
//
//
//		History:
//			06/04/96	JosephJ		Created
//
#include "common.h"
#include "ini.h"
#include "inf.h"
#include "dev.h"
#include "test.h"

#define SIMPLE 0
#define COMPLEX 1
#define ACTUAL 2

//#define TEST_TYPE (SIMPLE)
#define TEST_TYPE (COMPLEX)
//#define TEST_TYPE (ACTUAL)


#if (TEST_TYPE==SIMPLE)
#elif (TEST_TYPE==COMPLEX)
#elif (TEST_TYPE==ACTUAL)
#endif

class CMicOptions
{
public:
	CMicOptions(void)	{}
	~CMicOptions()		{}
	BOOL	Load (int argc, const char *argv[]);
	void	Unload(void) {}
	static void	Usage(void);
	const TCHAR *OrigInfPath(void) {return m_rgchOrigInfPath;}
	const TCHAR *NewInfDir(void) {return m_rgchNewInfDir;}
	
private:

	TCHAR m_rgchOrigInfPath[MAX_PATH];
	TCHAR m_rgchNewInfDir[MAX_PATH];

};

CMicOptions gMicOptions;

BOOL CMicOptions::Load (int argc, const char *argv[])
{
	BOOL fRet = FALSE;
	UINT u;

	if (argc!=3) goto end;

	if (lstrlen(argv[1]) >= (sizeof(m_rgchOrigInfPath)/sizeof(TCHAR)))
	{
		goto end;
	}

	u = lstrlen(argv[2]);
	// Extra space for possible addition of '\\'.
	if ((u+1) >= (sizeof(m_rgchNewInfDir)/sizeof(TCHAR)))
	{
		goto end;
	}

	lstrcpy(m_rgchOrigInfPath, argv[1]);
	lstrcpy(m_rgchNewInfDir, argv[2]);

	ASSERT(u);

	// Add final \, if required.
	{
		TCHAR tch = m_rgchNewInfDir[u-1];
		if ( (tch!=(TCHAR) '\\') && (u>2 || tch!=(TCHAR)':'))
		{
			m_rgchNewInfDir[u]=TCHAR('\\');
			m_rgchNewInfDir[u+1]=0;
		}
	}

	printf
	(
		"OrigIP=[%s]; NewID=[%s]\n",
		m_rgchOrigInfPath,
		m_rgchNewInfDir
	);
	fRet = TRUE;

end:
	return fRet;
}

void CMicOptions::Usage (void)
{
	printf(TEXT("\nUsage: mic <original-inf-path> <destination-dir>\n\n"));
}

int  main_mic(int argc, char * argv[])
{
	const CInfManufacturerEntry *pManuE = NULL;
	CInfFile *pInf= NULL;
	CInfDevice *pDev = NULL;


	// Parse Options
	// 	Format: mic <original inf path> <destination-dir>
	if (!gMicOptions.Load(argc, (const char **) argv))
	{
		CMicOptions::Usage();
		return 1;
	}

	pInf= new CInfFile();
	pDev = new CInfDevice(NULL);

	if (!pInf || !pDev) goto end;
	
	if (pInf->Load(gMicOptions.OrigInfPath()))
	{
		pManuE = pInf->GetFirstManufacturerEntry();
	}

	for (;pManuE; pManuE = pManuE->Next())
	{
		const CInfManufacturerSection *pManuS=pManuE->GetManufacturerSection();
		const CInfModelEntry		*pModelE = NULL;
		if (pManuS)
		{
			pModelE = pManuS->GetFirstModelEntry();
		}
		for (;pModelE; pModelE = pModelE->Next())
		{
			if (pDev->Load(pInf, pManuE, pModelE))
			{
				TCHAR rgchNewInf[MAX_PATH];
				DWORD dwRank0Checksum = pDev->Rank0Checksum();
				DWORD dwDeviceChecksum = pDev->Checksum();
				wsprintf
				(
					rgchNewInf,
					TEXT("%s%08lx_%08lx.inf"),
					gMicOptions.NewInfDir(),
					dwRank0Checksum,
					dwDeviceChecksum
				);
				pDev->Dump();

				pDev->WriteInf(rgchNewInf);
				pDev->Unload();
			}
		}
	}

end:
	if (pDev) {delete pDev; pDev=NULL;}
	if (pInf) {pInf->Unload(); delete pInf; pInf=NULL;}

	gMicOptions.Unload();

	return 0;
}