xoblite™ / Blackbox for Windows bb5 | RC6 preview | 0.25.2.14
http://xoblite.net/
PluginManager.h File Reference
#include "..\Settings\Settings.h"
#include "..\Menu\Menu.h"
#include <vector>
#include <string>
#include <windows.h>
#include <stdio.h>
#include <commdlg.h>
#include <wininet.h>
#include <locale.h>

Classes

struct  pluginItem
 
class  PluginManager
 

Typedefs

typedef int(* beginPluginExFunc) (HINSTANCE, HWND)
 
typedef int(* beginPluginFunc) (HINSTANCE)
 
typedef int(* beginSlitPluginFunc) (HINSTANCE, HWND)
 
typedef int(* endPluginFunc) (HINSTANCE)
 
typedef LPCSTR(* pluginInfoFunc) (int)
 
typedef vector< pluginItemPluginsVector
 

Functions

void checkForUpdates (void *param)
 
void periodicCheckForUpdates (void *)
 

Typedef Documentation

◆ beginPluginExFunc

typedef int(* beginPluginExFunc) (HINSTANCE, HWND)

◆ beginPluginFunc

typedef int(* beginPluginFunc) (HINSTANCE)

◆ beginSlitPluginFunc

typedef int(* beginSlitPluginFunc) (HINSTANCE, HWND)

◆ endPluginFunc

typedef int(* endPluginFunc) (HINSTANCE)

◆ pluginInfoFunc

typedef LPCSTR(* pluginInfoFunc) (int)

◆ PluginsVector

typedef vector<pluginItem> PluginsVector

Function Documentation

◆ checkForUpdates()

