// Unpacking the file here, save the result in a temporary file
m_strTempFileName = pszFileNameInit;
- if (!FileTransform::Unpacking(infoUnpacker, m_strTempFileName, sToFindUnpacker))
+ if (!FileTransform::Unpacking(infoUnpacker, &m_unpackerSubcode, m_strTempFileName, sToFindUnpacker))
{
InitNew(); // leave crystal editor in valid, empty state
return FileLoadResult::FRESULT_ERROR_UNPACK;
}
- m_unpackerSubcode = infoUnpacker->m_subcode;
// we use the same unpacker for both files, so it must be defined after first file
ASSERT(infoUnpacker->m_PluginOrPredifferMode != PLUGIN_MODE::PLUGIN_AUTO);
// we need an unpacker/packer, at least a "do nothing" one
ASSERT(infoUnpacker != nullptr);
// repack the file here, overwrite the temporary file we did save in
- String csTempFileName = sIntermediateFilename;
- infoUnpacker->m_subcode = m_unpackerSubcode;
- if (!FileTransform::Packing(csTempFileName, *infoUnpacker))
+ bSaveSuccess = FileTransform::Packing(sIntermediateFilename, pszFileName, *infoUnpacker, m_unpackerSubcode);
+ try
{
- try
- {
- TFile(sIntermediateFilename).remove();
- }
- catch (Exception& e)
- {
- LogErrorStringUTF8(e.displayText());
- }
- // returns now, don't overwrite the original file
- return SAVE_PACK_FAILED;
+ TFile(sIntermediateFilename).remove();
}
- // the temp filename may have changed during packing
- if (csTempFileName != sIntermediateFilename)
+ catch (Exception& e)
{
- try
- {
- TFile(sIntermediateFilename).remove();
- }
- catch (Exception& e)
- {
- LogErrorStringUTF8(e.displayText());
- }
- sIntermediateFilename = csTempFileName;
+ LogErrorStringUTF8(e.displayText());
}
-
- // Write tempfile over original file
- try
+ if (!bSaveSuccess)
{
- TFile file1(sIntermediateFilename);
- file1.copyTo(pszFileName);
- file1.remove();
- if (bClearModifiedFlag)
- {
- SetModified(false);
- m_nSyncPosition = m_nUndoPosition;
- }
- bSaveSuccess = true;
-
- // remember revision number on save
- m_dwRevisionNumberOnSave = m_dwCurrentRevisionNumber;
-
- // redraw line revision marks
- UpdateViews (nullptr, nullptr, UPDATE_FLAGSONLY);
+ // returns now, don't overwrite the original file
+ return SAVE_PACK_FAILED;
}
- catch (Exception& e)
+
+ if (bClearModifiedFlag)
{
- LogErrorStringUTF8(e.displayText());
+ SetModified(false);
+ m_nSyncPosition = m_nUndoPosition;
}
+
+ // remember revision number on save
+ m_dwRevisionNumberOnSave = m_dwCurrentRevisionNumber;
+
+ // redraw line revision marks
+ UpdateViews (nullptr, nullptr, UPDATE_FLAGSONLY);
}
else
{
}
// known handler
-bool Packing(String & filepath, PackingInfo handler)
+bool Packing(String & filepath, const PackingInfo& handler, int handlerSubcode)
{
// no handler : return true
if (handler.m_PluginName.empty())
bHandled = plugin::InvokePackFile(srcFileName,
dstFileName,
bufferData.GetNChanged(),
- piScript, handler.m_subcode);
+ piScript, handlerSubcode);
if (bHandled)
bufferData.ValidateNewFile();
}
{
bHandled = plugin::InvokePackBuffer(*bufferData.GetDataBufferAnsi(),
bufferData.GetNChanged(),
- piScript, handler.m_subcode);
+ piScript, handlerSubcode);
if (bHandled)
bufferData.ValidateNewBuffer();
}
return bSuccess;
}
+bool Packing(const String& srcFilepath, const String& dstFilepath, const PackingInfo& handler, int handlerSubcode)
+{
+ String csTempFileName = srcFilepath;
+ if (!Packing(csTempFileName, handler, handlerSubcode))
+ return false;
+ try
+ {
+ TFile file1(csTempFileName);
+ file1.copyTo(dstFilepath);
+ if (srcFilepath!= csTempFileName)
+ file1.remove();
+ return true;
+ }
+ catch (Poco::Exception& e)
+ {
+ LogErrorStringUTF8(e.displayText());
+ return false;
+ }
+}
+
// known handler
bool Unpacking(String & filepath, const PackingInfo * handler, int * handlerSubcode)
{
return false;
// valid the subcode
- *handlerSubcode = subcode;
+ if (handlerSubcode)
+ *handlerSubcode = subcode;
// if the buffer changed, write it before leaving
bool bSuccess = true;
storageForPlugins bufferData;
bufferData.SetDataFileAnsi(filepath);
+ // temporary subcode
+ int subcode = 0;
// control value
bool bHandled = false;
bHandled = plugin::InvokeUnpackFile(srcFileName,
dstFileName,
bufferData.GetNChanged(),
- plugin->m_lpDispatch, handler->m_subcode);
+ plugin->m_lpDispatch, subcode);
if (bHandled)
bufferData.ValidateNewFile();
}
handler->m_PluginName = plugin->m_name;
bHandled = plugin::InvokeUnpackBuffer(*bufferData.GetDataBufferAnsi(),
bufferData.GetNChanged(),
- plugin->m_lpDispatch, handler->m_subcode);
+ plugin->m_lpDispatch, subcode);
if (bHandled)
bufferData.ValidateNewBuffer();
}
{
// we didn't find any unpacker, just hope it is normal Ansi/Unicode
handler->m_PluginName = _T("");
- handler->m_subcode = 0;
+ subcode = 0;
bHandled = true;
}
handler->m_PluginOrPredifferMode = PLUGIN_MODE::PLUGIN_MANUAL;
// assign the sucode
- *handlerSubcode = handler->m_subcode;
+ if (handlerSubcode)
+ *handlerSubcode = subcode;
// if the buffer changed, write it before leaving
bool bSuccess = true;
return bSuccess;
}
-bool Unpacking(PackingInfo *handler, String& filepath, const String& filteredText)
+bool Unpacking(PackingInfo *handler, int * handlerSubcode, String& filepath, const String& filteredText)
{
if (handler->m_PluginOrPredifferMode != PLUGIN_MODE::PLUGIN_MANUAL)
- return Unpacking(filepath, filteredText, handler, &handler->m_subcode);
+ return Unpacking(filepath, filteredText, handler, handlerSubcode);
else
- return Unpacking(filepath, handler, &handler->m_subcode);
+ return Unpacking(filepath, handler, handlerSubcode);
}
////////////////////////////////////////////////////////////////////////////////
public:
explicit PackingInfo(PLUGIN_MODE Mode = FileTransform::g_UnpackerMode)
: PluginForFile(Mode)
- , m_subcode(0)
, m_pufile(nullptr)
, m_bDisallowMixedEOL(false)
{
}
public:
- /// keep some info from unpacking for packing
- int m_subcode;
/// text type to override syntax highlighting
String m_textType;
/// custom UniFile
*/
bool Unpacking(String & filepath, const PackingInfo * handler, int * handlerSubcode);
-bool Unpacking(PackingInfo * handler, String & filepath, const String& filteredText);
+bool Unpacking(PackingInfo * handler, int * handlerSubcode, String & filepath, const String& filteredText);
/**
* @brief Prepare one file for saving, known handler
* @note Event FILE_PACK
* Never do Unicode conversion, it was done in SaveFromFile
*/
-bool Packing(String & filepath, PackingInfo handler);
+bool Packing(String & filepath, const PackingInfo& handler, int handlerSubcode);
+
+bool Packing(const String& srcFilepath, const String& dstFilepath, const PackingInfo& handler, int handlerSubcode);
/**
* @brief Prepare one file for diffing, scan all available plugins (events+filename filtering)
// Invoke unpacking plugins
if (infoUnpacker && strutils::compare_nocase(filepathUnpacked[nIndex], _T("NUL")) != 0)
{
- if (!FileTransform::Unpacking(infoUnpacker, filepathUnpacked[nIndex], filteredFilenames))
+ if (!FileTransform::Unpacking(infoUnpacker, nullptr, filepathUnpacked[nIndex], filteredFilenames))
goto exitPrepAndCompare;
// we use the same plugins for both files, so they must be defined before second file
return E_FAIL;
paths::CreateIfNeeded(path);
int nChanged = 0;
- return plugin::InvokeUnpackFolder(path, folder, nChanged, m_plugin->m_lpDispatch, m_infoUnpacker.m_subcode) ? S_OK : E_FAIL;
+ int subcode = 0;
+ return plugin::InvokeUnpackFolder(path, folder, nChanged, m_plugin->m_lpDispatch, subcode) ? S_OK : E_FAIL;
}
HRESULT Merge7zFormatMergePluginImpl::CompressArchive(HWND, LPCTSTR path, Merge7z::DirItemEnumerator *)
PrediffingInfo *ip = nullptr;
PluginManager pm;
IPluginInfos *ppi = ±
+ int subcode = 0;
ppi->FetchPluginInfos(_T("../../Data/Office/excel.xls|../../Data/Office/excel.xls"), &iu, &ip);
String file = paths::ConcatPath(oldModulePath, _T("..\\..\\Data\\Office\\excel.xls"));
- FileTransform::Unpacking(file, _T(".*\\.xls"), iu, &iu->m_subcode);
+ FileTransform::Unpacking(file, _T(".*\\.xls"), iu, &subcode);
}
} // namespace