2006-10-28 19:45:02 +00:00
|
|
|
/*
|
|
|
|
* ShConstants.cpp
|
|
|
|
*
|
|
|
|
* This file is a part of NSIS.
|
|
|
|
*
|
2021-01-01 20:27:52 +00:00
|
|
|
* Copyright (C) 1999-2021 Nullsoft and Contributors
|
2006-10-28 19:45:02 +00:00
|
|
|
*
|
|
|
|
* Licensed under the zlib/libpng license (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
*
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* This software is provided 'as-is', without any express or implied
|
|
|
|
* warranty.
|
2010-03-24 17:22:56 +00:00
|
|
|
*
|
|
|
|
* Unicode support by Jim Park -- 08/24/2007
|
2006-10-28 19:45:02 +00:00
|
|
|
*/
|
|
|
|
|
2004-10-12 21:05:59 +00:00
|
|
|
#include "ShConstants.h"
|
|
|
|
|
|
|
|
ConstantsStringList::ConstantsStringList()
|
|
|
|
{
|
2010-04-13 15:19:12 +00:00
|
|
|
m_index = 0;
|
2004-10-12 21:05:59 +00:00
|
|
|
}
|
|
|
|
|
2010-03-24 17:22:56 +00:00
|
|
|
int ConstantsStringList::add(const TCHAR *name, int value1, int value2)
|
2004-10-12 21:05:59 +00:00
|
|
|
{
|
|
|
|
int pos=SortedStringListND<struct constantstring>::add(name);
|
|
|
|
if (pos == -1) return -1;
|
|
|
|
|
2010-04-14 10:15:40 +00:00
|
|
|
constantstring *ptr = ((constantstring*) m_gr.get()) + pos;
|
|
|
|
ptr->index = m_index;
|
|
|
|
ptr->pos = pos;
|
|
|
|
ptr->value1 = value1;
|
|
|
|
ptr->value2 = value2;
|
2004-10-12 21:05:59 +00:00
|
|
|
|
2010-04-13 15:19:12 +00:00
|
|
|
int temp = m_index;
|
|
|
|
m_index++;
|
2004-10-12 21:05:59 +00:00
|
|
|
|
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
2014-05-20 17:26:33 +00:00
|
|
|
int ConstantsStringList::get(const TCHAR *name, int n_chars /*= -1*/)
|
2004-10-12 21:05:59 +00:00
|
|
|
{
|
|
|
|
int v=SortedStringListND<struct constantstring>::find(name, n_chars);
|
|
|
|
if (v==-1) return -1;
|
2010-04-13 15:19:12 +00:00
|
|
|
return (((struct constantstring*) m_gr.get())[v].index);
|
2004-10-12 21:05:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ConstantsStringList::getnum()
|
|
|
|
{
|
2010-04-13 15:19:12 +00:00
|
|
|
return m_index;
|
2004-10-12 21:05:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ConstantsStringList::get_value1(int idx)
|
|
|
|
{
|
|
|
|
int pos=get_internal_idx(idx);
|
|
|
|
if (pos==-1) return -1;
|
2010-04-13 15:19:12 +00:00
|
|
|
return (((struct constantstring*) m_gr.get())[pos].value1);
|
2004-10-12 21:05:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ConstantsStringList::get_value2(int idx)
|
|
|
|
{
|
|
|
|
int pos=get_internal_idx(idx);
|
|
|
|
if (pos==-1) return -1;
|
2010-04-13 15:19:12 +00:00
|
|
|
return (((struct constantstring*) m_gr.get())[pos].value2);
|
2004-10-12 21:05:59 +00:00
|
|
|
}
|
|
|
|
|
2010-03-24 17:22:56 +00:00
|
|
|
TCHAR* ConstantsStringList::idx2name(int idx)
|
2004-10-12 21:05:59 +00:00
|
|
|
{
|
|
|
|
int pos=get_internal_idx(idx);
|
|
|
|
if (pos==-1) return NULL;
|
2010-04-13 15:19:12 +00:00
|
|
|
struct constantstring *data=(struct constantstring *) m_gr.get();
|
|
|
|
return ((TCHAR*) m_strings.get() + data[pos].name);
|
2004-10-12 21:05:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int ConstantsStringList::get_internal_idx(int idx)
|
|
|
|
{
|
2010-04-13 15:19:12 +00:00
|
|
|
struct constantstring *data=(struct constantstring *) m_gr.get();
|
2010-03-29 14:24:47 +00:00
|
|
|
|
|
|
|
// We do a linear search because the strings are sorted.
|
2010-04-13 15:19:12 +00:00
|
|
|
for (int i = 0; i < m_index; i++)
|
2004-10-12 21:05:59 +00:00
|
|
|
{
|
|
|
|
if (data[i].index == idx)
|
|
|
|
{
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2013-03-07 21:25:35 +00:00
|
|
|
|
|
|
|
bool ConstantsStringList::set_values(const TCHAR *name, int val1, int val2)
|
|
|
|
{
|
|
|
|
int v = SortedStringListND<struct constantstring>::find(name, -1);
|
|
|
|
if (-1 == v) return false;
|
|
|
|
|
|
|
|
struct constantstring & cs = ((struct constantstring*) m_gr.get())[v];
|
|
|
|
cs.value1 = val1;
|
|
|
|
cs.value2 = val2;
|
|
|
|
return true;
|
|
|
|
}
|