269 lines
6.9 KiB
C++
269 lines
6.9 KiB
C++
#include "stdafx.h"
|
|
#include "TinyXMLWrap.h"
|
|
|
|
bool ConfigHandler::bWaitForKey = FALSE;
|
|
bool ConfigHandler::bPrompt = TRUE;
|
|
bool ConfigHandler::bBackup = FALSE;
|
|
char ConfigHandler::dataPath[MAX_PATH];
|
|
ConfigHandler::ExecutionMode ConfigHandler::m_mode = ConfigHandler::Unset;
|
|
char ConfigHandler::outputFile[MAX_PATH];
|
|
bool ConfigHandler::bUseP4 = FALSE;
|
|
char ConfigHandler::P4Port[MAX_PATH];
|
|
char ConfigHandler::P4User[MAX_PATH];
|
|
char ConfigHandler::P4Client[MAX_PATH];
|
|
char ConfigHandler::P4Password[MAX_PATH];
|
|
char ConfigHandler::P4CL[MAX_PATH];
|
|
PerforceHandler ConfigHandler::p4con;
|
|
|
|
using namespace ProjectScanner;
|
|
std::vector<Action> ConfigHandler::m_actions;
|
|
|
|
void Action::compute()
|
|
{
|
|
_strlwr_s(m_path1, MAX_PATH);
|
|
_strlwr_s(m_path2, MAX_PATH);
|
|
m_path1Len = (unsigned int)strlen(m_path1);
|
|
m_path2Len = (unsigned int)strlen(m_path2);
|
|
for (unsigned int i=0; i<m_path1Len; i++)
|
|
{
|
|
if (m_path1[i] == '\\')
|
|
m_path1[i] = '/';
|
|
}
|
|
for (unsigned int i=0; i<m_path2Len; i++)
|
|
{
|
|
if (m_path2[i] == '\\')
|
|
m_path2[i] = '/';
|
|
}
|
|
}
|
|
|
|
bool ConfigHandler::ReadConfigFile(const char* _szXMLFile)
|
|
{
|
|
strcpy_s(outputFile, MAX_PATH-1, "UbiArt_Framework_ProjectScanner.html");
|
|
m_actions.clear();
|
|
ProjectScanner::Error::SetOS(ErrorOS_DOS);
|
|
|
|
ErrorOS os = ErrorOS_DOS;
|
|
bWaitForKey = FALSE;
|
|
bPrompt = TRUE;
|
|
|
|
m_mode = Unset;
|
|
|
|
const char* szDumpFileName = "ProjectScanner_Log.txt";
|
|
|
|
TinyXMLWrap XML;
|
|
if (!XML.openFile(_szXMLFile, false))
|
|
{
|
|
ProjectScanner::Error::Raise("FATAL: Could not open XML file %s", _szXMLFile);
|
|
return FALSE;
|
|
}
|
|
|
|
|
|
if (XML.enterElement("Errors"))
|
|
{
|
|
const char* val = XML.readAttribute("os");
|
|
if (val && !strcmp(val, "DOS"))
|
|
{
|
|
os = ErrorOS_DOS;
|
|
}
|
|
else
|
|
{
|
|
if (val && !strcmp(val, "WINDOWS"))
|
|
{
|
|
os = ErrorOS_Windows;
|
|
}
|
|
else
|
|
{
|
|
ProjectScanner::Error::Log("\"OS\" not regognized (supported are \"DOS\" and \"WINDOWS\") in XML file %s", _szXMLFile);
|
|
}
|
|
}
|
|
|
|
val = XML.readAttribute("prompt");
|
|
if (val && !strcmp(val, "Yes"))
|
|
{
|
|
bPrompt = TRUE;
|
|
}
|
|
else
|
|
{
|
|
if (val && !strcmp(val, "No"))
|
|
{
|
|
bPrompt = FALSE;
|
|
}
|
|
else
|
|
{
|
|
ProjectScanner::Error::Log("\"Prompt\" field %s contains bad value (supported are \"Yes\" and \"No\") in XML file %s", val, _szXMLFile);
|
|
}
|
|
}
|
|
|
|
val = XML.readAttribute("Wait_For_Key");
|
|
if (val && !strcmp(val, "Yes"))
|
|
{
|
|
bWaitForKey = TRUE;
|
|
}
|
|
else
|
|
{
|
|
if (val && !strcmp(val, "No"))
|
|
{
|
|
bWaitForKey = FALSE;
|
|
}
|
|
else
|
|
{
|
|
ProjectScanner::Error::Log("\"Wait_For_Key\" field %s contains bad value (supported are \"Yes\" and \"No\") in XML file %s", val, _szXMLFile);
|
|
}
|
|
}
|
|
XML.exitElement();
|
|
}
|
|
else
|
|
{
|
|
ProjectScanner::Error::Log("No \"Errors\" tag found in XML config file %s", _szXMLFile);
|
|
}
|
|
ProjectScanner::Error::Configure(os, bPrompt, bWaitForKey, szDumpFileName );
|
|
|
|
|
|
if (XML.enterElement("Files"))
|
|
{
|
|
const char* val = XML.readAttribute("Folder_Mode");
|
|
if (val && atoi(val))
|
|
m_mode = ReplaceFolder;
|
|
|
|
val = XML.readAttribute("Data_Path");
|
|
memset(dataPath, 0, MAX_PATH);
|
|
if (val)
|
|
strcpy_s(dataPath, MAX_PATH-1, val);
|
|
|
|
val = XML.readAttribute("backup");
|
|
if (val && !strcmp(val, "Yes"))
|
|
{
|
|
bBackup = TRUE;
|
|
}
|
|
else
|
|
{
|
|
if (val && !strcmp(val, "No"))
|
|
{
|
|
bBackup = FALSE;
|
|
}
|
|
else
|
|
{
|
|
ProjectScanner::Error::Log("\"backup\" field contains bad value (supported are \"Yes\" and \"No\") in XML file %s", _szXMLFile);
|
|
}
|
|
}
|
|
|
|
XML.exitElement();
|
|
}
|
|
else
|
|
{
|
|
ProjectScanner::Error::Log("No \"Files\" tag found in XML config file %s", _szXMLFile);
|
|
}
|
|
|
|
if (XML.enterElement("Action"))
|
|
{
|
|
if (m_mode != ReplaceFolder)
|
|
m_mode = ReplacePath;
|
|
do
|
|
{
|
|
Action action;
|
|
const char* val = XML.readAttribute("oldPath");
|
|
if (val)
|
|
action.setOldPath(val);
|
|
else
|
|
ProjectScanner::Error::Log("\"Action\" tag must feature a \"oldPath\" property");
|
|
|
|
val = XML.readAttribute("newPath");
|
|
if (val)
|
|
action.setNewPath(val);
|
|
else
|
|
ProjectScanner::Error::Log("\"Action\" tag must feature a \"newPath\" property");
|
|
action.compute();
|
|
m_actions.push_back(action);
|
|
} while (XML.nextSameElement());
|
|
}
|
|
|
|
if (XML.enterElement("FolderExclusion"))
|
|
{
|
|
if (m_mode == ReplacePath || m_mode == ReplaceFolder)
|
|
ProjectScanner::Error::Raise("can't be in both \"Action\" and \"FolderExclusion\" modes at the same time");
|
|
m_mode = ExcludeFolder;
|
|
do
|
|
{
|
|
Action action;
|
|
const char* val = XML.readAttribute("SearchPath");
|
|
if (val)
|
|
action.setSearchPath(val);
|
|
else
|
|
ProjectScanner::Error::Log("\"FolderExclusion\" tag must feature a \"SearchPath\" property");
|
|
|
|
val = XML.readAttribute("ExcludePath");
|
|
if (val)
|
|
action.setExcludePath(val);
|
|
else
|
|
ProjectScanner::Error::Log("\"FolderExclusion\" tag must feature a \"ExcludePath\" property");
|
|
action.compute();
|
|
m_actions.push_back(action);
|
|
} while (XML.nextSameElement());
|
|
}
|
|
if (XML.enterElement("Perforce"))
|
|
{
|
|
bUseP4 = TRUE;
|
|
|
|
const char* val ;
|
|
|
|
val = XML.readAttribute("Port");
|
|
memset(P4Port, 0, MAX_PATH);
|
|
if (val)
|
|
strcpy_s(P4Port, MAX_PATH-1, val);
|
|
|
|
val = XML.readAttribute("User");
|
|
memset(P4User, 0, MAX_PATH);
|
|
if (val)
|
|
strcpy_s(P4User, MAX_PATH-1, val);
|
|
|
|
val = XML.readAttribute("Password");
|
|
memset(P4Password, 0, MAX_PATH);
|
|
if (val)
|
|
strcpy_s(P4Password, MAX_PATH-1, val);
|
|
|
|
val = XML.readAttribute("Client");
|
|
memset(P4Client, 0, MAX_PATH);
|
|
if (val)
|
|
strcpy_s(P4Client, MAX_PATH-1, val);
|
|
|
|
val = XML.readAttribute("Cl");
|
|
memset(P4CL, 0, MAX_PATH);
|
|
if (val)
|
|
{
|
|
strcpy_s(P4CL, MAX_PATH-1, "-c");
|
|
strcat_s(P4CL, MAX_PATH-1, val);
|
|
}
|
|
|
|
XML.exitElement();
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
void writeTCHARtoChar(const TCHAR* _tcharPtr, char* _charPtr)
|
|
{
|
|
int readIndex = 0;
|
|
int writeIndex = 0;
|
|
while(_tcharPtr[readIndex])
|
|
{
|
|
_charPtr[writeIndex] = (char)_tcharPtr[readIndex];
|
|
writeIndex++;
|
|
readIndex++;
|
|
}
|
|
_charPtr[writeIndex] = 0;
|
|
}
|
|
|
|
void ConfigHandler::setExcludePathFromCmdLine(const _TCHAR* _where, const _TCHAR* _what, const _TCHAR* _output)
|
|
{
|
|
char buf[MAX_PATH];
|
|
writeTCHARtoChar(_output, outputFile);
|
|
writeTCHARtoChar(_where, dataPath);
|
|
writeTCHARtoChar(_where, buf);
|
|
m_mode = ExcludeFolder;
|
|
Action action;
|
|
action.setSearchPath(buf);
|
|
writeTCHARtoChar(_what, buf);
|
|
action.setExcludePath(buf);
|
|
action.compute();
|
|
m_actions.push_back(action);
|
|
}
|
|
|