diff options
author | Kirill Volinsky <mataes2007@gmail.com> | 2012-05-26 17:29:10 +0000 |
---|---|---|
committer | Kirill Volinsky <mataes2007@gmail.com> | 2012-05-26 17:29:10 +0000 |
commit | 8b437fdb2e61c4f94e01eb727f6a4c68ba12c0b7 (patch) | |
tree | 3bcfd8deeba38930980044af3a78865b3e20e097 /plugins/Db_autobackups | |
parent | 1ee7fc10f76d284b5b8bc4ed4d93bdd1a057d55b (diff) |
projects cleanup
db_autobackups moved from mmap_sa, coz it for all databases
git-svn-id: http://svn.miranda-ng.org/main/trunk@184 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Db_autobackups')
-rw-r--r-- | plugins/Db_autobackups/backup.c | 230 | ||||
-rw-r--r-- | plugins/Db_autobackups/db_autobackups.rc | 182 | ||||
-rw-r--r-- | plugins/Db_autobackups/db_autobackups_10.vcxproj | 183 | ||||
-rw-r--r-- | plugins/Db_autobackups/db_autobackups_10.vcxproj.filters | 55 | ||||
-rw-r--r-- | plugins/Db_autobackups/icos/backup.ico | bin | 0 -> 2550 bytes | |||
-rw-r--r-- | plugins/Db_autobackups/main.c | 262 | ||||
-rw-r--r-- | plugins/Db_autobackups/options.c | 360 | ||||
-rw-r--r-- | plugins/Db_autobackups/options.h | 37 | ||||
-rw-r--r-- | plugins/Db_autobackups/resource.h | 35 | ||||
-rw-r--r-- | plugins/Db_autobackups/resource.rc | 2 | ||||
-rw-r--r-- | plugins/Db_autobackups/version.h | 16 | ||||
-rw-r--r-- | plugins/Db_autobackups/version.rc | 39 |
12 files changed, 1401 insertions, 0 deletions
diff --git a/plugins/Db_autobackups/backup.c b/plugins/Db_autobackups/backup.c new file mode 100644 index 0000000000..377a1fe539 --- /dev/null +++ b/plugins/Db_autobackups/backup.c @@ -0,0 +1,230 @@ +#include "headers.h"
+#include <commctrl.h>
+
+TCHAR dbname[MAX_PATH];
+
+static UINT_PTR timer_id;
+
+INT_PTR CALLBACK DlgProcProgress(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch(msg) {
+ case WM_INITDIALOG:
+ {
+ HWND prog = GetDlgItem(hwndDlg, IDC_PROGRESS);
+ TranslateDialogDefault( hwndDlg );
+ SendMessage(prog, PBM_SETPOS, 0, 0);
+ }
+ break;
+ case WM_COMMAND:
+ if ( HIWORD( wParam ) == BN_CLICKED && LOWORD( wParam ) == IDCANCEL ) {
+ // in the progress dialog, use the user data to indicate that the user has pressed cancel
+ SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)1);
+ return TRUE;
+ }
+ break;
+ }
+ return FALSE;
+}
+
+INT_PTR DBSaveAs(WPARAM wParam, LPARAM lParam)
+{
+ HWND progress_dialog = 0;
+ TCHAR fname_buff[MAX_PATH], szFilter[128];
+ int i;
+ OPENFILENAME ofn = {0};
+ CallService(MS_DB_GETPROFILENAMET,MAX_PATH,(LPARAM)fname_buff);
+
+ i = mir_sntprintf(szFilter, 64, _T("%s (*.dat)"), TranslateT("Miranda Databases")) + 1;
+ _tcscpy(szFilter + i, _T("*.dat"));
+ i += 6;
+ i += mir_sntprintf(szFilter + i, 48, _T("%s (*.*)"), TranslateT("All Files")) + 1;
+ _tcscpy(szFilter + i, _T("*"));
+ szFilter[i + 2] = 0;
+
+ ofn.lStructSize = sizeof(ofn);
+ ofn.lpstrFile = fname_buff;
+ ofn.nMaxFile = MAX_PATH;
+ ofn.Flags = OFN_NOREADONLYRETURN | OFN_OVERWRITEPROMPT;
+ ofn.lpstrFilter = szFilter;
+ ofn.nFilterIndex = 1;
+ ofn.lpstrDefExt = _T("dat");
+
+ if (GetSaveFileName(&ofn))
+ Backup(fname_buff);
+
+ return 0;
+}
+
+struct FileNameFound_Tag
+{
+ TCHAR Name[MAX_PATH];
+ FILETIME CreationTime;
+}FileNameFound;
+
+int RotateBackups(HWND progress_dialog, DWORD start_time)
+{
+ TCHAR backupfilename1[MAX_PATH] = {0}, backupfilename2[MAX_PATH] = {0}, backupfolderTmp[MAX_PATH] = {0};
+ TCHAR* backupfolder;
+ unsigned int i = 0;
+ HWND prog = GetDlgItem(progress_dialog, IDC_PROGRESS);
+ MSG msg;
+
+ WIN32_FIND_DATA FindFileData;
+ HANDLE hFind;
+
+ backupfolder = Utils_ReplaceVarsT(options.folder);
+
+ mir_sntprintf(backupfolderTmp, SIZEOF(backupfolderTmp), _T("%s\\*"), backupfolder);
+ hFind = FindFirstFile(backupfolderTmp, &FindFileData);
+ if (hFind == INVALID_HANDLE_VALUE)
+ return 0;
+ _tcscpy(FileNameFound.Name, _T(""));
+ while (FindNextFile(hFind, &FindFileData))
+ {
+ if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ continue;
+ else if (_tcsicmp(&FindFileData.cFileName[_tcslen(FindFileData.cFileName)-4], _T(".bak")) == 0)
+ {
+ if (_tcsicmp(FileNameFound.Name, _T("")) == 0)
+ {
+ _tcscpy(FileNameFound.Name, FindFileData.cFileName);
+ FileNameFound.CreationTime = FindFileData.ftCreationTime;
+ }
+ else if ((FindFileData.ftCreationTime.dwHighDateTime < FileNameFound.CreationTime.dwHighDateTime) || (FindFileData.ftCreationTime.dwHighDateTime == FileNameFound.CreationTime.dwHighDateTime && FindFileData.ftCreationTime.dwLowDateTime < FileNameFound.CreationTime.dwLowDateTime))
+ {
+ _tcscpy(FileNameFound.Name, FindFileData.cFileName);
+ FileNameFound.CreationTime = FindFileData.ftCreationTime;
+ }
+ i++;
+ while(PeekMessage(&msg, progress_dialog, 0, 0, PM_REMOVE) != 0)
+ {
+ if(!IsDialogMessage(progress_dialog, &msg))
+ {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ }
+
+ SendMessage(prog, PBM_SETPOS, (WPARAM)(int)(100 * (options.num_backups - i) / options.num_backups), 0);
+ UpdateWindow(progress_dialog);
+ }
+ }
+
+ FindClose(hFind);
+ if (i >= options.num_backups)
+ {
+ mir_sntprintf(backupfilename1, MAX_PATH, _T("%s\\%s"), backupfolder, FileNameFound.Name);
+ DeleteFile(backupfilename1);
+ }
+ mir_free(backupfolder);
+ return 0;
+}
+
+int Backup(TCHAR* backup_filename)
+{
+ TCHAR source_file[MAX_PATH] = {0}, dest_file[MAX_PATH] = {0};
+ TCHAR* backupfolder,* pathtmp,* puText;
+ HWND progress_dialog;
+ DWORD start_time = GetTickCount();
+ int i;
+ size_t dest_file_len;
+
+ CallService(MS_DB_GETPROFILENAMET, MAX_PATH, (LPARAM)dbname);
+
+ if (backup_filename == NULL)
+ {
+ int err = 0;
+
+ SYSTEMTIME st;
+ TCHAR buffer[MAX_COMPUTERNAME_LENGTH+1];
+ DWORD size = sizeof(buffer);
+
+ backupfolder = Utils_ReplaceVarsT(options.folder);
+ // ensure the backup folder exists (either create it or return non-zero signifying error)
+ err = CreateDirectoryTree(backupfolder);
+ if(err != ERROR_ALREADY_EXISTS && err != 0) {
+ return 1;
+ }
+
+ GetLocalTime(&st);
+ GetComputerName(buffer, &size);
+ mir_sntprintf(dest_file, MAX_PATH, _T("%s\\%s_%02d.%02d.%02d@%02d-%02d-%02d_%s.bak"), backupfolder, dbname, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, buffer);
+ mir_free(backupfolder);
+ }
+ else
+ lstrcpyn(dest_file, backup_filename, MAX_PATH);
+
+ if(!options.disable_popups)
+ ShowPopup(dbname, TranslateT("Backup in Progress"));
+
+ if(!options.disable_progress) {
+ progress_dialog = CreateDialog(hInst, MAKEINTRESOURCE(IDD_COPYPROGRESS), 0, (DLGPROC)DlgProcProgress);
+ SetDlgItemText(progress_dialog, IDC_PROGRESSMESSAGE, TranslateT("Rotating backup files..."));
+ }
+
+ RotateBackups(progress_dialog, start_time);
+
+ SetDlgItemText(progress_dialog, 0xDAED, TranslateT("Copying database file..."));
+ SendMessage(progress_dialog, PBM_SETPOS, (WPARAM)(int)(0), 0);
+ UpdateWindow(progress_dialog);
+
+ mir_sntprintf(source_file, MAX_PATH, _T("%s\\%s"), profilePath, dbname);
+ pathtmp = Utils_ReplaceVarsT(source_file);
+ if (CopyFile(pathtmp, dest_file, 0))
+ {
+ SendMessage(progress_dialog, PBM_SETPOS, (WPARAM)(int)(100), 0);
+ UpdateWindow(progress_dialog);
+ DBWriteContactSettingDword(0, "AutoBackups", "LastBackupTimestamp", (DWORD)time(0));
+ if(!options.disable_popups)
+ {
+ dest_file_len = lstrlen(dest_file);
+ if(dest_file_len > 50)
+ {
+ puText = mir_alloc(sizeof(TCHAR) * (dest_file_len + 2));
+ for(i = (int)dest_file_len - 1; dest_file[i] != _T('\\'); i--);
+
+ lstrcpyn(puText, dest_file, i + 2);
+ lstrcat(puText, _T("\n"));
+ lstrcat(puText, dest_file + i + 1);
+ }
+ else
+ puText = mir_tstrdup(dest_file);
+
+ ShowPopup(puText, TranslateT("Database backuped"));
+ mir_free(puText);
+ }
+ }
+ else
+ DeleteFile(dest_file);
+ mir_free(pathtmp);
+
+ DestroyWindow(progress_dialog);
+ return 0;
+}
+
+VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) {
+ time_t t = time(0), diff = t - (time_t)DBGetContactSettingDword(0, "AutoBackups", "LastBackupTimestamp", (DWORD)t);
+ if(diff > (time_t)(options.period * (options.period_type == PT_MINUTES ? 60 : (options.period_type == PT_HOURS ? 60 * 60 : 60 * 60 * 24 ) )))
+ Backup(NULL);
+}
+
+int SetBackupTimer(void)
+{
+ if(options.backup_types & BT_PERIODIC)
+ {
+ if(timer_id == 0)
+ timer_id = SetTimer(0, 0, 1000 * 60, TimerProc);
+ }
+ else if(timer_id != 0)
+ {
+ KillTimer(0, timer_id);
+ timer_id = 0;
+ }
+ return 0;
+}
+
+INT_PTR ABService(WPARAM wParam, LPARAM lParam)
+{
+ Backup((TCHAR*)wParam);
+ return 0;
+}
diff --git a/plugins/Db_autobackups/db_autobackups.rc b/plugins/Db_autobackups/db_autobackups.rc new file mode 100644 index 0000000000..714f4a3505 --- /dev/null +++ b/plugins/Db_autobackups/db_autobackups.rc @@ -0,0 +1,182 @@ +// Microsoft Visual C++ generated resource script.
+//
+#include "resource.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#include <winres.h>
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// Russian resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
+#ifdef _WIN32
+LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
+#pragma code_page(1251)
+#endif //_WIN32
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Dialog
+//
+
+IDD_COPYPROGRESS DIALOGEX 0, 0, 186, 58
+STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER |
+ WS_POPUP | WS_VISIBLE | WS_CAPTION
+CAPTION "Backup progress"
+FONT 8, "MS Shell Dlg", 400, 0, 0x1
+BEGIN
+ CONTROL "",IDC_PROGRESS,"msctls_progress32",WS_BORDER,7,24,172,9
+ CTEXT "",IDC_PROGRESSMESSAGE,31,7,114,13
+ PUSHBUTTON "Cancel",IDCANCEL,58,39,67,12
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// DESIGNINFO
+//
+
+#ifdef APSTUDIO_INVOKED
+GUIDELINES DESIGNINFO
+BEGIN
+ IDD_COPYPROGRESS, DIALOG
+ BEGIN
+ LEFTMARGIN, 7
+ RIGHTMARGIN, 179
+ TOPMARGIN, 7
+ BOTTOMMARGIN, 51
+ END
+END
+#endif // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Icon
+//
+
+// Icon with lowest ID value placed first to ensure application icon
+// remains consistent on all systems.
+IDI_ICON1 ICON "icos\\backup.ico"
+#endif // Russian resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+/////////////////////////////////////////////////////////////////////////////
+// English (U.S.) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
+#ifdef _WIN32
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+#pragma code_page(1252)
+#endif //_WIN32
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Dialog
+//
+
+IDD_OPTIONS DIALOGEX 0, 0, 271, 193
+STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_CHILD
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ GROUPBOX "Automatic Backups",IDC_STATIC,6,7,258,179,WS_GROUP
+ RTEXT "Number of backups to keep:",IDC_STATIC,13,94,132,8
+ EDITTEXT IDC_ED_NUMBACKUPS,164,90,30,12,ES_NUMBER,WS_EX_RIGHT
+ CONTROL "",SPIN_NUMBACKUPS,"msctls_updown32",UDS_SETBUDDYINT |
+ UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS,182,90,10,
+ 12
+ PUSHBUTTON "Backup NOW",IDC_BUT_NOW,173,19,75,14
+ CONTROL "Disabled",IDC_RAD_DISABLED,"Button",BS_AUTOCHECKBOX |
+ WS_TABSTOP,17,19,128,10
+ CONTROL "When Miranda starts",IDC_RAD_START,"Button",
+ BS_AUTOCHECKBOX | WS_TABSTOP,17,35,156,10
+ CONTROL "When Miranda exits",IDC_RAD_EXIT,"Button",
+ BS_AUTOCHECKBOX | WS_TABSTOP,17,51,156,10
+ CONTROL "Every:",IDC_RAD_PERIODIC,"Button",BS_AUTOCHECKBOX |
+ WS_TABSTOP,17,67,43,10
+ COMBOBOX IDC_PT,148,67,46,30,CBS_DROPDOWNLIST | WS_TABSTOP
+ EDITTEXT IDC_ED_PERIOD,106,67,30,12,ES_NUMBER,WS_EX_RIGHT
+ CONTROL "",SPIN_PERIOD,"msctls_updown32",UDS_SETBUDDYINT |
+ UDS_ALIGNRIGHT | UDS_AUTOBUDDY | UDS_ARROWKEYS,126,67,10,
+ 12
+ LTEXT "Backup to folder:",IDC_STATIC,18,120,124,11
+ EDITTEXT IDC_ED_FOLDER,26,133,168,13,ES_AUTOHSCROLL
+ PUSHBUTTON "Browse...",IDC_BUT_BROWSE,199,132,49,14
+ CONTROL "Go to the ""Customize -> Folders"" to change settings",
+ IDC_LNK_FOLDERS,"Hyperlink",NOT WS_VISIBLE | WS_TABSTOP,
+ 18,129,231,21
+ CONTROL "Disable progress bar",IDC_CHK_NOPROG,"Button",
+ BS_AUTOCHECKBOX | WS_TABSTOP,17,152,182,11
+ CONTROL "Disable Popups",IDC_CHK_NOPOPUP,"Button",
+ BS_AUTOCHECKBOX | WS_TABSTOP,17,168,182,11
+END
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// DESIGNINFO
+//
+
+#ifdef APSTUDIO_INVOKED
+GUIDELINES DESIGNINFO
+BEGIN
+ IDD_OPTIONS, DIALOG
+ BEGIN
+ LEFTMARGIN, 6
+ RIGHTMARGIN, 264
+ VERTGUIDE, 17
+ VERTGUIDE, 193
+ VERTGUIDE, 248
+ TOPMARGIN, 38
+ BOTTOMMARGIN, 186
+ END
+END
+#endif // APSTUDIO_INVOKED
+
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE
+BEGIN
+ "resource.h\0"
+END
+
+2 TEXTINCLUDE
+BEGIN
+ "#include <winres.h>\0"
+END
+
+3 TEXTINCLUDE
+BEGIN
+ "\r\n"
+ "\0"
+END
+
+#endif // APSTUDIO_INVOKED
+
+#endif // English (U.S.) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+
+
+/////////////////////////////////////////////////////////////////////////////
+#endif // not APSTUDIO_INVOKED
+
diff --git a/plugins/Db_autobackups/db_autobackups_10.vcxproj b/plugins/Db_autobackups/db_autobackups_10.vcxproj new file mode 100644 index 0000000000..7b20970df4 --- /dev/null +++ b/plugins/Db_autobackups/db_autobackups_10.vcxproj @@ -0,0 +1,183 @@ +<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <ProjectName>Db_autobackups</ProjectName>
+ <ProjectGuid>{751ED05D-AD3E-4EC6-A485-4ECDF1FE6068}</ProjectGuid>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <CharacterSet>Unicode</CharacterSet>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <CharacterSet>Unicode</CharacterSet>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup>
+ <_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\Plugins\</OutDir>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)$(Configuration)64\Plugins\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\Obj\$(ProjectName)\</IntDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(SolutionDir)$(Configuration)64\Obj\$(ProjectName)\</IntDir>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\Plugins\</OutDir>
+ <OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)$(Configuration)64\Plugins\</OutDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\Obj\$(ProjectName)\</IntDir>
+ <IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(SolutionDir)$(Configuration)64\Obj\$(ProjectName)\</IntDir>
+ <IgnoreImportLibrary Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</IgnoreImportLibrary>
+ <IgnoreImportLibrary Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</IgnoreImportLibrary>
+ <IgnoreImportLibrary Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</IgnoreImportLibrary>
+ <IgnoreImportLibrary Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</IgnoreImportLibrary>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <Optimization>Disabled</Optimization>
+ <AdditionalIncludeDirectories>..\..\include;..\ExternalAPI;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;DB_AUTOBACKUPS_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <MinimalRebuild>true</MinimalRebuild>
+ <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+ <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+ <WarningLevel>Level3</WarningLevel>
+ <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <SubSystem>Windows</SubSystem>
+ <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
+ <AdditionalDependencies>comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <RandomizedBaseAddress>false</RandomizedBaseAddress>
+ </Link>
+ <ResourceCompile>
+ <AdditionalIncludeDirectories>..\..\include\msapi</AdditionalIncludeDirectories>
+ </ResourceCompile>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <Optimization>Disabled</Optimization>
+ <AdditionalIncludeDirectories>..\..\include;..\ExternalAPI;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>WIN64;_DEBUG;_WINDOWS;_USRDLL;DB_AUTOBACKUPS_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+ <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
+ <WarningLevel>Level3</WarningLevel>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <SubSystem>Windows</SubSystem>
+ <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
+ <AdditionalDependencies>comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <RandomizedBaseAddress>false</RandomizedBaseAddress>
+ </Link>
+ <ResourceCompile>
+ <AdditionalIncludeDirectories>..\..\include\msapi</AdditionalIncludeDirectories>
+ </ResourceCompile>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <AdditionalIncludeDirectories>..\..\include;..\ExternalAPI;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;DB_AUTOBACKUPS_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+ <WarningLevel>Level3</WarningLevel>
+ <FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
+ <Optimization>Full</Optimization>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <SubSystem>Windows</SubSystem>
+ <OptimizeReferences>true</OptimizeReferences>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
+ <AdditionalDependencies>comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <RandomizedBaseAddress>false</RandomizedBaseAddress>
+ </Link>
+ <ResourceCompile>
+ <AdditionalIncludeDirectories>..\..\include\msapi</AdditionalIncludeDirectories>
+ </ResourceCompile>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <AdditionalIncludeDirectories>..\..\include;..\ExternalAPI;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+ <PreprocessorDefinitions>WIN64;NDEBUG;_WINDOWS;_USRDLL;DB_AUTOBACKUPS_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Full</Optimization>
+ <InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
+ <FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
+ </ClCompile>
+ <Link>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <SubSystem>Windows</SubSystem>
+ <OptimizeReferences>true</OptimizeReferences>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <ImportLibrary>$(IntDir)$(TargetName).lib</ImportLibrary>
+ <AdditionalDependencies>comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <RandomizedBaseAddress>false</RandomizedBaseAddress>
+ </Link>
+ <ResourceCompile>
+ <AdditionalIncludeDirectories>..\..\include\msapi</AdditionalIncludeDirectories>
+ </ResourceCompile>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="backup.c" />
+ <ClCompile Include="options.c" />
+ <ClCompile Include="main.c" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="headers.h" />
+ <ClInclude Include="options.h" />
+ <ClInclude Include="resource.h" />
+ <ClInclude Include="version.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="icos\backup.ico" />
+ </ItemGroup>
+ <ItemGroup>
+ <ResourceCompile Include="db_autobackups.rc" />
+ <ResourceCompile Include="version.rc" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
\ No newline at end of file diff --git a/plugins/Db_autobackups/db_autobackups_10.vcxproj.filters b/plugins/Db_autobackups/db_autobackups_10.vcxproj.filters new file mode 100644 index 0000000000..964916d73a --- /dev/null +++ b/plugins/Db_autobackups/db_autobackups_10.vcxproj.filters @@ -0,0 +1,55 @@ +<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup>
+ <Filter Include="Source Files">
+ <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
+ <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
+ </Filter>
+ <Filter Include="Header Files">
+ <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
+ <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
+ </Filter>
+ <Filter Include="Resource Files">
+ <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
+ <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav</Extensions>
+ </Filter>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="backup.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="options.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="main.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="headers.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="options.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="resource.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="version.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ </ItemGroup>
+ <ItemGroup>
+ <None Include="icos\backup.ico">
+ <Filter>Resource Files</Filter>
+ </None>
+ </ItemGroup>
+ <ItemGroup>
+ <ResourceCompile Include="db_autobackups.rc">
+ <Filter>Resource Files</Filter>
+ </ResourceCompile>
+ <ResourceCompile Include="version.rc">
+ <Filter>Resource Files</Filter>
+ </ResourceCompile>
+ </ItemGroup>
+</Project>
\ No newline at end of file diff --git a/plugins/Db_autobackups/icos/backup.ico b/plugins/Db_autobackups/icos/backup.ico Binary files differnew file mode 100644 index 0000000000..2bd78218d8 --- /dev/null +++ b/plugins/Db_autobackups/icos/backup.ico diff --git a/plugins/Db_autobackups/main.c b/plugins/Db_autobackups/main.c new file mode 100644 index 0000000000..7390bd9dc7 --- /dev/null +++ b/plugins/Db_autobackups/main.c @@ -0,0 +1,262 @@ +#include "headers.h"
+#include "version.h"
+#include "m_trigger.h"
+
+struct MM_INTERFACE mmi;
+HINSTANCE hInst;
+PLUGINLINK *pluginLink;
+int hLangpack;
+
+HANDLE hFolder;
+HANDLE hHooks[4];
+HANDLE hServices[3];
+
+PLUGININFOEX pluginInfo={
+ sizeof(PLUGININFOEX),
+ __PLUGIN_NAME,
+ __VERSION_DWORD,
+ __PLUGIN_DESC,
+ "chaos.persei, sje, Kildor, Billy_Bons",
+ "chaos.persei@gmail.com",
+ __COPYRIGHTS,
+ "http://mods.mirandaim.ru/",
+ UNICODE_AWARE,
+ 0, //doesn't replace anything built-in
+ // Generate your own unique id for your plugin.
+ // Do not use this UUID!
+ // Use uuidgen.exe to generate the uuuid
+ // {81C220A6-0226-4ad6-BFCA-217B17A16053}
+ { 0x81c220a6, 0x226, 0x4ad6, { 0xbf, 0xca, 0x21, 0x7b, 0x17, 0xa1, 0x60, 0x53 } }
+};
+
+#define MIID_DB_AUTOBACKUPS { 0x81c220a6, 0x226, 0x4ad6, { 0xbf, 0xca, 0x21, 0x7b, 0x17, 0xa1, 0x60, 0x53 } }
+
+struct
+{
+ TCHAR* szDescr;
+ char* szName;
+ int defIconID;
+}
+static const iconList[] = {
+ { _T("Backup Profile"), "backup", IDI_ICON1 },
+ { _T("Save Profile As..."), "saveas", IDI_ICON1 }
+};
+
+INT_PTR BackupServiceTrgr(WPARAM wParam, LPARAM lParam)
+{
+ if(wParam & ACT_PERFORM) {
+ return Backup(NULL);
+ }
+ return 0;
+}
+
+static int FoldersGetBackupPath(WPARAM wParam, LPARAM lParam)
+{
+ FoldersGetCustomPathT(hFolder, options.folder, MAX_PATH, DIR SUB_DIR);
+ return 0;
+}
+
+static int FoldersInit(void)
+{
+ hFolder = (HANDLE) FoldersRegisterCustomPathT("Database Backups", "Backup Folder", DIR SUB_DIR);
+ hHooks[0] = HookEvent(ME_FOLDERS_PATH_CHANGED, FoldersGetBackupPath);
+ FoldersGetBackupPath(0, 0);
+ return 0;
+}
+
+static void IcoLibInit(void)
+{
+ int i;
+ SKINICONDESC sid = {0};
+ TCHAR tszFile[MAX_PATH];
+ GetModuleFileName(hInst, tszFile, MAX_PATH);
+
+ sid.cbSize = sizeof(SKINICONDESC);
+ sid.ptszDefaultFile = tszFile;
+ sid.ptszSection = _T("Database/Database Backups");
+ sid.flags = SIDF_ALL_TCHAR;
+
+ for ( i = 0; i < SIZEOF(iconList); i++ ) {
+ sid.pszName = iconList[i].szName;
+ sid.ptszDescription = iconList[i].szDescr;
+ sid.iDefaultIndex = -iconList[i].defIconID;
+ CallService(MS_SKIN2_ADDICON, 0, (LPARAM)&sid);
+ }
+}
+
+static void MenuInit(void)
+{
+ CLISTMENUITEM menu = {0};
+ menu.cbSize = sizeof(menu);
+ menu.flags = CMIF_TCHAR;
+ menu.hIcon=(HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"backup");
+ menu.ptszPopupName = LPGENT("Database");
+
+ menu.ptszName = LPGENT("Backup Profile");
+ menu.pszService = MS_AB_BACKUP;
+ menu.position = 500100000;
+ CallService(MS_CLIST_ADDMAINMENUITEM,0,(LPARAM)&menu);
+
+ menu.hIcon=(HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"saveas");
+ menu.ptszName = LPGENT("Save Profile As...");
+ menu.pszService = MS_AB_SAVEAS;
+ menu.position = 500100001;
+ CallService(MS_CLIST_ADDMAINMENUITEM,0,(LPARAM)&menu);
+}
+
+static void TriggerActionInit(void)
+{
+ ACTIONREGISTER ar = {0};
+ ar.cbSize = sizeof(ACTIONREGISTER);
+ ar.pszName = "Backup Database";
+ ar.pszService = MS_AB_BACKUPTRGR;
+
+ CallService(MS_TRIGGER_REGISTERACTION, 0, (LPARAM)&ar);
+}
+
+static int ModulesLoad(WPARAM wParam, LPARAM lParam)
+{
+ profilePath = Utils_ReplaceVarsT(_T("%miranda_userdata%"));
+
+ IcoLibInit();
+ if(ServiceExists(MS_FOLDERS_REGISTER_PATH))
+ FoldersInit();
+ LoadOptions();
+ MenuInit();
+
+ // register trigger action for triggerplugin
+ if(ServiceExists(MS_TRIGGER_REGISTERACTION))
+ TriggerActionInit();
+
+ hHooks[1] = HookEvent(ME_OPT_INITIALISE, OptionsInit);
+ if(options.backup_types & BT_START)
+ Backup(NULL);
+ return 0;
+}
+
+// can't do this on unload, since other plugins will be have already been unloaded, but their hooks
+// for setting changed event not cleared. the backup on exit function will write to the db, calling those hooks.
+int PreShutdown(WPARAM wParam, LPARAM lParam) {
+ if(options.backup_types & BT_EXIT)
+ {
+ options.disable_popups = 1; // Don't try to show popups on exit
+ Backup(NULL);
+ }
+ return 0;
+}
+
+void SysInit()
+{
+ mir_getMMI( &mmi );
+ mir_getLP( &pluginInfo );
+ OleInitialize(0);
+
+ hServices[0] = CreateServiceFunction(MS_AB_BACKUP, ABService);
+ hServices[1] = CreateServiceFunction(MS_AB_BACKUPTRGR, BackupServiceTrgr);
+ hServices[2] = CreateServiceFunction(MS_AB_SAVEAS, DBSaveAs);
+
+ hHooks[2] = HookEvent(ME_SYSTEM_PRESHUTDOWN, PreShutdown);
+ hHooks[3] = HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoad);
+}
+
+BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved)
+{
+ hInst=hinstDLL;
+ return TRUE;
+}
+
+__declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
+{
+ if ( mirandaVersion < PLUGIN_MAKE_VERSION(0,8,1,0)) {
+ MessageBox( NULL, _T("The ") _T(__PLUGIN_NAME_BASE) _T(" plugin cannot be loaded. It requires Miranda IM 0.8.1 or later."), _T(__PLUGIN_NAME_BASE), MB_OK|MB_ICONWARNING|MB_SETFOREGROUND|MB_TOPMOST );
+ return NULL;
+ }
+ return &pluginInfo;
+}
+
+static const MUUID interfaces[] = {MIID_DB_AUTOBACKUPS, MIID_LAST};
+__declspec(dllexport) const MUUID* MirandaPluginInterfaces(void)
+{
+ return interfaces;
+}
+
+int __declspec(dllexport) Load(PLUGINLINK *link)
+{
+ pluginLink=link;
+ SysInit();
+ return 0;
+}
+
+int __declspec(dllexport) Unload(void)
+{
+ int i;
+
+ OleUninitialize();
+
+ for (i=0; i<SIZEOF(hHooks); ++i)
+ {
+ if (hHooks[i])
+ UnhookEvent(hHooks[i]);
+ }
+ for (i=0; i<SIZEOF(hServices); ++i)
+ {
+ if (hServices[i])
+ DestroyServiceFunction(hServices[i]);
+ }
+
+ return 0;
+}
+
+void ShowPopup(TCHAR* text, TCHAR* header)
+{
+ POPUPDATAT ppd = {0};
+
+ lstrcpy(ppd.lptzText, text);
+ lstrcpy(ppd.lptzContactName, header);
+ ppd.lchIcon = (HICON)CallService(MS_SKIN2_GETICON, 0, (LPARAM)"backup");
+
+ PUAddPopUpT(&ppd);
+}
+
+int CreateDirectoryTree(TCHAR *szDir)
+{
+ TCHAR *pszLastBackslash, szTestDir[ MAX_PATH ];
+
+ lstrcpyn( szTestDir, szDir, SIZEOF( szTestDir ));
+ pszLastBackslash = _tcsrchr( szTestDir, '\\' );
+ if ( pszLastBackslash == NULL )
+ return 0;
+
+ *pszLastBackslash = '\0';
+ CreateDirectoryTree( szTestDir );
+ *pszLastBackslash = '\\';
+ return ( CreateDirectory( szTestDir, NULL ) == 0 ) ? GetLastError() : 0;
+}
+
+HWND CreateToolTip(HWND hwndParent, LPTSTR ptszText, LPTSTR ptszTitle)
+{
+ TOOLINFO ti = { 0 };
+ HWND hwndTT;
+ hwndTT = CreateWindowEx(WS_EX_TOPMOST,
+ TOOLTIPS_CLASS, NULL,
+ WS_POPUP | TTS_NOPREFIX,
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ hwndParent, NULL, hInst, NULL);
+
+ SetWindowPos(hwndTT, HWND_TOPMOST, 0, 0, 0, 0,
+ SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
+
+ ti.cbSize = sizeof(TOOLINFO);
+ ti.uFlags = TTF_SUBCLASS | TTF_CENTERTIP;
+ ti.hwnd = hwndParent;
+ ti.hinst = hInst;
+ ti.lpszText = ptszText;
+ GetClientRect (hwndParent, &ti.rect);
+ ti.rect.left -= 80;
+
+ SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
+ SendMessage(hwndTT, TTM_SETTITLE, 1, (LPARAM)ptszTitle);
+ SendMessage(hwndTT, TTM_SETMAXTIPWIDTH, 0, (LPARAM)700);
+ return hwndTT;
+}
diff --git a/plugins/Db_autobackups/options.c b/plugins/Db_autobackups/options.c new file mode 100644 index 0000000000..51baa1b687 --- /dev/null +++ b/plugins/Db_autobackups/options.c @@ -0,0 +1,360 @@ +#include "headers.h"
+#include <shlobj.h>
+
+Options options;
+static HWND hPathTip;
+
+int LoadOptions(void) {
+ DBVARIANT dbv;
+ TCHAR* tmp;
+
+ options.backup_types = (BackupType)DBGetContactSettingByte(0, "AutoBackups", "BackupType", (BYTE)(BT_PERIODIC));
+ options.period = (unsigned int)DBGetContactSettingWord(0, "AutoBackups", "Period", 1);
+ options.period_type = (PeriodType)DBGetContactSettingByte(0, "AutoBackups", "PeriodType", (BYTE)PT_DAYS);
+
+ if(!ServiceExists(MS_FOLDERS_GET_PATH)) {
+
+ if(!DBGetContactSettingTString(0, "AutoBackups", "Folder", &dbv)) {
+ tmp = Utils_ReplaceVarsT(dbv.ptszVal);
+
+ if(_tcslen(tmp) >= 2 && tmp[1] == ':')
+ _tcsncpy(options.folder, dbv.ptszVal, MAX_PATH-1);
+ else
+ mir_sntprintf(options.folder, MAX_PATH, _T("%s\\%s"), profilePath, dbv.ptszVal);
+
+ DBFreeVariant(&dbv);
+ mir_free(tmp);
+ } else
+ mir_sntprintf(options.folder, MAX_PATH, _T("%s%s"), DIR, SUB_DIR);
+ }
+ options.num_backups = (unsigned int)DBGetContactSettingWord(0, "AutoBackups", "NumBackups", 3);
+
+ options.disable_progress = (BOOL)DBGetContactSettingByte(0, "AutoBackups", "NoProgress", 0);
+ options.disable_popups = (BOOL)DBGetContactSettingByte(0, "AutoBackups", "NoPopups", 0);
+
+ SetBackupTimer();
+ return 0;
+}
+
+int SaveOptions(void) {
+ TCHAR prof_dir[MAX_PATH];
+ TCHAR* buf,* tmp;
+ size_t prof_len, opt_len;
+
+ DBWriteContactSettingByte(0, "AutoBackups", "BackupType", (BYTE)options.backup_types);
+ if (options.period < 1) options.period = 1;
+ DBWriteContactSettingWord(0, "AutoBackups", "Period", (WORD)options.period);
+ DBWriteContactSettingByte(0, "AutoBackups", "PeriodType", (BYTE)options.period_type);
+
+ mir_sntprintf(prof_dir, MAX_PATH, _T("%s\\"), profilePath);
+ prof_len = _tcslen(prof_dir);
+ opt_len = _tcslen(options.folder);
+
+ if(opt_len > prof_len && _tcsncmp(options.folder, prof_dir, prof_len) == 0) {
+ DBWriteContactSettingTString(0, "AutoBackups", "Folder", (options.folder + prof_len));
+ } else
+ DBWriteContactSettingTString(0, "AutoBackups", "Folder", options.folder);
+
+ tmp = Utils_ReplaceVarsT(options.folder);
+ if(_tcslen(tmp) < 2 || tmp[1] != ':')
+ {
+ buf = mir_tstrdup(options.folder);
+ mir_sntprintf(options.folder, MAX_PATH, _T("%s\\%s"), profilePath, buf);
+ mir_free(buf);
+ }
+ mir_free(tmp);
+ DBWriteContactSettingWord(0, "AutoBackups", "NumBackups", (WORD)options.num_backups);
+ DBWriteContactSettingByte(0, "AutoBackups", "NoProgress", (BYTE)options.disable_progress);
+ DBWriteContactSettingByte(0, "AutoBackups", "NoPopups", (BYTE)options.disable_popups);
+
+ SetBackupTimer();
+ return 0;
+}
+
+Options new_options;
+
+int SetDlgState(HWND hwndDlg) {
+ TCHAR buff[10];
+
+ if(new_options.backup_types == BT_DISABLED) {
+ CheckDlgButton(hwndDlg, IDC_RAD_DISABLED, BST_CHECKED);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_RAD_DISABLED), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_ED_NUMBACKUPS), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_ED_FOLDER), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BUT_BROWSE), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_LNK_FOLDERS), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_NOPROG), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_NOPOPUP), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_ED_PERIOD), FALSE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_PT), FALSE);
+
+ CheckDlgButton(hwndDlg, IDC_RAD_START, BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_RAD_EXIT, BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_RAD_PERIODIC, BST_UNCHECKED);
+ } else {
+ EnableWindow(GetDlgItem(hwndDlg, IDC_RAD_DISABLED), TRUE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_ED_NUMBACKUPS), TRUE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_ED_FOLDER), TRUE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_BUT_BROWSE), TRUE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_LNK_FOLDERS), TRUE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_NOPROG), TRUE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_CHK_NOPOPUP), TRUE);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_ED_PERIOD), new_options.backup_types & BT_PERIODIC);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_PT), new_options.backup_types & BT_PERIODIC);
+
+ CheckDlgButton(hwndDlg, IDC_RAD_DISABLED, BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_RAD_START, new_options.backup_types & BT_START ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_RAD_EXIT, new_options.backup_types & BT_EXIT ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_RAD_PERIODIC, new_options.backup_types & BT_PERIODIC ? BST_CHECKED : BST_UNCHECKED);
+ }
+
+ SendDlgItemMessage(hwndDlg, SPIN_PERIOD, UDM_SETRANGE32, (WPARAM)1, (LPARAM)60);
+ SetDlgItemText(hwndDlg, IDC_ED_PERIOD, _itot(new_options.period, buff, 10));
+
+ SendDlgItemMessage(hwndDlg, SPIN_NUMBACKUPS, UDM_SETRANGE32, (WPARAM)1, (LPARAM)100);
+ SetDlgItemText(hwndDlg, IDC_ED_NUMBACKUPS, _itot(new_options.num_backups, buff, 10));
+
+ SetDlgItemText(hwndDlg, IDC_ED_FOLDER, new_options.folder);
+
+ CheckDlgButton(hwndDlg, IDC_CHK_NOPROG, new_options.disable_progress ? BST_CHECKED : BST_UNCHECKED);
+ CheckDlgButton(hwndDlg, IDC_CHK_NOPOPUP, new_options.disable_popups ? BST_CHECKED : BST_UNCHECKED);
+ if (!ServiceExists(MS_POPUP_ADDPOPUP))
+ ShowWindow(GetDlgItem(hwndDlg, IDC_CHK_NOPOPUP), SW_HIDE);
+
+ return 0;
+}
+
+int CALLBACK BrowseProc(HWND hwnd,UINT uMsg, LPARAM lParam, LPARAM lpData )
+{
+ TCHAR* folder;
+ switch(uMsg)
+ {
+ case BFFM_INITIALIZED:
+ folder = Utils_ReplaceVarsT(options.folder);
+ SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)folder);
+ mir_free(folder);
+ break;
+ }
+ return 0;
+}
+
+INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ TCHAR buff[10];
+ TCHAR folder_buff[MAX_PATH] = {0}, backupfolder[MAX_PATH] = {0};
+ TCHAR tszTooltipText[1024];
+ TCHAR* tmp;
+ BROWSEINFO bi;
+ LPCITEMIDLIST pidl;
+ OPENOPTIONSDIALOG ood = {0};
+
+ switch ( msg ) {
+ case WM_INITDIALOG:
+ TranslateDialogDefault( hwndDlg );
+ memcpy(&new_options, &options, sizeof(Options));
+
+ if (ServiceExists(MS_FOLDERS_GET_PATH))
+ {
+ ShowWindow(GetDlgItem(hwndDlg, IDC_ED_FOLDER), SW_HIDE);
+ ShowWindow(GetDlgItem(hwndDlg, IDC_BUT_BROWSE), SW_HIDE);
+ ShowWindow(GetDlgItem(hwndDlg, IDC_LNK_FOLDERS), SW_SHOW);
+ }
+ else
+ {
+ mir_sntprintf(tszTooltipText, SIZEOF(tszTooltipText), _T("%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s"),
+ _T("%miranda_path%"), TranslateT("path to root miranda folder"),
+ _T("%miranda_profile%"), TranslateT("path to current miranda profile"),
+ _T("%miranda_profilename%"), TranslateT("name of current miranda profile (filename, without extension)"),
+ _T("%miranda_userdata%"), TranslateT("will return parsed string %miranda_profile%\\Profiles\\%miranda_profilename%"),
+ _T("%appdata%"), TranslateT("same as environment variable %APPDATA% for currently logged-on Windows user"),
+ _T("%username%"), TranslateT("username for currently logged-on Windows user"),
+ _T("%mydocuments%"), TranslateT("\"My Documents\" folder for currently logged-on Windows user"),
+ _T("%desktop%"), TranslateT("\"Desktop\" folder for currently logged-on Windows user"),
+ _T("%xxxxxxx%"), TranslateT("any environment variable defined in current Windows session (like %systemroot%, %allusersprofile%, etc.)")
+ );
+ hPathTip = CreateToolTip(GetDlgItem(hwndDlg, IDC_ED_FOLDER), tszTooltipText, TranslateT("Variables"));
+ }
+
+ SetDlgState(hwndDlg);
+
+ SendMessage(GetDlgItem(hwndDlg, IDC_PT), CB_ADDSTRING, 0, (LPARAM) TranslateT("Days"));
+ SendMessage(GetDlgItem(hwndDlg, IDC_PT), CB_ADDSTRING, 0, (LPARAM) TranslateT("Hours"));
+ SendMessage(GetDlgItem(hwndDlg, IDC_PT), CB_ADDSTRING, 0, (LPARAM) TranslateT("Minutes"));
+ switch(new_options.period_type){
+ case PT_DAYS: SendDlgItemMessage(hwndDlg, IDC_PT, CB_SETCURSEL, 0, 0); break;
+ case PT_HOURS: SendDlgItemMessage(hwndDlg, IDC_PT, CB_SETCURSEL, 1, 0); break;
+ case PT_MINUTES: SendDlgItemMessage(hwndDlg, IDC_PT, CB_SETCURSEL, 2, 0); break;
+ }
+ if (hPathTip)
+ SetTimer(hwndDlg, 0, 3000, NULL);
+ return TRUE;
+ case WM_COMMAND:
+ if ( HIWORD( wParam ) == EN_CHANGE && ( HWND )lParam == GetFocus()) {
+ switch( LOWORD( wParam )) {
+ case IDC_ED_PERIOD:
+ case IDC_ED_FOLDER:
+ case IDC_ED_NUMBACKUPS:
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ }
+ }
+ if ( HIWORD( wParam ) == CBN_SELCHANGE) {
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ }
+ if ( HIWORD( wParam ) == BN_CLICKED ) {
+ switch( LOWORD( wParam )) {
+ case IDC_RAD_DISABLED:
+ if(IsDlgButtonChecked(hwndDlg, IDC_RAD_DISABLED)) {
+ new_options.backup_types = BT_DISABLED;
+ }
+ SetDlgState(hwndDlg);
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ break;
+ case IDC_RAD_START:
+ if(IsDlgButtonChecked(hwndDlg, IDC_RAD_START))
+ new_options.backup_types |= BT_START;
+ else
+ new_options.backup_types &= ~BT_START;
+ SetDlgState(hwndDlg);
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ break;
+ case IDC_RAD_EXIT:
+ if(IsDlgButtonChecked(hwndDlg, IDC_RAD_EXIT))
+ new_options.backup_types |= BT_EXIT;
+ else
+ new_options.backup_types &= ~BT_EXIT;
+ SetDlgState(hwndDlg);
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ break;
+ case IDC_RAD_PERIODIC:
+ if(IsDlgButtonChecked(hwndDlg, IDC_RAD_PERIODIC))
+ new_options.backup_types |= BT_PERIODIC;
+ else
+ new_options.backup_types &= ~BT_PERIODIC;
+ SetDlgState(hwndDlg);
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ break;
+
+ case IDC_BUT_BROWSE:
+ bi.hwndOwner = hwndDlg;
+ bi.pidlRoot = 0;
+ bi.pszDisplayName = folder_buff;
+ bi.lpszTitle = TranslateT("Select Backup Folder");
+ bi.ulFlags = BIF_NEWDIALOGSTYLE;
+ bi.lpfn = BrowseProc;
+ bi.lParam = 0;
+ bi.iImage = 0;
+
+ if((pidl = SHBrowseForFolder(&bi)) != 0) {
+ SHGetPathFromIDList(pidl, folder_buff);
+
+ SetDlgItemText(hwndDlg, IDC_ED_FOLDER, folder_buff);
+
+ SendMessage( GetParent( hwndDlg ), PSM_CHANGED, 0, 0 );
+
+ CoTaskMemFree((void *)pidl);
+ }
+ break;
+ case IDC_BUT_NOW:
+ Backup(NULL);
+ break;
+ case IDC_CHK_NOPROG:
+ new_options.disable_progress = IsDlgButtonChecked(hwndDlg, IDC_CHK_NOPROG);
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ break;
+ case IDC_CHK_NOPOPUP:
+ new_options.disable_popups = IsDlgButtonChecked(hwndDlg, IDC_CHK_NOPOPUP);
+ SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0);
+ break;
+ case IDC_LNK_FOLDERS:
+ ood.cbSize = sizeof(ood);
+ ood.pszGroup = "Customize";
+ ood.pszPage = "Folders";
+ CallService( MS_OPT_OPENOPTIONS, 0, (LPARAM)&ood );
+ break;
+ }
+ }
+
+ break;
+
+ case WM_TIMER:
+ if(IsWindow(hPathTip))
+ KillTimer(hPathTip, 4); // It will prevent tooltip autoclosing
+ break;
+
+ case WM_NOTIFY:
+ if (((LPNMHDR)lParam)->code == PSN_APPLY ) {
+ GetDlgItemText(hwndDlg, IDC_ED_PERIOD, buff, sizeof(buff));
+ new_options.period = _ttoi(buff);
+ GetDlgItemText(hwndDlg, IDC_ED_NUMBACKUPS, buff, sizeof(buff));
+ new_options.num_backups = _ttoi(buff);
+
+ switch(SendDlgItemMessage(hwndDlg, IDC_PT, CB_GETCURSEL, 0, 0)) {
+ case 0: new_options.period_type = PT_DAYS; break;
+ case 1: new_options.period_type = PT_HOURS; break;
+ case 2: new_options.period_type = PT_MINUTES; break;
+ }
+
+ GetDlgItemText(hwndDlg, IDC_ED_FOLDER, folder_buff, MAX_PATH);
+ {
+ BOOL folder_ok = TRUE;
+ int err = 0;
+ tmp = Utils_ReplaceVarsT(folder_buff);
+
+ if(_tcslen(tmp) >= 2 && tmp[1] == ':')
+ _tcsncpy(backupfolder, tmp, MAX_PATH-1);
+ else
+ mir_sntprintf(backupfolder, MAX_PATH, _T("%s\\%s"), profilePath, tmp);
+ mir_free(tmp);
+
+ err = CreateDirectoryTree(backupfolder);
+ if(err != ERROR_ALREADY_EXISTS && err != 0) {
+ TCHAR msg_buff[512];
+ FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, err, 0, msg_buff, 512, 0);
+ MessageBox(0, msg_buff, TranslateT("Error Creating Backup Folder"), MB_OK | MB_ICONERROR);
+ folder_ok = FALSE;
+ }
+
+ if(folder_ok) {
+ _tcsncpy(new_options.folder, folder_buff, MAX_PATH-1);
+ memcpy(&options, &new_options, sizeof(Options));
+ SaveOptions();
+ } else {
+ memcpy(&new_options, &options, sizeof(Options));
+ SetDlgState(hwndDlg);
+ }
+ }
+ return TRUE;
+
+ }
+ break;
+
+ case WM_DESTROY:
+ if (hPathTip)
+ {
+ KillTimer(hwndDlg, 0);
+ DestroyWindow(hPathTip);
+ hPathTip = 0;
+ }
+ return FALSE;
+ }
+
+ return FALSE;
+}
+
+int OptionsInit(WPARAM wParam, LPARAM lParam)
+{
+ OPTIONSDIALOGPAGE odp;
+
+ ZeroMemory(&odp, sizeof(odp));
+ odp.cbSize = sizeof(odp);
+ odp.position = -790000000;
+ odp.hInstance = hInst;
+ odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS);
+ odp.ptszTitle = LPGENT("Database AutoBackups");
+ odp.ptszGroup = LPGENT("Services");
+ odp.flags = ODPF_BOLDGROUPS | ODPF_TCHAR;
+ odp.pfnDlgProc = DlgProcOptions;
+ CallService( MS_OPT_ADDPAGE, wParam,( LPARAM )&odp );
+
+ return 0;
+}
diff --git a/plugins/Db_autobackups/options.h b/plugins/Db_autobackups/options.h new file mode 100644 index 0000000000..240fc9566e --- /dev/null +++ b/plugins/Db_autobackups/options.h @@ -0,0 +1,37 @@ +/*
+
+Miranda IM: the free IM client for Microsoft* Windows*
+
+Copyright 2000-2003 Miranda ICQ/IM project,
+all portions of this codebase are copyrighted to the people
+listed in contributors.txt.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+typedef enum { BT_DISABLED = 0, BT_START = 1, BT_EXIT = 2, BT_PERIODIC = 4} BackupType;
+typedef enum { PT_DAYS, PT_HOURS, PT_MINUTES} PeriodType;
+
+typedef struct Options_tag {
+ int backup_types;
+ unsigned int period;
+ PeriodType period_type;
+ TCHAR folder[MAX_PATH];
+ unsigned int num_backups;
+ BOOL disable_progress;
+ BOOL disable_popups;
+} Options;
+
+extern Options options;
\ No newline at end of file diff --git a/plugins/Db_autobackups/resource.h b/plugins/Db_autobackups/resource.h new file mode 100644 index 0000000000..fe3f28621c --- /dev/null +++ b/plugins/Db_autobackups/resource.h @@ -0,0 +1,35 @@ +//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ generated include file.
+// Used by db_autobackups.rc
+//
+#define IDD_OPTIONS 101
+#define IDI_ICON1 270
+#define IDD_COPYPROGRESS 271
+#define SPIN_PERIOD 1369
+#define SPIN_NUMBACKUPS 1370
+#define IDC_PT 1371
+#define IDC_ED_PERIOD 1658
+#define IDC_RAD_DISABLED 1660
+#define IDC_RAD_START 1663
+#define IDC_RAD_EXIT 1664
+#define IDC_RAD_PERIODIC 1665
+#define IDC_ED_NUMBACKUPS 1666
+#define IDC_ED_FOLDER 1667
+#define IDC_BUT_BROWSE 1668
+#define IDC_LNK_FOLDERS 1669
+#define IDC_CHK_NOPROG 1670
+#define IDC_BUT_NOW 1671
+#define IDC_CHK_NOPOPUP 1672
+#define IDC_PROGRESSMESSAGE 0xDAED
+#define IDC_PROGRESS 0xDEAD
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE 272
+#define _APS_NEXT_COMMAND_VALUE 40018
+#define _APS_NEXT_CONTROL_VALUE 1673
+#define _APS_NEXT_SYMED_VALUE 101
+#endif
+#endif
diff --git a/plugins/Db_autobackups/resource.rc b/plugins/Db_autobackups/resource.rc new file mode 100644 index 0000000000..42f5b0b55b --- /dev/null +++ b/plugins/Db_autobackups/resource.rc @@ -0,0 +1,2 @@ +#include "db_autobackups.rc"
+#include "version.rc"
diff --git a/plugins/Db_autobackups/version.h b/plugins/Db_autobackups/version.h new file mode 100644 index 0000000000..37c48ddca2 --- /dev/null +++ b/plugins/Db_autobackups/version.h @@ -0,0 +1,16 @@ +#define __FILEVERSION_STRING 0,0,0,8
+#define __VERSION_STRING "0.0.0.8"
+#define __VERSION_DWORD 0x00000008
+
+#define __PLUGIN_NAME_BASE "DB Autobackuper"
+#define __PLUGIN_DESC __PLUGIN_NAME_BASE " plugin."
+#define __COPYRIGHTS "© 2005-2011 chaos.persei, sje, Kildor, Billy_Bons, Vasilich"
+
+#if defined (_WIN64)
+#define __PLUGIN_NAME __PLUGIN_NAME_BASE " (x64)"
+#elif (UNICODE)
+#define __PLUGIN_NAME __PLUGIN_NAME_BASE " (Unicode)"
+#else
+#define __PLUGIN_NAME __PLUGIN_NAME_BASE
+#endif
+
diff --git a/plugins/Db_autobackups/version.rc b/plugins/Db_autobackups/version.rc new file mode 100644 index 0000000000..cd4434c66d --- /dev/null +++ b/plugins/Db_autobackups/version.rc @@ -0,0 +1,39 @@ +
+#include <windows.h>
+#include "version.h"
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Version
+//
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION __FILEVERSION_STRING
+ PRODUCTVERSION __FILEVERSION_STRING
+ FILEFLAGSMASK 0x17L
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x4L
+ FILETYPE 0x2L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "041904b0"
+ BEGIN
+ VALUE "FileDescription", __PLUGIN_DESC
+ VALUE "FileVersion", __VERSION_STRING
+ VALUE "LegalCopyright", __COPYRIGHTS
+ VALUE "OriginalFilename", "db_autobackups.dll"
+ VALUE "ProductName", __PLUGIN_NAME
+ VALUE "ProductVersion", __VERSION_STRING
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x419, 1200
+ END
+END
|