void checkForUpdates ( void * param)
631{
632 if (pSettings->checkingForUpdates) _endthread();
633 else
634 {
635 // Display "<->" icon in toolbar.windowLabel -> update in progress!
636 pSettings->checkingForUpdates = true;
637// if ((pSettings->toolbarMode == TOOLBAR_MODE_WINDOWLABEL) && pToolbar) pToolbar->UpdateToolbarWindow();
638// SendMessage(GetBBWnd(), BB_CONSOLEMESSAGE, (WPARAM)CONSOLE_REGULAR_MESSAGE, (LPARAM)"xoblite -> Checking for updates...");
639 }
640
641 bool silent = *((bool*)param);
642 int updates = 0;
643 char listOfURLs[MAX_LINE_LENGTH] = "", path[MAX_LINE_LENGTH], msg[MAX_LINE_LENGTH], listOfUpdates[MAX_LINE_LENGTH] = "";
644
645 //====================
646/*
647 // Extract distributed repository URLs from all
648 // plugins that support automatic updating...
649 for (int i=0; i < (int)pPluginManager->pluginList.size(); i++)
650 {
651 pPluginManager->pluginInfo = (pluginInfoFunc)GetProcAddress(pPluginManager->pluginList[i].hModule, "pluginInfo");
652 if (pPluginManager->pluginInfo)
653 {
654 strcpy(msg, pPluginManager->pluginInfo(PLUGIN_UPDATE_URL));
655
656 // Make sure the string supplied by the plugin is a valid URL
657 // and that it isn't the same URL as for the central repository...
658 if (IsInString(msg, "http://") && !IsInString(msg, pSettings->pluginsRepository))
659 {
660 if (!IsInString(listOfURLs, msg))
661 {
662 strcat(listOfURLs, msg);
663 strcat(listOfURLs, " ");
664 }
665 }
666 }
667 }
668*/
669 // Finally, we add the central repository URL at the end of the list
670 // (i.e. if a plugin does not return a URL for automatic updating we fall
671 // back to the central plugin repository defined in xoblite.rc, which means
672 // that the information provided by the distributed repositories
673 // will have precedence in case of duplicate plugin update information! :D )
674 strcat(listOfURLs, pSettings->pluginsRepository);
675
676 //====================
677
678 if (IsInString(listOfURLs, "http://"))
679 {
680 GetBlackboxPath(path, sizeof(path));
681 strcat(path, "update.log");
682
683 if (FileExists(path)) remove(path); // Delete existing update.log file...
684
685 //====================
686
687 if (DownloadFile(listOfURLs, path))
688 {
689 char plugin[MAX_LINE_LENGTH], parameter[MAX_LINE_LENGTH];
690 char onlineVersion[MAX_LINE_LENGTH], currentVersion[MAX_LINE_LENGTH];
691 char onlineDate[MAX_LINE_LENGTH], currentDate[MAX_LINE_LENGTH];
692 char onlineAuthor[MAX_LINE_LENGTH];
693
694 for (int i=0; i < (int)pPluginManager->pluginList.size(); i++)
695 {
696 pPluginManager->pluginInfo = (pluginInfoFunc)GetProcAddress(pPluginManager->pluginList[i].hModule, "pluginInfo");
697 if (pPluginManager->pluginInfo)
698 {
699 strcpy(plugin, pPluginManager->pluginInfo(PLUGIN_NAME));
700 strcpy(currentVersion, pPluginManager->pluginInfo(PLUGIN_VERSION));
701 strcpy(currentDate, pPluginManager->pluginInfo(PLUGIN_RELEASEDATE));
702
703 sprintf(parameter, "%s.version:", plugin);
704 strcpy(onlineVersion, ReadString(path, parameter, ""));
705 if (!strlen(onlineVersion))
706 {
707 // The plugin was not not supported by the specified repository (or invalid syntax)...
708 pPluginManager->pluginList[i].UpdateAvailable = false;
709 continue;
710 }
711 sprintf(parameter, "%s.date:", plugin);
712 strcpy(onlineDate, ReadString(path, parameter, "xxxx-xx-xx"));
713
714 //====================
715
716 // Check if online version/date differs from the current version/date...
717 if (!_stricmp(currentDate, onlineDate))
718 {
719 if (!_stricmp(currentVersion, onlineVersion))
720 {
721 // If not, continue looking...
722 pPluginManager->pluginList[i].UpdateAvailable = false;
723 continue;
724 }
725 }
726
727 // ...but if it differs we have found an updated plugin!
728 pPluginManager->pluginList[i].UpdateAvailable = true;
729
730 sprintf(parameter, "%s.author:", plugin);
731 strcpy(onlineAuthor, ReadString(path, parameter, (LPSTR)pPluginManager->pluginInfo(PLUGIN_AUTHOR)));
732
733 sprintf(msg, "\n%s %s by %s (%s) ", plugin, onlineVersion, onlineAuthor, onlineDate);
734 strcat(listOfUpdates, msg);
735 updates++;
736 }
737 else pPluginManager->pluginList[i].UpdateAvailable = false;
738 }
739 }
740 else
741 {
742 strcpy(msg, "Note: Some repositories were not currently available, \nwhich may affect the result of this check for updates. ");
743 MessageBox(GetBBWnd(), msg, "xoblite", MB_OK | MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST);
744 }
745 }
746
747 //====================
748
749 if (!silent)
750 {
751 char xobVersion[MAX_LINE_LENGTH], xobOnlineVersion[MAX_LINE_LENGTH];
752 ULONG *size = 0;
753 void *versionPtr;
754 UINT bytes;
755
756 // Extract currently running xoblite version...
757 // (make sure the correct version encoding is used, currently "000004b0" = language neutral)
758 DWORD number = GetFileVersionInfoSize("Blackbox.exe", size);
759 char temp[MAX_LINE_LENGTH];
760 GetFileVersionInfo("Blackbox.exe", NULL, number, (LPVOID)temp);
761 VerQueryValue(temp, TEXT("\\StringFileInfo\\000004b0\\FileVersion"), &versionPtr, &bytes);
762 strcpy(xobVersion, (LPCSTR)versionPtr);
763 if ((xobVersion[strlen(xobVersion)-1] == '\n') || (xobVersion[strlen(xobVersion)-1] == '\r')) xobVersion[strlen(xobVersion)-1] = '\0'; // Failsafe
764
765 // ...and compare that with the xoblite version available online...
766 strcpy(xobOnlineVersion, ReadString(path, "xoblite.version:", ""));
767 if ((xobOnlineVersion[strlen(xobOnlineVersion)-1] == '\n') || (xobOnlineVersion[strlen(xobOnlineVersion)-1] == '\r')) xobOnlineVersion[strlen(xobOnlineVersion)-1] = '\0'; // Failsafe
768
769 bool xobliteUpdateFound = false;
770 if (strlen(xobOnlineVersion) && _stricmp(xobVersion, xobOnlineVersion)) xobliteUpdateFound = true;
771
772 //====================
773
774 // Display result of the check for updates in the console...
775 if (updates > 0)
776 {
777 if (xobliteUpdateFound) sprintf(msg, "Checking for updates -> xoblite %s and %d updated plugin", xobOnlineVersion, updates);
778 else sprintf(msg, "Checking for updates -> %d updated plugin", updates);
779 if (updates > 1) strcat(msg, "s");
780 strcat(msg, " available.");
781 }
782 else if (xobliteUpdateFound) sprintf(msg, "Checking for updates -> xoblite %s available.", xobOnlineVersion);
783 else strcpy(msg, "Checking for updates -> No updates were found.");
784
785 SendMessage(GetBBWnd(), BB_CONSOLEMESSAGE, (WPARAM)CONSOLE_INFORMATION_MESSAGE, (LPARAM)msg);
786
787 //====================
788
789 if (xobliteUpdateFound)
790 {
791 sprintf(msg, "Shell update found! \n\nCurrent version: \nxoblite %s \n\nOnline version: \nxoblite %s \n\nDo you want to download this update? \n(clicking \"Yes\" will take you to the xoblite website) ", xobVersion, xobOnlineVersion);
792
793 if (MessageBox(GetBBWnd(), msg, "xoblite", MB_YESNO | MB_ICONQUESTION | MB_SETFOREGROUND | MB_TOPMOST) == IDYES)
794 {
795 // Choosing to download an update will (for now) take the user to the xoblite
796 // website to manually download the latest build (mostly to reduce maintenance
797 // overhead, however this could possibly change in a future release...)
798 BBExecute(GetDesktopWindow(), NULL, "http://xoblite.net/", NULL, NULL, SW_SHOWNORMAL, true);
799 }
800
801 // Choosing to download an update will (for now) take the user to the xoblite
802 // website to manually download the latest build (mostly to reduce maintenance
803 // overhead, however this could possibly change in a future release...)
804// SendMessage(GetBBWnd(), BB_POPUPMESSAGE, (WPARAM)msg, (LPARAM)"@GoToURL http://xoblite.net/");
805 }
806
807 //====================
808
809 if (updates > 0)
810 {
811 sprintf(msg, "Found %d updated plugins: \n", updates);
812 strcat(msg, listOfUpdates);
813 if (updates == 1) strcat(msg, "\n\nDo you want to download this update? ");
814 else strcat(msg, "\n\nDo you want to download any of these updates? ");
815
816 if (MessageBox(GetBBWnd(), msg, "xoblite", MB_YESNO | MB_ICONQUESTION | MB_SETFOREGROUND | MB_TOPMOST) == IDYES)
817 {
818 for (int i=0; i < (int)pPluginManager->pluginList.size(); i++)
819 {
820 if (pPluginManager->pluginList[i].UpdateAvailable)
821 {
822 pSettings->checkingForUpdates = false; // Disable update lock to access updatePlugin() ...
823 pPluginManager->UpdatePlugin(NULL, i, false);
824 pSettings->checkingForUpdates = true; // Re-enable update lock...
825 }
826 }
827 }
828 }
829 else
830 {
831 strcpy(msg, "No updated plugins were found. ");
832 MessageBox(GetBBWnd(), msg, "xoblite", MB_OK | MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST);
833 }
834 }
835
836 //====================
837
838 // Finally, we update xoblite.checked.for.updates in xoblite.rc... (temporarily disable write protection if necessary!)
839 time_t systemTime;
840 struct tm localTime;
841 time(&systemTime);
842 localtime_s(&localTime, &systemTime);
843
844 _locale_t timestampLocale = _create_locale(LC_TIME, "en-US"); // -> Always use en-US format for the "checked for updates" timestamp...
845 _strftime_l(pSettings->checkedForUpdates, 20, "#%j / %Y-%m-%d", &localTime, timestampLocale);
846 _free_locale(timestampLocale);
847
848 bool tempBool = pSettings->writeProtection;
849 pSettings->writeProtection = false;
850 WriteString(pSettings->xobrcDefaultFile, "xoblite.checked.for.updates:", pSettings->checkedForUpdates);
851 pSettings->writeProtection = tempBool;
852
853 //====================
854
855 // Remove "<->" icon from toolbar.windowLabel -> update no longer in progress
856 pSettings->checkingForUpdates = false;
857// if ((pSettings->toolbarMode == TOOLBAR_MODE_WINDOWLABEL) && pToolbar) pToolbar->UpdateToolbarWindow();
858
859 _endthread();
860}
void WriteString(LPCSTR fp, LPCSTR keyword, LPSTR value)
Definition BBApi.cpp:3156
bool DownloadFile(LPCSTR url, LPCSTR path)
Definition BBApi.cpp:3296
bool IsInString(LPCSTR inputString, LPCSTR searchString)
Definition BBApi.cpp:2519
LPSTR ReadString(LPCSTR fp, LPCSTR szString, LPSTR szDefault)
Definition BBApi.cpp:544
bool FileExists(LPCSTR szFileName)
Definition BBApi.cpp:819
bool WINAPI GetBlackboxPath(LPSTR pszPath, int nMaxLen)
Definition BBApi.cpp:214
HINSTANCE BBExecute(HWND Owner, LPCSTR szOperation, LPCSTR szCommand, LPCSTR szArgs, LPCSTR szDirectory, int nShowCmd, bool noErrorMsgs)
Definition BBApi.cpp:1648
Settings * pSettings
Definition Blackbox.cpp:46
PluginManager * pPluginManager
Definition Blackbox.cpp:43
HWND GetBBWnd()
Definition BBApi.cpp:128
#define PLUGIN_NAME
Definition BBApi.h:266
#define PLUGIN_AUTHOR
Definition BBApi.h:268
#define BB_CONSOLEMESSAGE
Definition BBApi.h:165
#define PLUGIN_RELEASEDATE
Definition BBApi.h:269
#define MAX_LINE_LENGTH
Definition BBApi.h:64
#define CONSOLE_INFORMATION_MESSAGE
Definition BBApi.h:298
#define PLUGIN_VERSION
Definition BBApi.h:267
LPCSTR(* pluginInfoFunc)(int)
Definition PluginManager.h:51

