Support better 2GB+ file (cmdline & session file adaptation)

Some members (_line2go, _column2go and _pos2go) from the CmdLineParams & CmdLineParamsDTO structs need 'int' to 'intptr_t' change to support 2GB+ files.
Saving & loading of the 'session.xml' needs a 2GB+ adaptation too. The underlying TinyXML (older v1) does not have a native support for the 64-bit integers, so loading/writing there has been changed to strings instead of integers. This way is fully compatible with a possible future update to TinyXML-2 (which has already built-in support for the 64-bit integers).

Fix #11213, close #11258
This commit is contained in:
xomx 2022-02-21 18:11:28 +01:00 committed by Don Ho
parent 9c19bae7c9
commit ca8c302805
6 changed files with 78 additions and 79 deletions

View File

@ -6118,8 +6118,8 @@ std::vector<generic_string> Notepad_plus::loadCommandlineParams(const TCHAR * co
LangType lt = pCmdParams->_langType;
generic_string udl = pCmdParams->_udlName;
int lineNumber = pCmdParams->_line2go;
int columnNumber = pCmdParams->_column2go;
intptr_t lineNumber = pCmdParams->_line2go;
intptr_t columnNumber = pCmdParams->_column2go;
intptr_t positionNumber = pCmdParams->_pos2go;
bool recursive = pCmdParams->_isRecursive;
bool readOnly = pCmdParams->_isReadOnly;

View File

@ -2175,43 +2175,42 @@ bool NppParameters::getSessionFromXmlTree(TiXmlDocument *pSessionDoc, Session& s
if (fileName)
{
Position position;
(childNode->ToElement())->Attribute(TEXT("firstVisibleLine"), reinterpret_cast<int*>(&position._firstVisibleLine));
(childNode->ToElement())->Attribute(TEXT("xOffset"), reinterpret_cast<int*>(&position._xOffset));
(childNode->ToElement())->Attribute(TEXT("startPos"), reinterpret_cast<int*>(&position._startPos));
(childNode->ToElement())->Attribute(TEXT("endPos"), reinterpret_cast<int*>(&position._endPos));
(childNode->ToElement())->Attribute(TEXT("selMode"), reinterpret_cast<int*>(&position._selMode));
(childNode->ToElement())->Attribute(TEXT("scrollWidth"), reinterpret_cast<int*>(&position._scrollWidth));
(childNode->ToElement())->Attribute(TEXT("offset"), reinterpret_cast<int*>(&position._offset));
(childNode->ToElement())->Attribute(TEXT("wrapCount"), reinterpret_cast<int*>(&position._wrapCount));
position._firstVisibleLine = static_cast<intptr_t>(_ttoi64((childNode->ToElement())->Attribute(TEXT("firstVisibleLine"))));
position._xOffset = static_cast<intptr_t>(_ttoi64((childNode->ToElement())->Attribute(TEXT("xOffset"))));
position._startPos = static_cast<intptr_t>(_ttoi64((childNode->ToElement())->Attribute(TEXT("startPos"))));
position._endPos = static_cast<intptr_t>(_ttoi64((childNode->ToElement())->Attribute(TEXT("endPos"))));
position._selMode = static_cast<intptr_t>(_ttoi64((childNode->ToElement())->Attribute(TEXT("selMode"))));
position._scrollWidth = static_cast<intptr_t>(_ttoi64((childNode->ToElement())->Attribute(TEXT("scrollWidth"))));
position._offset = static_cast<intptr_t>(_ttoi64((childNode->ToElement())->Attribute(TEXT("offset"))));
position._wrapCount = static_cast<intptr_t>(_ttoi64((childNode->ToElement())->Attribute(TEXT("wrapCount"))));
MapPosition mapPosition;
int32_t mapPosVal;
const TCHAR *mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapFirstVisibleDisplayLine"), &mapPosVal);
const TCHAR* mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapFirstVisibleDisplayLine"));
if (mapPosStr)
mapPosition._firstVisibleDisplayLine = mapPosVal;
mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapFirstVisibleDocLine"), &mapPosVal);
mapPosition._firstVisibleDisplayLine = static_cast<intptr_t>(_ttoi64(mapPosStr));
mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapFirstVisibleDocLine"));
if (mapPosStr)
mapPosition._firstVisibleDocLine = mapPosVal;
mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapLastVisibleDocLine"), &mapPosVal);
mapPosition._firstVisibleDocLine = static_cast<intptr_t>(_ttoi64(mapPosStr));
mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapLastVisibleDocLine"));
if (mapPosStr)
mapPosition._lastVisibleDocLine = mapPosVal;
mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapNbLine"), &mapPosVal);
mapPosition._lastVisibleDocLine = static_cast<intptr_t>(_ttoi64(mapPosStr));
mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapNbLine"));
if (mapPosStr)
mapPosition._nbLine = mapPosVal;
mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapHigherPos"), &mapPosVal);
mapPosition._nbLine = static_cast<intptr_t>(_ttoi64(mapPosStr));
mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapHigherPos"));
if (mapPosStr)
mapPosition._higherPos = mapPosVal;
mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapWidth"), &mapPosVal);
mapPosition._higherPos = static_cast<intptr_t>(_ttoi64(mapPosStr));
mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapWidth"));
if (mapPosStr)
mapPosition._width = mapPosVal;
mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapHeight"), &mapPosVal);
mapPosition._width = static_cast<intptr_t>(_ttoi64(mapPosStr));
mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapHeight"));
if (mapPosStr)
mapPosition._height = mapPosVal;
mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapKByteInDoc"), &mapPosVal);
mapPosition._height = static_cast<intptr_t>(_ttoi64(mapPosStr));
mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapKByteInDoc"));
if (mapPosStr)
mapPosition._KByteInDoc = mapPosVal;
mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapWrapIndentMode"), &mapPosVal);
mapPosition._KByteInDoc = static_cast<intptr_t>(_ttoi64(mapPosStr));
mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapWrapIndentMode"));
if (mapPosStr)
mapPosition._wrapIndentMode = mapPosVal;
mapPosition._wrapIndentMode = static_cast<intptr_t>(_ttoi64(mapPosStr));
const TCHAR *boolStr = (childNode->ToElement())->Attribute(TEXT("mapIsWrap"));
if (boolStr)
mapPosition._isWrap = (lstrcmp(TEXT("yes"), boolStr) == 0);
@ -2234,26 +2233,24 @@ bool NppParameters::getSessionFromXmlTree(TiXmlDocument *pSessionDoc, Session& s
sessionFileInfo sfi(fileName, langName, encStr ? encoding : -1, isUserReadOnly, position, backupFilePath, fileModifiedTimestamp, mapPosition);
for (TiXmlNode *markNode = childNode->FirstChildElement(TEXT("Mark"));
markNode ;
markNode;
markNode = markNode->NextSibling(TEXT("Mark")))
{
int lineNumber;
const TCHAR *lineNumberStr = (markNode->ToElement())->Attribute(TEXT("line"), &lineNumber);
const TCHAR* lineNumberStr = (markNode->ToElement())->Attribute(TEXT("line"));
if (lineNumberStr)
{
sfi._marks.push_back(lineNumber);
sfi._marks.push_back(static_cast<size_t>(_ttoi64(lineNumberStr)));
}
}
for (TiXmlNode *foldNode = childNode->FirstChildElement(TEXT("Fold"));
foldNode ;
foldNode;
foldNode = foldNode->NextSibling(TEXT("Fold")))
{
int lineNumber;
const TCHAR *lineNumberStr = (foldNode->ToElement())->Attribute(TEXT("line"), &lineNumber);
const TCHAR *lineNumberStr = (foldNode->ToElement())->Attribute(TEXT("line"));
if (lineNumberStr)
{
sfi._foldStates.push_back(lineNumber);
sfi._foldStates.push_back(static_cast<size_t>(_ttoi64(lineNumberStr)));
}
}
if (k == 0)
@ -3286,14 +3283,16 @@ void NppParameters::writeSession(const Session & session, const TCHAR *fileName)
{
TiXmlNode *fileNameNode = viewElems[k].viewNode->InsertEndChild(TiXmlElement(TEXT("File")));
(fileNameNode->ToElement())->SetAttribute(TEXT("firstVisibleLine"), static_cast<int>(viewSessionFiles[i]._firstVisibleLine));
(fileNameNode->ToElement())->SetAttribute(TEXT("xOffset"), static_cast<int>(viewSessionFiles[i]._xOffset));
(fileNameNode->ToElement())->SetAttribute(TEXT("scrollWidth"), static_cast<int>(viewSessionFiles[i]._scrollWidth));
(fileNameNode->ToElement())->SetAttribute(TEXT("startPos"), static_cast<int>(viewSessionFiles[i]._startPos));
(fileNameNode->ToElement())->SetAttribute(TEXT("endPos"), static_cast<int>(viewSessionFiles[i]._endPos));
(fileNameNode->ToElement())->SetAttribute(TEXT("selMode"), static_cast<int>(viewSessionFiles[i]._selMode));
(fileNameNode->ToElement())->SetAttribute(TEXT("offset"), static_cast<int>(viewSessionFiles[i]._offset));
(fileNameNode->ToElement())->SetAttribute(TEXT("wrapCount"), static_cast<int>(viewSessionFiles[i]._wrapCount));
TCHAR szInt64[64];
(fileNameNode->ToElement())->SetAttribute(TEXT("firstVisibleLine"), _i64tot(static_cast<LONGLONG>(viewSessionFiles[i]._firstVisibleLine), szInt64, 10));
(fileNameNode->ToElement())->SetAttribute(TEXT("xOffset"), _i64tot(static_cast<LONGLONG>(viewSessionFiles[i]._xOffset), szInt64, 10));
(fileNameNode->ToElement())->SetAttribute(TEXT("scrollWidth"), _i64tot(static_cast<LONGLONG>(viewSessionFiles[i]._scrollWidth), szInt64, 10));
(fileNameNode->ToElement())->SetAttribute(TEXT("startPos"), _i64tot(static_cast<LONGLONG>(viewSessionFiles[i]._startPos), szInt64, 10));
(fileNameNode->ToElement())->SetAttribute(TEXT("endPos"), _i64tot(static_cast<LONGLONG>(viewSessionFiles[i]._endPos), szInt64, 10));
(fileNameNode->ToElement())->SetAttribute(TEXT("selMode"), _i64tot(static_cast<LONGLONG>(viewSessionFiles[i]._selMode), szInt64, 10));
(fileNameNode->ToElement())->SetAttribute(TEXT("offset"), _i64tot(static_cast<LONGLONG>(viewSessionFiles[i]._offset), szInt64, 10));
(fileNameNode->ToElement())->SetAttribute(TEXT("wrapCount"), _i64tot(static_cast<LONGLONG>(viewSessionFiles[i]._wrapCount), szInt64, 10));
(fileNameNode->ToElement())->SetAttribute(TEXT("lang"), viewSessionFiles[i]._langName.c_str());
(fileNameNode->ToElement())->SetAttribute(TEXT("encoding"), viewSessionFiles[i]._encoding);
(fileNameNode->ToElement())->SetAttribute(TEXT("userReadOnly"), (viewSessionFiles[i]._isUserReadOnly && !viewSessionFiles[i]._isMonitoring) ? TEXT("yes") : TEXT("no"));
@ -3301,31 +3300,31 @@ void NppParameters::writeSession(const Session & session, const TCHAR *fileName)
(fileNameNode->ToElement())->SetAttribute(TEXT("backupFilePath"), viewSessionFiles[i]._backupFilePath.c_str());
(fileNameNode->ToElement())->SetAttribute(TEXT("originalFileLastModifTimestamp"), static_cast<int32_t>(viewSessionFiles[i]._originalFileLastModifTimestamp.dwLowDateTime));
(fileNameNode->ToElement())->SetAttribute(TEXT("originalFileLastModifTimestampHigh"), static_cast<int32_t>(viewSessionFiles[i]._originalFileLastModifTimestamp.dwHighDateTime));
// docMap
(fileNameNode->ToElement())->SetAttribute(TEXT("mapFirstVisibleDisplayLine"), (int)viewSessionFiles[i]._mapPos._firstVisibleDisplayLine);
(fileNameNode->ToElement())->SetAttribute(TEXT("mapFirstVisibleDocLine"), (int)viewSessionFiles[i]._mapPos._firstVisibleDocLine);
(fileNameNode->ToElement())->SetAttribute(TEXT("mapLastVisibleDocLine"), (int)viewSessionFiles[i]._mapPos._lastVisibleDocLine);
(fileNameNode->ToElement())->SetAttribute(TEXT("mapNbLine"), (int)viewSessionFiles[i]._mapPos._nbLine);
(fileNameNode->ToElement())->SetAttribute(TEXT("mapHigherPos"), (int)viewSessionFiles[i]._mapPos._higherPos);
(fileNameNode->ToElement())->SetAttribute(TEXT("mapWidth"), (int)viewSessionFiles[i]._mapPos._width);
(fileNameNode->ToElement())->SetAttribute(TEXT("mapHeight"), (int)viewSessionFiles[i]._mapPos._height);
(fileNameNode->ToElement())->SetAttribute(TEXT("mapKByteInDoc"), (int)viewSessionFiles[i]._mapPos._KByteInDoc);
(fileNameNode->ToElement())->SetAttribute(TEXT("mapWrapIndentMode"), (int)viewSessionFiles[i]._mapPos._wrapIndentMode);
(fileNameNode->ToElement())->SetAttribute(TEXT("mapFirstVisibleDisplayLine"), _i64tot(static_cast<LONGLONG>(viewSessionFiles[i]._mapPos._firstVisibleDisplayLine), szInt64, 10));
(fileNameNode->ToElement())->SetAttribute(TEXT("mapFirstVisibleDocLine"), _i64tot(static_cast<LONGLONG>(viewSessionFiles[i]._mapPos._firstVisibleDocLine), szInt64, 10));
(fileNameNode->ToElement())->SetAttribute(TEXT("mapLastVisibleDocLine"), _i64tot(static_cast<LONGLONG>(viewSessionFiles[i]._mapPos._lastVisibleDocLine), szInt64, 10));
(fileNameNode->ToElement())->SetAttribute(TEXT("mapNbLine"), _i64tot(static_cast<LONGLONG>(viewSessionFiles[i]._mapPos._nbLine), szInt64, 10));
(fileNameNode->ToElement())->SetAttribute(TEXT("mapHigherPos"), _i64tot(static_cast<LONGLONG>(viewSessionFiles[i]._mapPos._higherPos), szInt64, 10));
(fileNameNode->ToElement())->SetAttribute(TEXT("mapWidth"), _i64tot(static_cast<LONGLONG>(viewSessionFiles[i]._mapPos._width), szInt64, 10));
(fileNameNode->ToElement())->SetAttribute(TEXT("mapHeight"), _i64tot(static_cast<LONGLONG>(viewSessionFiles[i]._mapPos._height), szInt64, 10));
(fileNameNode->ToElement())->SetAttribute(TEXT("mapKByteInDoc"), _i64tot(static_cast<LONGLONG>(viewSessionFiles[i]._mapPos._KByteInDoc), szInt64, 10));
(fileNameNode->ToElement())->SetAttribute(TEXT("mapWrapIndentMode"), _i64tot(static_cast<LONGLONG>(viewSessionFiles[i]._mapPos._wrapIndentMode), szInt64, 10));
fileNameNode->ToElement()->SetAttribute(TEXT("mapIsWrap"), viewSessionFiles[i]._mapPos._isWrap ? TEXT("yes") : TEXT("no"));
for (size_t j = 0, len = viewSessionFiles[i]._marks.size() ; j < len ; ++j)
{
size_t markLine = viewSessionFiles[i]._marks[j];
TiXmlNode *markNode = fileNameNode->InsertEndChild(TiXmlElement(TEXT("Mark")));
markNode->ToElement()->SetAttribute(TEXT("line"), static_cast<int32_t>(markLine));
markNode->ToElement()->SetAttribute(TEXT("line"), _ui64tot(static_cast<ULONGLONG>(markLine), szInt64, 10));
}
for (size_t j = 0, len = viewSessionFiles[i]._foldStates.size() ; j < len ; ++j)
{
size_t foldLine = viewSessionFiles[i]._foldStates[j];
TiXmlNode *foldNode = fileNameNode->InsertEndChild(TiXmlElement(TEXT("Fold")));
foldNode->ToElement()->SetAttribute(TEXT("line"), static_cast<int32_t>(foldLine));
foldNode->ToElement()->SetAttribute(TEXT("line"), _ui64tot(static_cast<ULONGLONG>(foldLine), szInt64, 10));
}
}
}

View File

@ -143,14 +143,14 @@ void cutString(const TCHAR *str2cut, std::vector<generic_string> & patternVect);
struct Position
{
size_t _firstVisibleLine = 0;
size_t _startPos = 0;
size_t _endPos = 0;
size_t _xOffset = 0;
size_t _selMode = 0;
size_t _scrollWidth = 1;
size_t _offset = 0;
size_t _wrapCount = 0;
intptr_t _firstVisibleLine = 0;
intptr_t _startPos = 0;
intptr_t _endPos = 0;
intptr_t _xOffset = 0;
intptr_t _selMode = 0;
intptr_t _scrollWidth = 1;
intptr_t _offset = 0;
intptr_t _wrapCount = 0;
};
@ -228,9 +228,9 @@ struct CmdLineParams
bool _isPreLaunch = false;
bool _showLoadingTime = false;
bool _alwaysOnTop = false;
int _line2go = -1;
int _column2go = -1;
int _pos2go = -1;
intptr_t _line2go = -1;
intptr_t _column2go = -1;
intptr_t _pos2go = -1;
POINT _point = {};
bool _isPointXValid = false;
@ -269,9 +269,9 @@ struct CmdLineParamsDTO
bool _isRecursive = false;
bool _openFoldersAsWorkspace = false;
int _line2go = 0;
int _column2go = 0;
int _pos2go = 0;
intptr_t _line2go = 0;
intptr_t _column2go = 0;
intptr_t _pos2go = 0;
LangType _langType = L_EXTERNAL;
generic_string _udlName;

View File

@ -1839,8 +1839,8 @@ void ScintillaEditView::restoreCurrentPosPostStep()
return;
}
size_t displayedLine = execute(SCI_GETFIRSTVISIBLELINE);
size_t docLine = execute(SCI_DOCLINEFROMVISIBLE, displayedLine); //linenumber of the line displayed in the
intptr_t displayedLine = execute(SCI_GETFIRSTVISIBLELINE);
intptr_t docLine = execute(SCI_DOCLINEFROMVISIBLE, displayedLine); //linenumber of the line displayed in the
// check docLine must equals saved position
@ -1855,7 +1855,7 @@ void ScintillaEditView::restoreCurrentPosPostStep()
{
// don't scroll anything if the wrap count is different than the saved one.
// Buffer update may be in progress (in case wrap is enabled)
size_t wrapCount = execute(SCI_WRAPCOUNT, docLine);
intptr_t wrapCount = execute(SCI_WRAPCOUNT, docLine);
if (wrapCount == pos._wrapCount)
{
scroll(0, pos._offset);

View File

@ -408,7 +408,7 @@ public:
execute(SCI_SETXOFFSET,xOffset);
};
void scroll(size_t column, size_t line){
void scroll(intptr_t column, intptr_t line){
execute(SCI_LINESCROLL, column, line);
};

View File

@ -238,7 +238,7 @@ generic_string getLocalizationPathFromParam(ParamVector & params)
return NppParameters::getLocPathFromStr(locStr.c_str());
}
int getNumberFromParam(char paramName, ParamVector & params, bool & isParamePresent)
intptr_t getNumberFromParam(char paramName, ParamVector & params, bool & isParamePresent)
{
generic_string numStr;
if (!getParamVal(paramName, params, numStr))
@ -247,7 +247,7 @@ int getNumberFromParam(char paramName, ParamVector & params, bool & isParamePres
return -1;
}
isParamePresent = true;
return generic_atoi(numStr.c_str());
return static_cast<intptr_t>(_ttoi64(numStr.c_str()));
};
generic_string getEasterEggNameFromParam(ParamVector & params, unsigned char & type)
@ -453,8 +453,8 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int)
cmdLineParams._line2go = getNumberFromParam('n', params, isParamePresent);
cmdLineParams._column2go = getNumberFromParam('c', params, isParamePresent);
cmdLineParams._pos2go = getNumberFromParam('p', params, isParamePresent);
cmdLineParams._point.x = getNumberFromParam('x', params, cmdLineParams._isPointXValid);
cmdLineParams._point.y = getNumberFromParam('y', params, cmdLineParams._isPointYValid);
cmdLineParams._point.x = static_cast<LONG>(getNumberFromParam('x', params, cmdLineParams._isPointXValid));
cmdLineParams._point.y = static_cast<LONG>(getNumberFromParam('y', params, cmdLineParams._isPointYValid));
NppParameters& nppParameters = NppParameters::getInstance();