OSDN Git Service

Leave the class name as CIniOptionsMgr, but rename the filename to IniOptionsMgr.*
[winmerge-jp/winmerge-jp.git] / Src / FileTransform.h
1 /////////////////////////////////////////////////////////////////////////////
2 //    WinMerge:  an interactive diff/merge utility
3 //    Copyright (C) 1997-2000  Thingamahoochie Software
4 //    Author: Dean Grimm
5 //    SPDX-License-Identifier: GPL-2.0-or-later
6 /////////////////////////////////////////////////////////////////////////////
7 /**
8  *  @file FileTransform.h
9  *
10  *  @brief Declaration of file transformations
11  */ 
12 #pragma once
13
14 #include <vector>
15 #include "UnicodeString.h"
16 #include "MergeApp.h"
17
18 /**
19  * @brief Modes for plugin (Modes for prediffing included)
20  */
21 enum class PLUGIN_MODE
22 {
23         // Modes for "unpacking"
24         PLUGIN_MANUAL,
25         PLUGIN_AUTO,
26         PLUGIN_BUILTIN_XML,
27
28         // Modes for "prediffing"
29         PREDIFF_MANUAL = PLUGIN_MANUAL,
30         PREDIFF_AUTO = PLUGIN_AUTO,
31 };
32
33 namespace FileTransform
34 {
35 extern PLUGIN_MODE g_UnpackerMode;
36 extern PLUGIN_MODE g_PredifferMode;
37 }
38
39 class UniFile;
40
41 /**
42  * @brief Plugin information for a given file
43  *
44  * @note Can be be passed/copied between threads
45  */
46 class PluginForFile
47 {
48 public:
49         void Initialize(PLUGIN_MODE Mode)
50         {
51                 // and init Plugin/Prediffer mode and Plugin name accordingly
52                 m_PluginOrPredifferMode = Mode;
53                 if (Mode != PLUGIN_MODE::PLUGIN_AUTO)
54                 {
55                         m_PluginName.erase();
56                 }
57                 else
58                 {
59                         m_PluginName = _("<Automatic>");
60                 }
61         };
62         explicit PluginForFile(PLUGIN_MODE Mode) 
63         {
64                 Initialize(Mode);
65         };
66 public:
67         /// PLUGIN_AUTO if the plugin will be defined during the first use (via scan of all available plugins)
68         PLUGIN_MODE     m_PluginOrPredifferMode;
69
70         /// plugin name when it is defined
71         String          m_PluginName;
72 };
73
74 /**
75  * @brief Unpacking/packing information for a given file
76  *
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
80  */
81 class PackingInfo : public PluginForFile
82 {
83 public:
84         explicit PackingInfo(PLUGIN_MODE Mode = FileTransform::g_UnpackerMode)
85         : PluginForFile(Mode)
86         , m_subcode(0)
87         , m_pufile(nullptr)
88         , m_bDisallowMixedEOL(false)
89         {
90         }
91 public:
92         /// keep some info from unpacking for packing
93         int                     m_subcode;
94         /// text type to override syntax highlighting
95         String          m_textType;
96         /// custom UniFile
97         UniFile*        m_pufile;
98         bool            m_bDisallowMixedEOL;
99 };
100
101 /**
102  * @brief Prediffing information for a given file
103  *
104  * @note Can be be passed/copied between threads
105  */
106 class PrediffingInfo : public PluginForFile
107 {
108 public:
109         explicit PrediffingInfo(PLUGIN_MODE Mode = FileTransform::g_PredifferMode)
110         : PluginForFile(Mode)
111         {
112         }
113 };
114
115 namespace FileTransform
116 {
117
118 // Events handler
119 // WinMerge uses one of these entry points to call a plugin
120
121 // bMayOverwrite : tells if we can overwrite the source file
122 // if we don't, don't forget do delete the temp file after use
123
124 /**
125  * @brief Prepare one file for loading, scan all available plugins (events+filename filtering) 
126  *
127  * @param filepath : [in, out] Most plugins change this filename
128  * @param handler : unpacking handler, to keep to pack again
129  *
130  * @return Tells if WinMerge handles this file
131  *
132  * @note Event FILE_UNPACK
133  * Apply only the first correct handler
134  */
135 bool Unpacking(String & filepath, const String& filteredText, PackingInfo * handler, int * handlerSubcode);
136 /**
137  * @brief Prepare one file for loading, known handler
138  *
139  * @param filepath : [in, out] Most plugins change this filename
140  */
141 bool Unpacking(String & filepath, const PackingInfo * handler, int * handlerSubcode);
142
143 bool Unpacking(PackingInfo * handler, String & filepath, const String& filteredText);
144
145 /**
146  * @brief Prepare one file for saving, known handler
147  *
148  * @return Tells if we can save the file (really hope we can)
149  *
150  * @param filepath : [in, out] Most plugins change this filename
151  *
152  * @note Event FILE_PACK
153  * Never do Unicode conversion, it was done in SaveFromFile
154  */
155 bool Packing(String & filepath, PackingInfo handler);
156
157 /**
158  * @brief Prepare one file for diffing, scan all available plugins (events+filename filtering) 
159  *
160  * @param filepath : [in, out] Most plugins change this filename
161  * @param handler : unpacking handler, to keep to pack again
162  *
163  * @return Tells if WinMerge handles this file
164  *
165  * @note Event FILE_PREDIFF BUFFER_PREDIFF
166  * Apply only the first correct handler
167  */
168 bool Prediffing(String & filepath, const String& filteredText, PrediffingInfo * handler, bool bMayOverwrite);
169 /**
170  * @brief Prepare one file for diffing, known handler
171  *
172  * @param filepath : [in, out] Most plugins change this filename
173  */
174 bool Prediffing(String & filepath, PrediffingInfo handler, bool bMayOverwrite);
175
176 bool Prediffing(PrediffingInfo * handler, String & filepath, const String& filteredText, bool bMayOverwrite);
177
178 /**
179  * @brief Transform all files to UTF8 aslong possible
180  *
181  * @param codepage : [in] codepage of source file
182  * @param filepath : [in,out] path of file to be prepared. This filename is updated if bMayOverwrite is false
183  * @param bMayOverwrite : [in] True only if the filepath points out a temp file
184  *
185  * @return Tells if we can go on with diffutils
186  * convert all Ansi or unicode-files to UTF8 
187  * if other file is unicode or uses a different codepage
188  */
189 bool AnyCodepageToUTF8(int codepage, String & filepath, bool bMayOverwrite);
190
191
192 /**
193  * @brief Get the list of all the free functions in all the scripts for this event :
194  * 
195  * @note the order is :
196  * 1st script file, 1st function name
197  * 1st script file, 2nd function name
198  * 1st script file, ...
199  * 1st script file, last function name
200  * 2nd script file, 1st function name
201  * 2nd script file, 2nd function name
202  * 2nd script file, ...
203  * 2nd script file, last function name
204  * ... script file
205  * last script file, 1st function name
206  * last script file, 2nd function name
207  * last script file, ...
208  * last script file, last function name
209  */
210 std::vector<String> GetFreeFunctionsInScripts(const wchar_t* TransformationEvent);
211
212 /** 
213  * @brief : Execute one free function from one script
214  *
215  * @param iFncChosen : index of the function in the list returned by GetFreeFunctionsInScripts
216  *
217  * @return Tells if the text has been changed 
218  *
219  * @note Event EDITOR_SCRIPT, ?
220  */
221 bool Interactive(String & text, const wchar_t *TransformationEvent, int iFncChosen);
222
223 }