summaryrefslogtreecommitdiff
path: root/NSCmpts/BackupData.cpp
blob: 5459f2a34f9a27590d27611b01c73dfca114ca30 (plain)
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
// BackupData.cpp: implementation of the CBackupData class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "BackupData.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

UINT CBackupData::m_nExtensions = 0;
UINT CBackupData::m_nSources = 0;


UINT CBackupData::LoadExtensions(string_array& asExt, const CPropertyBag& settings)
{
	int nCnt = 0;		// Number of URLs from Registry
	string sExt;
	string sKeyName;

	// Format Key Name
	sKeyName.format(NS_BACKUP_REG_EXT, nCnt++);

	while((sExt = settings.GetString(sKeyName, NS_NO_KEY)) != NS_NO_KEY)
	{
		asExt.push_back(sExt);
		sKeyName.format(NS_BACKUP_REG_EXT, nCnt++);
	}

	m_nExtensions = max(m_nExtensions, --nCnt);
	return nCnt;
}

UINT CBackupData::SaveExtensions(const string_array& asExt, CPropertyBag& settings)
{
	UINT nCnt = 0;		// Number of URLs from Registry
	string sKeyName = _T("");

	string_array::const_iterator iter = asExt.begin();
	for(; iter != asExt.end(); iter++)
	{
		sKeyName.format(NS_BACKUP_REG_EXT, nCnt++);
		settings.WriteString(sKeyName, *iter);
	}

	UINT nRet = nCnt - 1;

	for(; nCnt < m_nExtensions; nCnt++) 
	{
		// Format Registry Key
		sKeyName.format(NS_BACKUP_REG_EXT, nCnt);
		settings.DeleteProperty(sKeyName);
	}

	m_nExtensions = 0;

	return nRet;
}

UINT CBackupData::LoadSources(file_array& aSources, const CPropertyBag& settings)
{
	int nCnt = 0;		
	string sPath;
	string sKeyName;

	// Format Key Name
	sKeyName.format(NS_BACKUP_REG_SOURCE, nCnt++);

	// Add URLs to List Box
	while((sPath = settings.GetString(sKeyName, NS_NO_KEY)) != NS_NO_KEY) 
	{
		aSources.push_back(sPath);
	
		// Format Key Name
		sKeyName.format(NS_BACKUP_REG_SOURCE, nCnt++);
	}

	return m_nSources = --nCnt;

}

UINT CBackupData::SaveSources(const file_array& aSources, CPropertyBag& settings)
{
	UINT nCnt = 0;		// Number of URLs from Registry
	string sKeyName;

	file_array::const_iterator iter = aSources.begin();
	for(; iter != aSources.end(); iter++)
	{
		sKeyName.format(NS_BACKUP_REG_SOURCE, nCnt++);
		settings.WriteString(sKeyName, *iter);
	}

	UINT nRet = nCnt - 1;

	for(; nCnt < m_nSources; nCnt++) 
	{
		// Format Registry Key
		sKeyName.format(NS_BACKUP_REG_SOURCE, nCnt);
		settings.DeleteProperty(sKeyName);
	}

	return nRet;
}