/*
* px *
Copyright (c) 2008 Shawn Hladky
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "pxheaders.h"
#include "jobfiles_filesclientuser.h"
static const ErrorId fileInfo = {ErrorOf( ES_CLIENT, 0, E_INFO, EV_CLIENT, 5) , "%depotFile%#%rev% - %action% change %change% (%type%)" };
JobFiles_FilesClientUser::JobFiles_FilesClientUser(bool Tagged, bool Sumary, bool CaseSensitive, ClientUser* cu) : PassthroughClientUser(cu)
{
tagged = Tagged;
sumary = Sumary;
caseSensitive = CaseSensitive;
}
void JobFiles_FilesClientUser::OutputStat(StrDict *out)
{
//StrBuf shawn1;
//StrBuf shawn2;
//shawn1.Set("test");
//StrRef shawn1Val("shawn1");
//shawn2.Set("Test");
//StrRef shawn2Val("shawn2");
//StrOps::Lower(shawn2);
//if (shawn1 == shawn2) printf("equal \n");
//std::map<StrPtr, StrPtr*> myMap;
//myMap[shawn1] = &shawn1Val;
//myMap[shawn2] = &shawn2Val;
//printf("test1 %s\n", myMap[shawn1]->Text());
//printf("test2 %s\n", myMap[shawn2]->Text());
if (sumary)
{
// take a local copy of the StrDict
StrBufDict* myOut = new StrBufDict(*out);
outputDicts.Put((void*) myOut);
// take a local copy of the depot Filename
StrBuf* var = fileNames.Put();
var->Set(out->GetVar("depotFile"));
// StrRef var1, val1;
// // Dump out the variables, using the GetVar( x ) interface.
// // Don't display the function, which is only relevant to rpc.
// for(int i = 0; varList->GetVar( i, var1, val1 ); i++ )
// {
//printf("%s = %s\n", var1.Text(), val1.Text());
// }
if (!caseSensitive)
{
StrOps::Lower(*var);
//var->SetCaseFolding(StrPtr::CaseUse::ST_WINDOWS);
//printf("lower: %s\n", var->Text());
}
//// add or replace it in our map
//if (filesMap.count(var))
//{
// printf("you suck\n");
// filesMap.erase(var);
//}
//else
//{
// printf("you suck 2\n");
//}
filesMap[*var] = myOut;
}
else
{
outputDict(out);
}
}
void JobFiles_FilesClientUser::outputDict(StrDict *out)
{
if (tagged)
{
passthroughCU->OutputStat(out);
}
else
{
Error e;
e.Set(fileInfo);
e << out->GetVar("depotFile");
e << out->GetVar("rev");
e << out->GetVar("action");
e << out->GetVar("change");
e << out->GetVar("type");
passthroughCU->Message(&e);
}
}
void JobFiles_FilesClientUser::Finished()
{
for(std::map<StrPtr, StrDict*>::iterator it = filesMap.begin(); it != filesMap.end(); it++)
{
outputDict(it->second);
}
}
void JobFiles_FilesClientUser::Debug()
{
}