mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-18 04:11:57 -06:00
3.13
This commit is contained in:
564
Far/FarPlugin.h
Executable file
564
Far/FarPlugin.h
Executable file
@@ -0,0 +1,564 @@
|
||||
#pragma once
|
||||
|
||||
#if defined(__BORLANDC__) && (__BORLANDC <= 0x520)
|
||||
#pragma option -a1
|
||||
#elif defined(__GNUC__) || (defined(__WATCOMC__) && (__WATCOMC__ < 1100))
|
||||
#pragma pack(1)
|
||||
#else
|
||||
#pragma pack(push,1)
|
||||
#if _MSC_VER
|
||||
#define _export
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define NM 260
|
||||
|
||||
struct FarFindData
|
||||
{
|
||||
DWORD dwFileAttributes;
|
||||
FILETIME ftCreationTime;
|
||||
FILETIME ftLastAccessTime;
|
||||
FILETIME ftLastWriteTime;
|
||||
DWORD nFileSizeHigh;
|
||||
DWORD nFileSizeLow;
|
||||
DWORD dwReserved0;
|
||||
DWORD dwReserved1;
|
||||
char cFileName[ MAX_PATH ];
|
||||
char cAlternateFileName[ 14 ];
|
||||
};
|
||||
|
||||
struct PluginPanelItem
|
||||
{
|
||||
FarFindData FindData;
|
||||
DWORD PackSizeHigh;
|
||||
DWORD PackSize;
|
||||
DWORD Flags;
|
||||
DWORD NumberOfLinks;
|
||||
char *Description;
|
||||
char *Owner;
|
||||
char **CustomColumnData;
|
||||
int CustomColumnNumber;
|
||||
DWORD UserData;
|
||||
DWORD Reserved[3];
|
||||
};
|
||||
|
||||
#define PPIF_PROCESSDESCR 0x80000000
|
||||
#define PPIF_SELECTED 0x40000000
|
||||
#define PPIF_USERDATA 0x20000000
|
||||
|
||||
enum {
|
||||
FMENU_SHOWAMPERSAND=1,
|
||||
FMENU_WRAPMODE=2,
|
||||
FMENU_AUTOHIGHLIGHT=4,
|
||||
FMENU_REVERSEAUTOHIGHLIGHT=8
|
||||
};
|
||||
|
||||
|
||||
typedef int (WINAPI *FARAPIMENU)(
|
||||
int PluginNumber,
|
||||
int X,
|
||||
int Y,
|
||||
int MaxHeight,
|
||||
unsigned int Flags,
|
||||
char *Title,
|
||||
char *Bottom,
|
||||
char *HelpTopic,
|
||||
int *BreakKeys,
|
||||
int *BreakCode,
|
||||
struct FarMenuItem *Item,
|
||||
int ItemsNumber
|
||||
);
|
||||
|
||||
typedef int (WINAPI *FARAPIDIALOG)(
|
||||
int PluginNumber,
|
||||
int X1,
|
||||
int Y1,
|
||||
int X2,
|
||||
int Y2,
|
||||
char *HelpTopic,
|
||||
struct FarDialogItem *Item,
|
||||
int ItemsNumber
|
||||
);
|
||||
|
||||
enum {
|
||||
FMSG_WARNING=1,
|
||||
FMSG_ERRORTYPE=2,
|
||||
FMSG_KEEPBACKGROUND=4,
|
||||
FMSG_DOWN=8,
|
||||
FMSG_LEFTALIGN=16
|
||||
};
|
||||
|
||||
typedef int (WINAPI *FARAPIMESSAGE)(
|
||||
int PluginNumber,
|
||||
unsigned int Flags,
|
||||
char *HelpTopic,
|
||||
char **Items,
|
||||
int ItemsNumber,
|
||||
int ButtonsNumber
|
||||
);
|
||||
|
||||
typedef char* (WINAPI *FARAPIGETMSG)(
|
||||
int PluginNumber,
|
||||
int MsgId
|
||||
);
|
||||
|
||||
|
||||
enum DialogItemTypes {
|
||||
DI_TEXT,
|
||||
DI_VTEXT,
|
||||
DI_SINGLEBOX,
|
||||
DI_DOUBLEBOX,
|
||||
DI_EDIT,
|
||||
DI_PSWEDIT,
|
||||
DI_FIXEDIT,
|
||||
DI_BUTTON,
|
||||
DI_CHECKBOX,
|
||||
DI_RADIOBUTTON
|
||||
};
|
||||
|
||||
enum FarDialogItemFlags {
|
||||
DIF_COLORMASK = 0xff,
|
||||
DIF_SETCOLOR = 0x100,
|
||||
DIF_BOXCOLOR = 0x200,
|
||||
DIF_GROUP = 0x400,
|
||||
DIF_LEFTTEXT = 0x800,
|
||||
DIF_MOVESELECT = 0x1000,
|
||||
DIF_SHOWAMPERSAND = 0x2000,
|
||||
DIF_CENTERGROUP = 0x4000,
|
||||
DIF_NOBRACKETS = 0x8000,
|
||||
DIF_SEPARATOR = 0x10000,
|
||||
DIF_EDITOR = 0x20000,
|
||||
DIF_HISTORY = 0x40000
|
||||
};
|
||||
|
||||
struct FarDialogItem
|
||||
{
|
||||
int Type;
|
||||
int X1,Y1,X2,Y2;
|
||||
int Focus;
|
||||
int Selected;
|
||||
unsigned int Flags;
|
||||
int DefaultButton;
|
||||
char Data[512];
|
||||
};
|
||||
|
||||
|
||||
struct FarMenuItem
|
||||
{
|
||||
char Text[128];
|
||||
int Selected;
|
||||
int Checked;
|
||||
int Separator;
|
||||
};
|
||||
|
||||
|
||||
enum {FCTL_CLOSEPLUGIN,FCTL_GETPANELINFO,FCTL_GETANOTHERPANELINFO,
|
||||
FCTL_UPDATEPANEL,FCTL_UPDATEANOTHERPANEL,
|
||||
FCTL_REDRAWPANEL,FCTL_REDRAWANOTHERPANEL,
|
||||
FCTL_SETANOTHERPANELDIR,FCTL_GETCMDLINE,FCTL_SETCMDLINE,
|
||||
FCTL_SETSELECTION,FCTL_SETANOTHERSELECTION,
|
||||
FCTL_SETVIEWMODE,FCTL_SETANOTHERVIEWMODE,FCTL_INSERTCMDLINE,
|
||||
FCTL_SETUSERSCREEN,FCTL_SETPANELDIR,FCTL_SETCMDLINEPOS,
|
||||
FCTL_GETCMDLINEPOS
|
||||
};
|
||||
|
||||
enum {PTYPE_FILEPANEL,PTYPE_TREEPANEL,PTYPE_QVIEWPANEL,PTYPE_INFOPANEL};
|
||||
|
||||
struct PanelInfo
|
||||
{
|
||||
int PanelType;
|
||||
int Plugin;
|
||||
RECT PanelRect;
|
||||
struct PluginPanelItem *PanelItems;
|
||||
int ItemsNumber;
|
||||
struct PluginPanelItem *SelectedItems;
|
||||
int SelectedItemsNumber;
|
||||
int CurrentItem;
|
||||
int TopPanelItem;
|
||||
int Visible;
|
||||
int Focus;
|
||||
int ViewMode;
|
||||
char ColumnTypes[80];
|
||||
char ColumnWidths[80];
|
||||
char CurDir[NM];
|
||||
int ShortNames;
|
||||
int SortMode;
|
||||
DWORD Reserved[2];
|
||||
};
|
||||
|
||||
|
||||
struct PanelRedrawInfo
|
||||
{
|
||||
int CurrentItem;
|
||||
int TopPanelItem;
|
||||
};
|
||||
|
||||
|
||||
typedef int (WINAPI *FARAPICONTROL)(
|
||||
HANDLE hPlugin,
|
||||
int Command,
|
||||
void *Param
|
||||
);
|
||||
|
||||
typedef HANDLE (WINAPI *FARAPISAVESCREEN)(int X1,int Y1,int X2,int Y2);
|
||||
|
||||
typedef void (WINAPI *FARAPIRESTORESCREEN)(HANDLE hScreen);
|
||||
|
||||
typedef int (WINAPI *FARAPIGETDIRLIST)(
|
||||
char *Dir,
|
||||
struct PluginPanelItem **pPanelItem,
|
||||
int *pItemsNumber
|
||||
);
|
||||
|
||||
typedef int (WINAPI *FARAPIGETPLUGINDIRLIST)(
|
||||
int PluginNumber,
|
||||
HANDLE hPlugin,
|
||||
char *Dir,
|
||||
struct PluginPanelItem **pPanelItem,
|
||||
int *pItemsNumber
|
||||
);
|
||||
|
||||
typedef void (WINAPI *FARAPIFREEDIRLIST)(struct PluginPanelItem *PanelItem);
|
||||
|
||||
enum VIEWER_FLAGS {
|
||||
VF_NONMODAL=1,VF_DELETEONCLOSE=2
|
||||
};
|
||||
|
||||
typedef int (WINAPI *FARAPIVIEWER)(
|
||||
char *FileName,
|
||||
char *Title,
|
||||
int X1,
|
||||
int Y1,
|
||||
int X2,
|
||||
int Y2,
|
||||
DWORD Flags
|
||||
);
|
||||
|
||||
typedef int (WINAPI *FARAPIEDITOR)(
|
||||
char *FileName,
|
||||
char *Title,
|
||||
int X1,
|
||||
int Y1,
|
||||
int X2,
|
||||
int Y2,
|
||||
DWORD Flags,
|
||||
int StartLine,
|
||||
int StartChar
|
||||
);
|
||||
|
||||
typedef int (WINAPI *FARAPICMPNAME)(
|
||||
char *Pattern,
|
||||
char *String,
|
||||
int SkipPath
|
||||
);
|
||||
|
||||
|
||||
#define FCT_DETECT 0x40000000
|
||||
|
||||
struct CharTableSet
|
||||
{
|
||||
char DecodeTable[256];
|
||||
char EncodeTable[256];
|
||||
char UpperTable[256];
|
||||
char LowerTable[256];
|
||||
char TableName[128];
|
||||
};
|
||||
|
||||
typedef int (WINAPI *FARAPICHARTABLE)(
|
||||
int Command,
|
||||
char *Buffer,
|
||||
int BufferSize
|
||||
);
|
||||
|
||||
typedef void (WINAPI *FARAPITEXT)(
|
||||
int X,
|
||||
int Y,
|
||||
int Color,
|
||||
char *Str
|
||||
);
|
||||
|
||||
|
||||
typedef int (WINAPI *FARAPIEDITORCONTROL)(
|
||||
int Command,
|
||||
void *Param
|
||||
);
|
||||
|
||||
|
||||
enum EDITOR_EVENTS {
|
||||
EE_READ,EE_SAVE,EE_REDRAW,EE_CLOSE
|
||||
};
|
||||
|
||||
enum EDITOR_CONTROL_COMMANDS {
|
||||
ECTL_GETSTRING,ECTL_SETSTRING,ECTL_INSERTSTRING,ECTL_DELETESTRING,
|
||||
ECTL_DELETECHAR,ECTL_INSERTTEXT,ECTL_GETINFO,ECTL_SETPOSITION,
|
||||
ECTL_SELECT,ECTL_REDRAW,ECTL_EDITORTOOEM,ECTL_OEMTOEDITOR,
|
||||
ECTL_TABTOREAL,ECTL_REALTOTAB,ECTL_EXPANDTABS,ECTL_SETTITLE,
|
||||
ECTL_READINPUT,ECTL_PROCESSINPUT,ECTL_ADDCOLOR,ECTL_GETCOLOR
|
||||
};
|
||||
|
||||
|
||||
struct EditorGetString
|
||||
{
|
||||
int StringNumber;
|
||||
char *StringText;
|
||||
char *StringEOL;
|
||||
int StringLength;
|
||||
int SelStart;
|
||||
int SelEnd;
|
||||
};
|
||||
|
||||
|
||||
struct EditorSetString
|
||||
{
|
||||
int StringNumber;
|
||||
char *StringText;
|
||||
char *StringEOL;
|
||||
int StringLength;
|
||||
};
|
||||
|
||||
|
||||
enum EDITOR_OPTIONS {
|
||||
EOPT_EXPANDTABS=1,EOPT_PERSISTENTBLOCKS=2,EOPT_DELREMOVESBLOCKS=4,
|
||||
EOPT_AUTOINDENT=8,EOPT_SAVEFILEPOSITION=16,EOPT_AUTODETECTTABLE=32,
|
||||
EOPT_CURSORBEYONDEOL=64
|
||||
};
|
||||
|
||||
|
||||
enum EDITOR_BLOCK_TYPES {
|
||||
BTYPE_NONE,BTYPE_STREAM,BTYPE_COLUMN
|
||||
};
|
||||
|
||||
|
||||
struct EditorInfo
|
||||
{
|
||||
int EditorID;
|
||||
char *FileName;
|
||||
int WindowSizeX;
|
||||
int WindowSizeY;
|
||||
int TotalLines;
|
||||
int CurLine;
|
||||
int CurPos;
|
||||
int CurTabPos;
|
||||
int TopScreenLine;
|
||||
int LeftPos;
|
||||
int Overtype;
|
||||
int BlockType;
|
||||
int BlockStartLine;
|
||||
int AnsiMode;
|
||||
int TableNum;
|
||||
DWORD Options;
|
||||
int TabSize;
|
||||
DWORD Reserved[8];
|
||||
};
|
||||
|
||||
|
||||
struct EditorSetPosition
|
||||
{
|
||||
int CurLine;
|
||||
int CurPos;
|
||||
int CurTabPos;
|
||||
int TopScreenLine;
|
||||
int LeftPos;
|
||||
int Overtype;
|
||||
};
|
||||
|
||||
|
||||
struct EditorSelect
|
||||
{
|
||||
int BlockType;
|
||||
int BlockStartLine;
|
||||
int BlockStartPos;
|
||||
int BlockWidth;
|
||||
int BlockHeight;
|
||||
};
|
||||
|
||||
|
||||
struct EditorConvertText
|
||||
{
|
||||
char *Text;
|
||||
int TextLength;
|
||||
};
|
||||
|
||||
|
||||
struct EditorConvertPos
|
||||
{
|
||||
int StringNumber;
|
||||
int SrcPos;
|
||||
int DestPos;
|
||||
};
|
||||
|
||||
|
||||
struct EditorColor
|
||||
{
|
||||
int StringNumber;
|
||||
int ColorItem;
|
||||
int StartPos;
|
||||
int EndPos;
|
||||
int Color;
|
||||
};
|
||||
|
||||
|
||||
struct PluginStartupInfo
|
||||
{
|
||||
int StructSize;
|
||||
char ModuleName[NM];
|
||||
int ModuleNumber;
|
||||
char *RootKey;
|
||||
FARAPIMENU Menu;
|
||||
FARAPIDIALOG Dialog;
|
||||
FARAPIMESSAGE Message;
|
||||
FARAPIGETMSG GetMsg;
|
||||
FARAPICONTROL Control;
|
||||
FARAPISAVESCREEN SaveScreen;
|
||||
FARAPIRESTORESCREEN RestoreScreen;
|
||||
FARAPIGETDIRLIST GetDirList;
|
||||
FARAPIGETPLUGINDIRLIST GetPluginDirList;
|
||||
FARAPIFREEDIRLIST FreeDirList;
|
||||
FARAPIVIEWER Viewer;
|
||||
FARAPIEDITOR Editor;
|
||||
FARAPICMPNAME CmpName;
|
||||
FARAPICHARTABLE CharTable;
|
||||
FARAPITEXT Text;
|
||||
FARAPIEDITORCONTROL EditorControl;
|
||||
};
|
||||
|
||||
|
||||
enum PLUGIN_FLAGS {
|
||||
PF_PRELOAD = 0x0001,
|
||||
PF_DISABLEPANELS = 0x0002,
|
||||
PF_EDITOR = 0x0004,
|
||||
PF_VIEWER = 0x0008
|
||||
};
|
||||
|
||||
|
||||
struct PluginInfo
|
||||
{
|
||||
int StructSize;
|
||||
DWORD Flags;
|
||||
char **DiskMenuStrings;
|
||||
int *DiskMenuNumbers;
|
||||
int DiskMenuStringsNumber;
|
||||
char **PluginMenuStrings;
|
||||
int PluginMenuStringsNumber;
|
||||
char **PluginConfigStrings;
|
||||
int PluginConfigStringsNumber;
|
||||
char *CommandPrefix;
|
||||
};
|
||||
|
||||
|
||||
struct InfoPanelLine
|
||||
{
|
||||
char Text[80];
|
||||
char Data[80];
|
||||
int Separator;
|
||||
};
|
||||
|
||||
|
||||
struct PanelMode
|
||||
{
|
||||
char *ColumnTypes;
|
||||
char *ColumnWidths;
|
||||
char **ColumnTitles;
|
||||
int FullScreen;
|
||||
int DetailedStatus;
|
||||
int AlignExtensions;
|
||||
int CaseConversion;
|
||||
char *StatusColumnTypes;
|
||||
char *StatusColumnWidths;
|
||||
DWORD Reserved[2];
|
||||
};
|
||||
|
||||
|
||||
enum OPENPLUGININFO_FLAGS {
|
||||
OPIF_USEFILTER = 0x0001,
|
||||
OPIF_USESORTGROUPS = 0x0002,
|
||||
OPIF_USEHIGHLIGHTING = 0x0004,
|
||||
OPIF_ADDDOTS = 0x0008,
|
||||
OPIF_RAWSELECTION = 0x0010,
|
||||
OPIF_REALNAMES = 0x0020,
|
||||
OPIF_SHOWNAMESONLY = 0x0040,
|
||||
OPIF_SHOWRIGHTALIGNNAMES = 0x0080,
|
||||
OPIF_SHOWPRESERVECASE = 0x0100,
|
||||
OPIF_FINDFOLDERS = 0x0200,
|
||||
OPIF_COMPAREFATTIME = 0x0400,
|
||||
OPIF_EXTERNALGET = 0x0800,
|
||||
OPIF_EXTERNALPUT = 0x1000,
|
||||
OPIF_EXTERNALDELETE = 0x2000,
|
||||
OPIF_EXTERNALMKDIR = 0x4000,
|
||||
OPIF_USEATTRHIGHLIGHTING = 0x8000
|
||||
};
|
||||
|
||||
|
||||
enum OPENPLUGININFO_SORTMODES {
|
||||
SM_DEFAULT,SM_UNSORTED,SM_NAME,SM_EXT,SM_MTIME,SM_CTIME,
|
||||
SM_ATIME,SM_SIZE,SM_DESCR,SM_OWNER,SM_COMPRESSEDSIZE,SM_NUMLINKS
|
||||
};
|
||||
|
||||
|
||||
struct KeyBarTitles
|
||||
{
|
||||
char *Titles[12];
|
||||
char *CtrlTitles[12];
|
||||
char *AltTitles[12];
|
||||
char *ShiftTitles[12];
|
||||
};
|
||||
|
||||
|
||||
struct OpenPluginInfo
|
||||
{
|
||||
int StructSize;
|
||||
DWORD Flags;
|
||||
char *HostFile;
|
||||
char *CurDir;
|
||||
char *Format;
|
||||
char *PanelTitle;
|
||||
struct InfoPanelLine *InfoLines;
|
||||
int InfoLinesNumber;
|
||||
char **DescrFiles;
|
||||
int DescrFilesNumber;
|
||||
struct PanelMode *PanelModesArray;
|
||||
int PanelModesNumber;
|
||||
int StartPanelMode;
|
||||
int StartSortMode;
|
||||
int StartSortOrder;
|
||||
struct KeyBarTitles *KeyBar;
|
||||
char *ShortcutData;
|
||||
};
|
||||
|
||||
enum {
|
||||
OPEN_DISKMENU,
|
||||
OPEN_PLUGINSMENU,
|
||||
OPEN_FINDLIST,
|
||||
OPEN_SHORTCUT,
|
||||
OPEN_COMMANDLINE,
|
||||
OPEN_EDITOR,
|
||||
OPEN_VIEWER
|
||||
};
|
||||
|
||||
enum {PKF_CONTROL=1,PKF_ALT=2,PKF_SHIFT=4};
|
||||
|
||||
enum FAR_EVENTS {
|
||||
FE_CHANGEVIEWMODE,
|
||||
FE_REDRAW,
|
||||
FE_IDLE,
|
||||
FE_CLOSE,
|
||||
FE_BREAK,
|
||||
FE_COMMAND
|
||||
};
|
||||
|
||||
enum OPERATION_MODES {
|
||||
OPM_SILENT=1,
|
||||
OPM_FIND=2,
|
||||
OPM_VIEW=4,
|
||||
OPM_EDIT=8,
|
||||
OPM_TOPLEVEL=16,
|
||||
OPM_DESCR=32
|
||||
};
|
||||
|
||||
#if defined(__BORLANDC__) && (__BORLANDC <= 0x520)
|
||||
#pragma option -a.
|
||||
#elif defined(__GNUC__) || (defined(__WATCOMC__) && (__WATCOMC__ < 1100))
|
||||
#pragma pack()
|
||||
#else
|
||||
#pragma pack(pop)
|
||||
#endif
|
||||
421
Far/FarUtils.cpp
Executable file
421
Far/FarUtils.cpp
Executable file
@@ -0,0 +1,421 @@
|
||||
// FarUtils.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "FarUtils.h"
|
||||
#include "Common/DynamicBuffer.h"
|
||||
#include "Common/StringConvert.h"
|
||||
#include "Windows/Defs.h"
|
||||
#include "Windows/Console.h"
|
||||
#include "Windows/Error.h"
|
||||
|
||||
using namespace NWindows;
|
||||
using namespace std;
|
||||
|
||||
namespace NFar {
|
||||
|
||||
CStartupInfo g_StartupInfo;
|
||||
|
||||
|
||||
void CStartupInfo::Init(const PluginStartupInfo &aPluginStartupInfo,
|
||||
const CSysString &aPliginNameForRegestry)
|
||||
{
|
||||
m_Data = aPluginStartupInfo;
|
||||
m_RegistryPath = aPluginStartupInfo.RootKey;
|
||||
m_RegistryPath += '\\';
|
||||
m_RegistryPath += aPliginNameForRegestry;
|
||||
}
|
||||
|
||||
const char *CStartupInfo::GetMsgString(int aMessageId)
|
||||
{
|
||||
return (const char*)m_Data.GetMsg(m_Data.ModuleNumber, aMessageId);
|
||||
}
|
||||
|
||||
int CStartupInfo::ShowMessage(unsigned int aFlags,
|
||||
const char *aHelpTopic, const char **anItems, int anItemsNumber, int aButtonsNumber)
|
||||
{
|
||||
return m_Data.Message(m_Data.ModuleNumber, aFlags, (char *)aHelpTopic,
|
||||
(char **)anItems, anItemsNumber, aButtonsNumber);
|
||||
}
|
||||
|
||||
namespace NMessageID
|
||||
{
|
||||
enum
|
||||
{
|
||||
kOk,
|
||||
kCancel,
|
||||
kWarning,
|
||||
kError
|
||||
};
|
||||
}
|
||||
|
||||
int CStartupInfo::ShowMessage(const char *aMessage)
|
||||
{
|
||||
const char *aMessagesItems[]= { GetMsgString(NMessageID::kError), aMessage,
|
||||
GetMsgString(NMessageID::kOk) };
|
||||
return ShowMessage(FMSG_WARNING, NULL, aMessagesItems,
|
||||
sizeof(aMessagesItems) / sizeof(aMessagesItems[0]), 1);
|
||||
}
|
||||
|
||||
int CStartupInfo::ShowMessage(int aMessageId)
|
||||
{
|
||||
return ShowMessage(GetMsgString(aMessageId));
|
||||
}
|
||||
|
||||
int CStartupInfo::ShowDialog(int X1, int Y1, int X2, int Y2,
|
||||
const char *aHelpTopic, struct FarDialogItem *anItems, int aNumItems)
|
||||
{
|
||||
return m_Data.Dialog(m_Data.ModuleNumber, X1, Y1, X2, Y2, (char *)aHelpTopic,
|
||||
anItems, aNumItems);
|
||||
}
|
||||
|
||||
int CStartupInfo::ShowDialog(int aSizeX, int aSizeY,
|
||||
const char *aHelpTopic, struct FarDialogItem *anItems, int aNumItems)
|
||||
{
|
||||
return ShowDialog(-1, -1, aSizeX, aSizeY, aHelpTopic, anItems, aNumItems);
|
||||
}
|
||||
|
||||
inline static BOOL GetBOOLValue(bool aBool)
|
||||
{
|
||||
return (aBool? TRUE: FALSE);
|
||||
}
|
||||
|
||||
void CStartupInfo::InitDialogItems(const CInitDialogItem *aSrcItems,
|
||||
FarDialogItem *aDestItems, int aNum)
|
||||
{
|
||||
for (int i = 0; i < aNum; i++)
|
||||
{
|
||||
const CInitDialogItem &aSrcItem = aSrcItems[i];
|
||||
FarDialogItem &aDestItem = aDestItems[i];
|
||||
|
||||
aDestItem.Type = aSrcItem.Type;
|
||||
aDestItem.X1 = aSrcItem.X1;
|
||||
aDestItem.Y1 = aSrcItem.Y1;
|
||||
aDestItem.X2 = aSrcItem.X2;
|
||||
aDestItem.Y2 = aSrcItem.Y2;
|
||||
aDestItem.Focus = GetBOOLValue(aSrcItem.Focus);
|
||||
if(aSrcItem.HistoryName != NULL)
|
||||
aDestItem.Selected = int(aSrcItem.HistoryName);
|
||||
else
|
||||
aDestItem.Selected = GetBOOLValue(aSrcItem.Selected);
|
||||
aDestItem.Flags = aSrcItem.Flags;
|
||||
aDestItem.DefaultButton = GetBOOLValue(aSrcItem.DefaultButton);
|
||||
|
||||
if(aSrcItem.DataMessageId < 0)
|
||||
strcpy(aDestItem.Data, aSrcItem.DataString);
|
||||
else
|
||||
strcpy(aDestItem.Data, GetMsgString(aSrcItem.DataMessageId));
|
||||
|
||||
/*
|
||||
if ((unsigned int)Init[i].Data < 0xFFF)
|
||||
strcpy(aDestItem.Data, GetMsg((unsigned int)aSrcItem.Data));
|
||||
else
|
||||
strcpy(aDestItem.Data,aSrcItem.Data);
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------
|
||||
|
||||
HANDLE CStartupInfo::SaveScreen(int X1, int Y1, int X2, int Y2)
|
||||
{
|
||||
return m_Data.SaveScreen(X1, Y1, X2, Y2);
|
||||
}
|
||||
|
||||
HANDLE CStartupInfo::SaveScreen()
|
||||
{
|
||||
return SaveScreen(0, 0, -1, -1);
|
||||
}
|
||||
|
||||
void CStartupInfo::RestoreScreen(HANDLE aHandle)
|
||||
{
|
||||
m_Data.RestoreScreen(aHandle);
|
||||
}
|
||||
|
||||
const char kRegestryKeyDelimiter = '\'';
|
||||
|
||||
CSysString CStartupInfo::GetFullKeyName(const CSysString &aKeyName) const
|
||||
{
|
||||
return (aKeyName.IsEmpty()) ? m_RegistryPath:
|
||||
(m_RegistryPath + kRegestryKeyDelimiter + aKeyName);
|
||||
}
|
||||
|
||||
|
||||
LONG CStartupInfo::CreateRegKey(HKEY aKeyParent,
|
||||
const CSysString &aKeyName, NRegistry::CKey &aDestKey) const
|
||||
{
|
||||
return aDestKey.Create(aKeyParent, GetFullKeyName(aKeyName));
|
||||
}
|
||||
|
||||
LONG CStartupInfo::OpenRegKey(HKEY aKeyParent,
|
||||
const CSysString &aKeyName, NRegistry::CKey &aDestKey) const
|
||||
{
|
||||
return aDestKey.Open(aKeyParent, GetFullKeyName(aKeyName));
|
||||
}
|
||||
|
||||
void CStartupInfo::SetRegKeyValue(HKEY aKeyParent, const CSysString &aKeyName,
|
||||
LPCTSTR aValueName, LPCTSTR aValue) const
|
||||
{
|
||||
NRegistry::CKey aRegKey;
|
||||
CreateRegKey(aKeyParent, aKeyName, aRegKey);
|
||||
aRegKey.SetValue(aValueName, aValue);
|
||||
}
|
||||
|
||||
void CStartupInfo::SetRegKeyValue(HKEY aKeyParent, const CSysString &aKeyName,
|
||||
LPCTSTR aValueName, UINT32 aValue) const
|
||||
{
|
||||
NRegistry::CKey aRegKey;
|
||||
CreateRegKey(aKeyParent, aKeyName, aRegKey);
|
||||
aRegKey.SetValue(aValueName, aValue);
|
||||
}
|
||||
|
||||
void CStartupInfo::SetRegKeyValue(HKEY aKeyParent, const CSysString &aKeyName,
|
||||
LPCTSTR aValueName, bool aValue) const
|
||||
{
|
||||
NRegistry::CKey aRegKey;
|
||||
CreateRegKey(aKeyParent, aKeyName, aRegKey);
|
||||
aRegKey.SetValue(aValueName, aValue);
|
||||
}
|
||||
|
||||
CSysString CStartupInfo::QueryRegKeyValue(HKEY aKeyParent, const CSysString &aKeyName,
|
||||
LPCTSTR aValueName, const CSysString &aValueDefault) const
|
||||
{
|
||||
NRegistry::CKey aRegKey;
|
||||
if (OpenRegKey(aKeyParent, aKeyName, aRegKey) != ERROR_SUCCESS)
|
||||
return aValueDefault;
|
||||
|
||||
CSysString aValue;
|
||||
if(aRegKey.QueryValue(aValueName, aValue) != ERROR_SUCCESS)
|
||||
return aValueDefault;
|
||||
|
||||
return aValue;
|
||||
}
|
||||
|
||||
UINT32 CStartupInfo::QueryRegKeyValue(HKEY aKeyParent, const CSysString &aKeyName,
|
||||
LPCTSTR aValueName, UINT32 aValueDefault) const
|
||||
{
|
||||
NRegistry::CKey aRegKey;
|
||||
if (OpenRegKey(aKeyParent, aKeyName, aRegKey) != ERROR_SUCCESS)
|
||||
return aValueDefault;
|
||||
|
||||
UINT32 aValue;
|
||||
if(aRegKey.QueryValue(aValueName, aValue) != ERROR_SUCCESS)
|
||||
return aValueDefault;
|
||||
|
||||
return aValue;
|
||||
}
|
||||
|
||||
bool CStartupInfo::QueryRegKeyValue(HKEY aKeyParent, const CSysString &aKeyName,
|
||||
LPCTSTR aValueName, bool aValueDefault) const
|
||||
{
|
||||
NRegistry::CKey aRegKey;
|
||||
if (OpenRegKey(aKeyParent, aKeyName, aRegKey) != ERROR_SUCCESS)
|
||||
return aValueDefault;
|
||||
|
||||
bool aValue;
|
||||
if(aRegKey.QueryValue(aValueName, aValue) != ERROR_SUCCESS)
|
||||
return aValueDefault;
|
||||
|
||||
return aValue;
|
||||
}
|
||||
|
||||
bool CStartupInfo::Control(HANDLE aPlugin, int aCommand, void *aParam)
|
||||
{
|
||||
return BOOLToBool(m_Data.Control(aPlugin, aCommand, aParam));
|
||||
}
|
||||
|
||||
bool CStartupInfo::ControlRequestActivePanel(int aCommand, void *aParam)
|
||||
{
|
||||
return Control(INVALID_HANDLE_VALUE, aCommand, aParam);
|
||||
}
|
||||
|
||||
bool CStartupInfo::ControlGetActivePanelInfo(PanelInfo &aPanelInfo)
|
||||
{
|
||||
return ControlRequestActivePanel(FCTL_GETPANELINFO, &aPanelInfo);
|
||||
}
|
||||
|
||||
bool CStartupInfo::ControlSetSelection(const PanelInfo &aPanelInfo)
|
||||
{
|
||||
return ControlRequestActivePanel(FCTL_SETSELECTION, (void *)&aPanelInfo);
|
||||
}
|
||||
|
||||
bool CStartupInfo::ControlGetActivePanelCurrentItemInfo(
|
||||
PluginPanelItem &aPluginPanelItem)
|
||||
{
|
||||
PanelInfo aPanelInfo;
|
||||
if(!ControlGetActivePanelInfo(aPanelInfo))
|
||||
return false;
|
||||
if(aPanelInfo.ItemsNumber <= 0)
|
||||
throw "There are no items";
|
||||
aPluginPanelItem = aPanelInfo.PanelItems[aPanelInfo.CurrentItem];
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CStartupInfo::ControlGetActivePanelSelectedOrCurrentItems(
|
||||
CObjectVector<PluginPanelItem> &aPluginPanelItems)
|
||||
{
|
||||
aPluginPanelItems.Clear();
|
||||
PanelInfo aPanelInfo;
|
||||
if(!ControlGetActivePanelInfo(aPanelInfo))
|
||||
return false;
|
||||
if(aPanelInfo.ItemsNumber <= 0)
|
||||
throw "There are no items";
|
||||
if (aPanelInfo.SelectedItemsNumber == 0)
|
||||
aPluginPanelItems.Add(aPanelInfo.PanelItems[aPanelInfo.CurrentItem]);
|
||||
else
|
||||
for (int i = 0; i < aPanelInfo.SelectedItemsNumber; i++)
|
||||
aPluginPanelItems.Add(aPanelInfo.SelectedItems[i]);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CStartupInfo::ControlClearPanelSelection()
|
||||
{
|
||||
PanelInfo aPanelInfo;
|
||||
if(!ControlGetActivePanelInfo(aPanelInfo))
|
||||
return false;
|
||||
for (int i = 0; i < aPanelInfo.ItemsNumber; i++)
|
||||
aPanelInfo.PanelItems[i].Flags &= ~PPIF_SELECTED;
|
||||
return ControlSetSelection(aPanelInfo);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////
|
||||
// menu function
|
||||
|
||||
int CStartupInfo::Menu(
|
||||
int x,
|
||||
int y,
|
||||
int aMaxHeight,
|
||||
unsigned int aFlags,
|
||||
const char *aTitle,
|
||||
const char *aBottom,
|
||||
const char *aHelpTopic,
|
||||
int *aBreakKeys,
|
||||
int *aBreakCode,
|
||||
struct FarMenuItem *anItems,
|
||||
int aNumItems)
|
||||
{
|
||||
return m_Data.Menu(m_Data.ModuleNumber, x, y, aMaxHeight, aFlags, (char *)aTitle,
|
||||
(char *)aBottom, (char *)aHelpTopic, aBreakKeys, aBreakCode, anItems, aNumItems);
|
||||
}
|
||||
|
||||
int CStartupInfo::Menu(
|
||||
unsigned int aFlags,
|
||||
const char *aTitle,
|
||||
const char *aHelpTopic,
|
||||
struct FarMenuItem *anItems,
|
||||
int aNumItems)
|
||||
{
|
||||
return Menu(-1, -1, 0, aFlags, aTitle, NULL, aHelpTopic, NULL,
|
||||
NULL, anItems, aNumItems);
|
||||
}
|
||||
|
||||
int CStartupInfo::Menu(
|
||||
unsigned int aFlags,
|
||||
const char *aTitle,
|
||||
const char *aHelpTopic,
|
||||
const CSysStringVector &anItems,
|
||||
int aSelectedItem)
|
||||
{
|
||||
vector<FarMenuItem> aFarMenuItems;
|
||||
for(int i = 0; i < anItems.Size(); i++)
|
||||
{
|
||||
FarMenuItem anItem;
|
||||
anItem.Checked = 0;
|
||||
anItem.Separator = 0;
|
||||
anItem.Selected = (i == aSelectedItem);
|
||||
CSysString aReducedString =
|
||||
anItems[i].Left(sizeof(anItem.Text) / sizeof(anItem.Text[0]) - 1);
|
||||
strcpy(anItem.Text, aReducedString);
|
||||
aFarMenuItems.push_back(anItem);
|
||||
}
|
||||
return Menu(aFlags, aTitle, aHelpTopic, &aFarMenuItems.front(),
|
||||
aFarMenuItems.size());
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////
|
||||
// CScreenRestorer
|
||||
|
||||
CScreenRestorer::~CScreenRestorer()
|
||||
{
|
||||
Restore();
|
||||
}
|
||||
void CScreenRestorer::Save()
|
||||
{
|
||||
if(m_Saved)
|
||||
return;
|
||||
m_HANDLE = g_StartupInfo.SaveScreen();
|
||||
m_Saved = true;
|
||||
}
|
||||
|
||||
void CScreenRestorer::Restore()
|
||||
{
|
||||
if(m_Saved)
|
||||
{
|
||||
g_StartupInfo.RestoreScreen(m_HANDLE);
|
||||
m_Saved = false;
|
||||
}
|
||||
};
|
||||
|
||||
static CSysString DWORDToString(DWORD aNumber)
|
||||
{
|
||||
char aBuffer[32];
|
||||
ultoa(aNumber, aBuffer, 10);
|
||||
return aBuffer;
|
||||
}
|
||||
|
||||
void PrintErrorMessage(const char *aMessage, int anCode)
|
||||
{
|
||||
CSysString aTmp = aMessage;
|
||||
aTmp += " #";
|
||||
aTmp += DWORDToString(anCode);
|
||||
g_StartupInfo.ShowMessage(aTmp);
|
||||
}
|
||||
|
||||
void PrintErrorMessage(const char *aMessage, const char *aText)
|
||||
{
|
||||
CSysString aTmp = aMessage;
|
||||
aTmp += ": ";
|
||||
aTmp += aText;
|
||||
g_StartupInfo.ShowMessage(aTmp);
|
||||
}
|
||||
|
||||
bool WasEscPressed()
|
||||
{
|
||||
NConsole::CIn anInConsole;
|
||||
HANDLE aHandle = ::GetStdHandle(STD_INPUT_HANDLE);
|
||||
if(aHandle == INVALID_HANDLE_VALUE)
|
||||
return true;
|
||||
anInConsole.Attach(aHandle);
|
||||
while (true)
|
||||
{
|
||||
DWORD aNumberOfEvents;
|
||||
if(!anInConsole.GetNumberOfEvents(aNumberOfEvents))
|
||||
return true;
|
||||
if(aNumberOfEvents == 0)
|
||||
return false;
|
||||
|
||||
INPUT_RECORD anEvent;
|
||||
if(!anInConsole.ReadEvent(anEvent, aNumberOfEvents))
|
||||
return true;
|
||||
if (anEvent.EventType == KEY_EVENT &&
|
||||
anEvent.Event.KeyEvent.bKeyDown &&
|
||||
anEvent.Event.KeyEvent.wVirtualKeyCode == VK_ESCAPE)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void ShowErrorMessage(DWORD aError)
|
||||
{
|
||||
CSysString aMessage;
|
||||
NError::MyFormatMessage(aError, aMessage);
|
||||
g_StartupInfo.ShowMessage(SystemStringToOemString(aMessage));
|
||||
|
||||
}
|
||||
|
||||
void ShowLastErrorMessage()
|
||||
{
|
||||
ShowErrorMessage(::GetLastError());
|
||||
}
|
||||
|
||||
}
|
||||
220
Far/FarUtils.h
Executable file
220
Far/FarUtils.h
Executable file
@@ -0,0 +1,220 @@
|
||||
// FarUtils.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __FARUTILS_H
|
||||
#define __FARUTILS_H
|
||||
|
||||
#include "FarPlugin.h"
|
||||
#include "Common/String.h"
|
||||
#include "Common/Vector.h"
|
||||
#include "Windows/Registry.h"
|
||||
|
||||
namespace NFar {
|
||||
|
||||
namespace NFileOperationReturnCode
|
||||
{
|
||||
enum EEnum
|
||||
{
|
||||
kInterruptedByUser = -1,
|
||||
kError = 0,
|
||||
kSuccess = 1
|
||||
};
|
||||
}
|
||||
|
||||
namespace NEditorReturnCode
|
||||
{
|
||||
enum EEnum
|
||||
{
|
||||
kOpenError = 0,
|
||||
kFileWasChanged = 1,
|
||||
kFileWasNotChanged = 2,
|
||||
kInterruptedByUser = 3
|
||||
};
|
||||
}
|
||||
|
||||
struct CInitDialogItem
|
||||
{
|
||||
DialogItemTypes Type;
|
||||
int X1,Y1,X2,Y2;
|
||||
bool Focus;
|
||||
bool Selected;
|
||||
unsigned int Flags; //FarDialogItemFlags Flags;
|
||||
bool DefaultButton;
|
||||
int DataMessageId;
|
||||
const char *DataString;
|
||||
const char *HistoryName;
|
||||
// void InitToFarDialogItem(struct FarDialogItem &anItemDest);
|
||||
};
|
||||
|
||||
class CStartupInfo
|
||||
{
|
||||
PluginStartupInfo m_Data;
|
||||
CSysString m_RegistryPath;
|
||||
|
||||
CSysString GetFullKeyName(const CSysString &aKeyName) const;
|
||||
LONG CreateRegKey(HKEY aKeyParent,
|
||||
const CSysString &aKeyName, NWindows::NRegistry::CKey &aDestKey) const;
|
||||
LONG OpenRegKey(HKEY aKeyParent,
|
||||
const CSysString &aKeyName, NWindows::NRegistry::CKey &aDestKey) const;
|
||||
|
||||
public:
|
||||
void Init(const PluginStartupInfo &aPluginStartupInfo,
|
||||
const CSysString &aPliginNameForRegestry);
|
||||
const char *GetMsgString(int aMessageId);
|
||||
int ShowMessage(unsigned int aFlags, const char *aHelpTopic,
|
||||
const char **anItems, int anItemsNumber, int aButtonsNumber);
|
||||
int ShowMessage(const char *aMessage);
|
||||
int ShowMessage(int aMessageId);
|
||||
|
||||
int ShowDialog(int X1, int Y1, int X2, int Y2,
|
||||
const char *aHelpTopic, struct FarDialogItem *anItems, int aNumItems);
|
||||
int ShowDialog(int aSizeX, int aSizeY,
|
||||
const char *aHelpTopic, struct FarDialogItem *anItems, int aNumItems);
|
||||
|
||||
void InitDialogItems(const CInitDialogItem *aSrcItems,
|
||||
FarDialogItem *aDestItems, int aNum);
|
||||
|
||||
HANDLE SaveScreen(int X1, int Y1, int X2, int Y2);
|
||||
HANDLE SaveScreen();
|
||||
void RestoreScreen(HANDLE aHandle);
|
||||
|
||||
void SetRegKeyValue(HKEY aKeyParent, const CSysString &aKeyName,
|
||||
const LPCTSTR aValueName, LPCTSTR aValue) const;
|
||||
void SetRegKeyValue(HKEY hRoot, const CSysString &aKeyName,
|
||||
const LPCTSTR aValueName, UINT32 aValue) const;
|
||||
void SetRegKeyValue(HKEY hRoot, const CSysString &aKeyName,
|
||||
const LPCTSTR aValueName, bool aValue) const;
|
||||
|
||||
CSysString QueryRegKeyValue(HKEY aKeyParent, const CSysString &aKeyName,
|
||||
LPCTSTR aValueName, const CSysString &aValueDefault) const;
|
||||
|
||||
UINT32 QueryRegKeyValue(HKEY aKeyParent, const CSysString &aKeyName,
|
||||
LPCTSTR aValueName, UINT32 aValueDefault) const;
|
||||
|
||||
bool QueryRegKeyValue(HKEY aKeyParent, const CSysString &aKeyName,
|
||||
LPCTSTR aValueName, bool aValueDefault) const;
|
||||
|
||||
bool Control(HANDLE aPlugin, int aCommand, void *aParam);
|
||||
bool ControlRequestActivePanel(int aCommand, void *aParam);
|
||||
bool ControlGetActivePanelInfo(PanelInfo &aPanelInfo);
|
||||
bool ControlSetSelection(const PanelInfo &aPanelInfo);
|
||||
bool ControlGetActivePanelCurrentItemInfo(PluginPanelItem &aPluginPanelItem);
|
||||
bool ControlGetActivePanelSelectedOrCurrentItems(
|
||||
CObjectVector<PluginPanelItem> &aPluginPanelItems);
|
||||
|
||||
bool ControlClearPanelSelection();
|
||||
|
||||
int Menu(
|
||||
int x,
|
||||
int y,
|
||||
int aMaxHeight,
|
||||
unsigned int aFlags,
|
||||
const char *aTitle,
|
||||
const char *aBottom,
|
||||
const char *aHelpTopic,
|
||||
int *aBreakKeys,
|
||||
int *aBreakCode,
|
||||
FarMenuItem *anItems,
|
||||
int aNumItems);
|
||||
int Menu(
|
||||
unsigned int aFlags,
|
||||
const char *aTitle,
|
||||
const char *aHelpTopic,
|
||||
FarMenuItem *anItems,
|
||||
int aNumItems);
|
||||
|
||||
int Menu(
|
||||
unsigned int aFlags,
|
||||
const char *aTitle,
|
||||
const char *aHelpTopic,
|
||||
const CSysStringVector &anItems,
|
||||
int aSelectedItem);
|
||||
|
||||
int Editor(const char *aFileName, const char *aTitle,
|
||||
int X1, int Y1, int X2, int Y2, DWORD aFlags, int aStartLine, int aStartChar)
|
||||
{ return m_Data.Editor((char *)aFileName, (char *)aTitle, X1, Y1, X2, Y2,
|
||||
aFlags, aStartLine, aStartChar); }
|
||||
int Editor(const char *aFileName)
|
||||
{ return Editor(aFileName, NULL, 0, 0, -1, -1, 0, -1, -1); }
|
||||
|
||||
int Viewer(const char *aFileName, const char *aTitle,
|
||||
int X1, int Y1, int X2, int Y2, DWORD aFlags)
|
||||
{ return m_Data.Viewer((char *)aFileName, (char *)aTitle, X1, Y1, X2, Y2, aFlags); }
|
||||
int Viewer(const char *aFileName)
|
||||
{ return Viewer(aFileName, NULL, 0, 0, -1, -1, VF_NONMODAL); }
|
||||
|
||||
};
|
||||
|
||||
class CScreenRestorer
|
||||
{
|
||||
bool m_Saved;
|
||||
HANDLE m_HANDLE;
|
||||
public:
|
||||
CScreenRestorer(): m_Saved(false){};
|
||||
~CScreenRestorer();
|
||||
void Save();
|
||||
void Restore();
|
||||
};
|
||||
|
||||
|
||||
extern CStartupInfo g_StartupInfo;
|
||||
|
||||
void PrintErrorMessage(const char *aMessage, int anCode);
|
||||
void PrintErrorMessage(const char *aMessage, const char *aText);
|
||||
|
||||
#define MY_TRY_BEGIN try\
|
||||
{
|
||||
|
||||
#define MY_TRY_END1(x) }\
|
||||
catch(int n)\
|
||||
{\
|
||||
PrintErrorMessage(x, n);\
|
||||
return;\
|
||||
}\
|
||||
catch(const CSysString &aText)\
|
||||
{\
|
||||
PrintErrorMessage(x, aText);\
|
||||
return;\
|
||||
}\
|
||||
catch(const char *aText)\
|
||||
{\
|
||||
PrintErrorMessage(x, aText);\
|
||||
return;\
|
||||
}\
|
||||
catch(...)\
|
||||
{\
|
||||
g_StartupInfo.ShowMessage(x);\
|
||||
return;\
|
||||
}
|
||||
|
||||
#define MY_TRY_END2(x, y) }\
|
||||
catch(int n)\
|
||||
{\
|
||||
PrintErrorMessage(x, n);\
|
||||
return y;\
|
||||
}\
|
||||
catch(const CSysString &aText)\
|
||||
{\
|
||||
PrintErrorMessage(x, aText);\
|
||||
return y;\
|
||||
}\
|
||||
catch(const char *aText)\
|
||||
{\
|
||||
PrintErrorMessage(x, aText);\
|
||||
return y;\
|
||||
}\
|
||||
catch(...)\
|
||||
{\
|
||||
g_StartupInfo.ShowMessage(x);\
|
||||
return y;\
|
||||
}
|
||||
|
||||
bool WasEscPressed();
|
||||
|
||||
void ShowErrorMessage(DWORD aError);
|
||||
void ShowLastErrorMessage();
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
101
Far/ProgressBox.cpp
Executable file
101
Far/ProgressBox.cpp
Executable file
@@ -0,0 +1,101 @@
|
||||
// ProgressBox.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "ProgressBox.h"
|
||||
|
||||
#include "FarUtils.h"
|
||||
|
||||
using namespace NFar;
|
||||
|
||||
static void CopySpaces(char *aString, int aNumSpaces)
|
||||
{
|
||||
for(int i = 0; i < aNumSpaces; i++)
|
||||
aString[i] = ' ';
|
||||
aString[i] = '\0';
|
||||
}
|
||||
|
||||
/////////////////////////////////
|
||||
// CMessageBox
|
||||
|
||||
const int kNumStringsMax = 10;
|
||||
|
||||
void CMessageBox::Init(const CSysString &aTitle, const CSysString &aMessage,
|
||||
int aNumStrings, int aWidth)
|
||||
{
|
||||
if (aNumStrings > kNumStringsMax)
|
||||
throw 120620;
|
||||
m_NumStrings = aNumStrings;
|
||||
m_Width = aWidth;
|
||||
|
||||
m_Title = aTitle;
|
||||
m_Message = aMessage;
|
||||
}
|
||||
|
||||
const int kNumStaticStrings = 2;
|
||||
|
||||
void CMessageBox::ShowProcessMessages(const char *aMessages[])
|
||||
{
|
||||
const char *aMsgItems[kNumStaticStrings + kNumStringsMax];
|
||||
aMsgItems[0] = m_Title;
|
||||
aMsgItems[1] = m_Message;
|
||||
|
||||
char aFormattedMessages[kNumStringsMax][256];
|
||||
|
||||
for (int i = 0; i < m_NumStrings; i++)
|
||||
{
|
||||
char *aFormattedMessage = aFormattedMessages[i];
|
||||
int aLen = strlen(aMessages[i]);
|
||||
int aSize = MyMax(m_Width, aLen);
|
||||
int aStartPos = (aSize - aLen) / 2;
|
||||
CopySpaces(aFormattedMessage, aStartPos);
|
||||
strcpy(aFormattedMessage + aStartPos, aMessages[i]);
|
||||
CopySpaces(aFormattedMessage + aStartPos + aLen, aSize - aStartPos - aLen);
|
||||
aMsgItems[kNumStaticStrings + i] = aFormattedMessage;
|
||||
}
|
||||
|
||||
g_StartupInfo.ShowMessage(0, NULL, aMsgItems, kNumStaticStrings + m_NumStrings, 0);
|
||||
}
|
||||
|
||||
/////////////////////////////////
|
||||
// CProgressBox
|
||||
|
||||
void CProgressBox::Init(const CSysString &aTitle, const CSysString &aMessage,
|
||||
UINT64 aStep)
|
||||
{
|
||||
CMessageBox::Init(aTitle, aMessage, 1, 22);
|
||||
m_Step = aStep;
|
||||
m_CompletedPrev = 0;
|
||||
m_Total = 0;
|
||||
}
|
||||
|
||||
|
||||
void CProgressBox::ShowProcessMessage(const char *aMessage)
|
||||
{
|
||||
CMessageBox::ShowProcessMessages(&aMessage);
|
||||
}
|
||||
|
||||
void CProgressBox::PrintPercent(UINT64 aPercent)
|
||||
{
|
||||
char aValueBuffer[32];
|
||||
sprintf(aValueBuffer, "%I64u%%", aPercent);
|
||||
ShowProcessMessage(aValueBuffer);
|
||||
}
|
||||
|
||||
void CProgressBox::SetTotal(UINT64 aTotal)
|
||||
{
|
||||
m_Total = aTotal;
|
||||
}
|
||||
|
||||
void CProgressBox::PrintCompeteValue(UINT64 aCompleted)
|
||||
{
|
||||
if (aCompleted >= m_CompletedPrev + m_Step || aCompleted < m_CompletedPrev ||
|
||||
aCompleted == 0)
|
||||
{
|
||||
if (m_Total == 0)
|
||||
PrintPercent(0);
|
||||
else
|
||||
PrintPercent(aCompleted * 100 / m_Total);
|
||||
m_CompletedPrev = aCompleted;
|
||||
}
|
||||
}
|
||||
36
Far/ProgressBox.h
Executable file
36
Far/ProgressBox.h
Executable file
@@ -0,0 +1,36 @@
|
||||
// ProgressBox.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __PROGRESSBOX_H
|
||||
#define __PROGRESSBOX_H
|
||||
|
||||
#include "Common/String.h"
|
||||
|
||||
class CMessageBox
|
||||
{
|
||||
CSysString m_Title;
|
||||
CSysString m_Message;
|
||||
int m_NumStrings;
|
||||
int m_Width;
|
||||
public:
|
||||
void Init(const CSysString &aConvertingTitle,
|
||||
const CSysString &aConvertingMessage, int aNumStrings, int aWidth);
|
||||
void ShowProcessMessages(const char *aMessages[]);
|
||||
};
|
||||
|
||||
class CProgressBox: public CMessageBox
|
||||
{
|
||||
UINT64 m_Total;
|
||||
UINT64 m_CompletedPrev;
|
||||
UINT64 m_Step;
|
||||
public:
|
||||
void Init(const CSysString &aConvertingTitle,
|
||||
const CSysString &aConvertingMessage, UINT64 aStep);
|
||||
void ShowProcessMessage(const char *aMessage);
|
||||
void PrintPercent(UINT64 aPercent);
|
||||
void PrintCompeteValue(UINT64 aCompleted);
|
||||
void SetTotal(UINT64 aTotal);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user