◆ periodicCheckForUpdates()

void periodicCheckForUpdates ( void * )
865{
866 if (pSettings->checkingForUpdates) _endthread();
867
868 char temp[MAX_LINE_LENGTH];// , windowLabel[25];
869
870 // Get current day of the year...
871 time_t systemTime;
872 struct tm localTime;
873 time(&systemTime);
874 localtime_s(&localTime, &systemTime);
875 int currentDay = localTime.tm_yday + 1;
876
877 // Extract day of the year for the last check...
878// strncpy(temp, &pSettings->checkedForUpdates[1], 3);
879 strncpy_s(temp, sizeof(temp), &pSettings->checkedForUpdates[1], 3);
880 temp[3] = 0;
881 int checkedDay = atoi(temp);
882
883 // Calculate the number of days since the last check for updates...
884 int interval;
885 if (currentDay >= checkedDay) interval = currentDay - checkedDay;
886 else interval = 366 - checkedDay + currentDay;
887
888 //====================
889/*
890 // Is the last checked date in xoblite.rc == the default?
891 // If so, xoblite is running for the first time -> display a nice welcome screen! =]
892 if (!_stricmp(pSettings->checkedForUpdates, "#001 / 2006-01-01"))
893 {
894 interval = 365; // ...just to trigger the update messagebox below! <g>
895 strcpy(windowLabel, "Welcome to xoblite!");
896 strcpy(temp,
897 "You seem to be running xoblite for the first time. \n\n"
898 "xoblite features a mechanism to notify you of available updates to the core (Blackbox.exe) and your loaded plugins. \n\n"
899 "A check for updates can be triggered using: \n"
900 "- The \"Check for updates...\" item in the Configuration/Global menu \n"
901 "- The core broadcast message: @xoblite CheckForUpdates \n"
902 "- Monthly periodic checking (user is notified if/when more than 30 days have passed since the last check) \n\n"
903 "Do you want to check for updates now? ");
904 }
905 else
906 {
907 strcpy(windowLabel, "xoblite");
908 sprintf(temp, "%d days have passed since you last checked for updates. \n\nDo you want to check for updates now? ", interval);
909 }
910*/
911 //====================
912
913 if (interval > 30) // Has more than 30 days passed since the last check for updates?
914 {
915/*
916 // Ask the user if he/she wants to check for updates...
917 if (MessageBox(NULL, temp, windowLabel, MB_YESNO | MB_ICONQUESTION | MB_SETFOREGROUND | MB_TOPMOST) == IDYES)
918 {
919 bool silent = false;
920 checkForUpdates(&silent); // We're already running in a separate thread! (NOTE: checkForUpdates will terminate the thread)
921 }
922 else
923 {
924 // Update xoblite.checked.for.updates in xoblite.rc... (temporarily disable write protection if necessary!)
925 _locale_t timestampLocale = _create_locale(LC_TIME, "en-US"); // -> Always use en-US format for the checked for updates timestamp...
926 _strftime_l(pSettings->checkedForUpdates, 20, "#%j / %Y-%m-%d", localTime, timestampLocale);
927 _free_locale(timestampLocale);
928
929 bool tempBool = pSettings->writeProtection;
930 pSettings->writeProtection = false;
931 WriteString(pSettings->xobrcDefaultFile, "xoblite.checked.for.updates:", pSettings->checkedForUpdates);
932 pSettings->writeProtection = tempBool;
933 }
934*/
935 bool silent = false;
936 checkForUpdates(&silent); // We're already running in a separate thread! (NOTE: checkForUpdates will terminate the thread)
937 }
938
939 //====================
940
941 _endthread();
942}
void checkForUpdates(void *param)
Definition PluginManager.cpp:630