1 /////////////////////////////////////////////////////////////////////////////
2 // WinMerge: an interactive diff/merge utility
3 // Copyright (C) 1997-2000 Thingamahoochie Software
5 // SPDX-License-Identifier: GPL-2.0-or-later
6 /////////////////////////////////////////////////////////////////////////////
8 * @file FileTransform.h
10 * @brief Declaration of file transformations
15 #include "UnicodeString.h"
19 * @brief Modes for plugin (Modes for prediffing included)
21 enum class PLUGIN_MODE
23 // Modes for "unpacking"
28 // Modes for "prediffing"
29 PREDIFF_MANUAL = PLUGIN_MANUAL,
30 PREDIFF_AUTO = PLUGIN_AUTO,
33 namespace FileTransform
35 extern PLUGIN_MODE g_UnpackerMode;
36 extern PLUGIN_MODE g_PredifferMode;
42 * @brief Plugin information for a given file
44 * @note Can be be passed/copied between threads
49 void Initialize(PLUGIN_MODE Mode)
51 // and init Plugin/Prediffer mode and Plugin name accordingly
52 m_PluginOrPredifferMode = Mode;
53 if (Mode != PLUGIN_MODE::PLUGIN_AUTO)
59 m_PluginName = _("<Automatic>");
62 explicit PluginForFile(PLUGIN_MODE Mode)
67 /// PLUGIN_AUTO if the plugin will be defined during the first use (via scan of all available plugins)
68 PLUGIN_MODE m_PluginOrPredifferMode;
70 /// plugin name when it is defined
75 * @brief Unpacking/packing information for a given file
77 * @note Can be be copied between threads
78 * Each thread really needs its own instance so that subcode is really defined
79 * during the unpacking (open file) of the thread
81 class PackingInfo : public PluginForFile
84 explicit PackingInfo(PLUGIN_MODE Mode = FileTransform::g_UnpackerMode)
87 , m_bDisallowMixedEOL(false)
91 /// text type to override syntax highlighting
95 bool m_bDisallowMixedEOL;
99 * @brief Prediffing information for a given file
101 * @note Can be be passed/copied between threads
103 class PrediffingInfo : public PluginForFile
106 explicit PrediffingInfo(PLUGIN_MODE Mode = FileTransform::g_PredifferMode)
107 : PluginForFile(Mode)
112 namespace FileTransform
116 // WinMerge uses one of these entry points to call a plugin
118 // bMayOverwrite : tells if we can overwrite the source file
119 // if we don't, don't forget do delete the temp file after use
122 * @brief Prepare one file for loading, scan all available plugins (events+filename filtering)
124 * @param filepath : [in, out] Most plugins change this filename
125 * @param handler : unpacking handler, to keep to pack again
127 * @return Tells if WinMerge handles this file
129 * @note Event FILE_UNPACK
130 * Apply only the first correct handler
132 bool Unpacking(String & filepath, const String& filteredText, PackingInfo * handler, int * handlerSubcode);
134 * @brief Prepare one file for loading, known handler
136 * @param filepath : [in, out] Most plugins change this filename
138 bool Unpacking(String & filepath, const PackingInfo * handler, int * handlerSubcode);
140 bool Unpacking(PackingInfo * handler, int * handlerSubcode, String & filepath, const String& filteredText);
143 * @brief Prepare one file for saving, known handler
145 * @return Tells if we can save the file (really hope we can)
147 * @param filepath : [in, out] Most plugins change this filename
149 * @note Event FILE_PACK
150 * Never do Unicode conversion, it was done in SaveFromFile
152 bool Packing(String & filepath, const PackingInfo& handler, int handlerSubcode);
154 bool Packing(const String& srcFilepath, const String& dstFilepath, const PackingInfo& handler, int handlerSubcode);
157 * @brief Prepare one file for diffing, scan all available plugins (events+filename filtering)
159 * @param filepath : [in, out] Most plugins change this filename
160 * @param handler : unpacking handler, to keep to pack again
162 * @return Tells if WinMerge handles this file
164 * @note Event FILE_PREDIFF BUFFER_PREDIFF
165 * Apply only the first correct handler
167 bool Prediffing(String & filepath, const String& filteredText, PrediffingInfo * handler, bool bMayOverwrite);
169 * @brief Prepare one file for diffing, known handler
171 * @param filepath : [in, out] Most plugins change this filename
173 bool Prediffing(String & filepath, PrediffingInfo handler, bool bMayOverwrite);
175 bool Prediffing(PrediffingInfo * handler, String & filepath, const String& filteredText, bool bMayOverwrite);
178 * @brief Transform all files to UTF8 aslong possible
180 * @param codepage : [in] codepage of source file
181 * @param filepath : [in,out] path of file to be prepared. This filename is updated if bMayOverwrite is false
182 * @param bMayOverwrite : [in] True only if the filepath points out a temp file
184 * @return Tells if we can go on with diffutils
185 * convert all Ansi or unicode-files to UTF8
186 * if other file is unicode or uses a different codepage
188 bool AnyCodepageToUTF8(int codepage, String & filepath, bool bMayOverwrite);
192 * @brief Get the list of all the free functions in all the scripts for this event :
194 * @note the order is :
195 * 1st script file, 1st function name
196 * 1st script file, 2nd function name
197 * 1st script file, ...
198 * 1st script file, last function name
199 * 2nd script file, 1st function name
200 * 2nd script file, 2nd function name
201 * 2nd script file, ...
202 * 2nd script file, last function name
204 * last script file, 1st function name
205 * last script file, 2nd function name
206 * last script file, ...
207 * last script file, last function name
209 std::vector<String> GetFreeFunctionsInScripts(const wchar_t* TransformationEvent);
212 * @brief : Execute one free function from one script
214 * @param iFncChosen : index of the function in the list returned by GetFreeFunctionsInScripts
216 * @return Tells if the text has been changed
218 * @note Event EDITOR_SCRIPT, ?
220 bool Interactive(String & text, const wchar_t *TransformationEvent, int iFncChosen);
222 String GetUnpackedFileExtension(const String& filteredFilenames, const PackingInfo* handler);