Finale SmartMusic
  Home | Log In | Register | Search | Help
   
MakeMusic Forum > Public Forums > Plug-In Development - FORUM HAS MOVED! > Installers, uninstallers and other utilities for Finale plug-ins.  Forum Quick Jump
 
You cannot post new topics in this forum. You cannot reply to topics in this forum. Printable Version
[ << Previous Thread | Next Thread >> | Show Newest Post First ]

author
Registered Member

Email Address Not AvailableClick to visit author's website.Send a Private Message to authorAIM Not AvailableICQ Not AvailableY! Not AvailableMSN Not Available
Date Joined Mar 2015
Total Posts : 30
 
   Posted 2/3/2016 2:37 PM (GMT -6)    Quote This PostAlert An Admin About This Post.
If you want your plug-ins can be installed by this installer. The user only need to click the installer .exe-file (this file must be located in the same folder with your .fxt-file) and then follow the install wizard. You can find such installer on www.playmusic-finale.com/downloads.
If you work in Visual C++, create Win32 Project (Windows application). Add the following code:

#include "Shlobj.h"
#include "WinNT.h"
#include "KtmW32.h"        

#include "Shellapi.h"     

#define FINALE_EARLIEST_VERSION 2004                        //Finale 2004
#define FINALE_LATEST_VERSION   2015                        //Finale 2014.5
#define FINALE_2007             2007
#define FINALE_2014_5           2015
#define MISSING_VERSION         2013
#define WINDOWS_VISTA           6 
#define WAIT_TIMER_IDENT        999
#define SHELL_EXECUTE_WAIT_TIME 300

Also declare the global variables and functions:

HWND hInstallWnd;
HANDLE hWaitEvent;
int nOSVersion;

bool __stdcall FindFile(char szFilePath[], char szFileName[]);
int __stdcall  CleanDirectory(char szFilePath[], FILETIME* lpInitFileTime);
VOID CALLBACK WaitTimerProc(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime);


In _tWinMain() delete the Main message loop

    // Main message loop:

    while (GetMessage(&msg, NULL, 0, 0))
    {
        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

and instead insert the following code:


 char szPluginName[]="YourPluginName";  // replace "YourPluginName" with your real Finale plug-in name!
 char szFilePath[MAX_PATH];
 LONG lResult;
 HKEY  hKeyResult=0;
 char szSubkey[128];
 char szFinaleVersion[16];
 DWORD dwType;
 DWORD dwSizeFilePath=sizeof(szFilePath);                                    
 char szInstallText[256];
 char szInstallMessageBoxText[256];
 char szCurrDir[MAX_PATH];
 char szPluginsFolder[MAX_PATH];
 DWORD dwCurrDirLength;
 WIN32_FIND_DATA findFileData, findNewFileData;
 int nFinaleNums=0;
 struct 
 {
  char* lpszFullPath;
  int version; 
 }
 finalePlugins[24];

 char szCaption[256];
 strcpy(szCaption, "Install ");
 strcat(szCaption, szPluginName);

 LPOSVERSIONINFO lpVersionInformation=new OSVERSIONINFO;                               
 lpVersionInformation->dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
 GetVersionEx(lpVersionInformation);
 nOSVersion=(int)lpVersionInformation->dwMajorVersion;
 delete lpVersionInformation;

 dwCurrDirLength=GetCurrentDirectory(sizeof(szCurrDir), szCurrDir);
 strcat(szCurrDir, "\\");
 strcat(szCurrDir, szPluginName);
 strcat(szCurrDir, "*.fxt");

 HANDLE hNewFile=FindFirstFile(szCurrDir, &findNewFileData);
 if (hNewFile!=INVALID_HANDLE_VALUE)
 {
  szCurrDir[dwCurrDirLength+1]='\0';
  strcat(szCurrDir, findNewFileData.cFileName);
  FindClose(hNewFile);
 }
 else
 {
  MessageBox(hInstallWnd, "The install file was not found.", szCaption, MB_OK | MB_ICONSTOP); 
  return (int) msg.wParam;
 }
///////
 if(nOSVersion>=WINDOWS_VISTA)
 {
    HANDLE hMutexControl=0;
    HANDLE hMutex=CreateMutex(NULL, true, "InstallFinalePluginMutex");
    int nResult=GetLastError();
    if(nResult==ERROR_ALREADY_EXISTS)
      hMutexControl=CreateMutex(NULL, true, "InstallFinalePluginMutexControl");   
    else
    {
      char szInstallModuleFileName[256];
      GetModuleFileName(NULL, szInstallModuleFileName, sizeof(szInstallModuleFileName));

      HINSTANCE hInstanceSE=ShellExecute(NULL, "runas", szInstallModuleFileName, 0, 0, SW_SHOWNORMAL);
      //The app re-runs itself as admin 
//-------------------------------------------------------------------------------------------------------
      if((int)hInstanceSE<32)
      {
        ReleaseMutex(hMutex);
        CloseHandle(hMutex);
        MessageBox( hInstallWnd, "Install failed. Try to install manually.", szCaption, MB_OK | MB_ICONSTOP );
        return 0;
      }
//------------------------------------------------------------------------------------------------------
      bool bRepeat=true;
      do
      {
        hWaitEvent=CreateEvent(NULL, true, false, NULL);
       MSG uMessage;
       DWORD dwResult;
       bool bDone=false;
       SetTimer(hInstallWnd, WAIT_TIMER_IDENT, SHELL_EXECUTE_WAIT_TIME, (TIMERPROC)WaitTimerProc);
              
       while( !bDone )
       {
        dwResult = MsgWaitForMultipleObjects( 1, &hWaitEvent, false, INFINITE, QS_ALLINPUT );
        if(dwResult==WAIT_OBJECT_0 + 1)
         while( PeekMessage( &uMessage, NULL, 0, 0, PM_REMOVE ) )
          if( uMessage.message == WM_QUIT )
            bDone = true;
          else
            DispatchMessage( &uMessage );
         else
             break;
       }
       ResetEvent(hWaitEvent);
       CloseHandle(hWaitEvent);   
//------------------------------------------------------------------------------------------------------
       hMutexControl = openMutex(SYNCHRONIZE, FALSE, "InstallFinalePluginMutexControl");/////////???????
       if(hMutexControl!=0)
       {
         bRepeat=false;   
         ReleaseMutex(hMutexControl);
         CloseHandle(hMutexControl);
       }
      }
      while(bRepeat);

      ReleaseMutex(hMutex);
      CloseHandle(hMutex);
//-------------------------------------------------------------------------------------------------------
      return 0;  
    }                                //end:  if(!(nResult==ERROR_ALREADY_EXISTS))
 }                                    //end:  if(nOSVersion>=WINDOWS_VISTA)


//-------------------------------------------------------------------------------------------//2.02.16
///////
 for(int nVersion=FINALE_LATEST_VERSION; nVersion>=FINALE_EARLIEST_VERSION; nVersion--)
  if(nVersion!=MISSING_VERSION)                       
  {                                                 //find all Finale versions on the computer
   if(nVersion>FINALE_2007)
   {
    strcpy(szSubkey, "SOFTWARE\\MakeMusic\\Finale"); 
   
    if(nVersion!=FINALE_2014_5)
      itoa(nVersion, szFinaleVersion, 10);
    else
      strcpy(szFinaleVersion, "2014.5");

    strcat(szSubkey, szFinaleVersion);
    lResult=RegopenKeyEx(HKEY_LOCAL_MACHINE, szSubkey, NULL, KEY_QUERY_VALUE, &hKeyResult);
    if(lResult==ERROR_SUCCESS)
    {
     lResult=RegQueryValueEx(hKeyResult, "InstallDir", NULL, &dwType, (LPBYTE)szFilePath, &dwSizeFilePath); 
     RegCloseKey(hKeyResult);
    }              //end:  if(lResult==ERROR_SUCCESS)
   }
   else
    if(nVersion==FINALE_2007)
    {
     strcpy(szSubkey, "SOFTWARE\\MakeMusic\\Finale"); 
     itoa(nVersion, szFinaleVersion, 10);
     strcat(szSubkey, szFinaleVersion);
     strcat(szSubkey, "\\InstallPath");
     lResult=RegopenKeyEx(HKEY_LOCAL_MACHINE, szSubkey, NULL, KEY_QUERY_VALUE, &hKeyResult);
     if(lResult==ERROR_SUCCESS)
     { 
      lResult=RegQueryValueEx(hKeyResult, "", NULL, &dwType, (LPBYTE)szFilePath, &dwSizeFilePath);

      RegCloseKey(hKeyResult);
      for(int n=0; n<dwSizeFilePath-4; n++)
       if((szFilePath[n]=='2')&&(szFilePath[n+1]=='0')&&(szFilePath[n+2]=='0')&&(szFilePath[n+3]=='7'))
         szFilePath[n+4]='\0';
     }                           //end:  if(lResult==ERROR_SUCCESS)
    }                           //end:  if(nVersion==FINALE_2007)
    else
    {                           //begin:  if(nVersion<FINALE_2007)    
     strcpy(szSubkey, "SOFTWARE\\CodaMusic\\Finale"); 
     itoa(nVersion, szFinaleVersion, 10);
     strcat(szSubkey, szFinaleVersion);
     strcat(szSubkey, "\\InstallPath");
     lResult=RegopenKeyEx(HKEY_LOCAL_MACHINE, szSubkey, NULL, KEY_QUERY_VALUE, &hKeyResult);
     if(lResult==ERROR_SUCCESS)
     {
      lResult=RegQueryValueEx(hKeyResult, "", NULL, &dwType, (LPBYTE)szFilePath, &dwSizeFilePath);
                                  
      RegCloseKey(hKeyResult);
      for(int n=0; n<dwSizeFilePath-4; n++)
       if((szFilePath[n]=='2')&&(szFilePath[n+1]=='0')&&(szFilePath[n+2]=='0')&&
           ((szFilePath[n+3]=='4')||(szFilePath[n+3]=='5')||(szFilePath[n+3]=='6')))
         szFilePath[n+4]='\0';
     }                           //end:  if(lResult==ERROR_SUCCESS)
    }                           //end:  if(nVersion<FINALE_2007)

   if((lResult==ERROR_SUCCESS)&&(dwType==REG_SZ))
   {
    strcat(szFilePath, "\\Plug-ins");

    finalePlugins[nFinaleNums].lpszFullPath=new char[256];
    strcpy(finalePlugins[nFinaleNums].lpszFullPath, szFilePath); 
    finalePlugins[nFinaleNums].version=nVersion;                                      
    nFinaleNums++;                         //number of Finale versions on the computer
   }            //end:   if((lResult==ERROR_SUCCESS)&&(dwType==REG_SZ))
  }        //end:   for(int nVersion=FINALE_LAST_VERSION; nVersion>=FINALE_EARLIEST_VERSION; nVersion--)

 if(nFinaleNums==0)
 {
   MessageBox( hInstallWnd, "Finale was not found on your computer.", szCaption, MB_OK | MB_ICONSTOP );
 }
 else
 {
  int nUninstalledFinale=0;
  int nNotFoundPluginsFolder=0;
  int nInstallNums=0;

  SYSTEMTIME initSysTime;                                   
  GetSystemTime(&initSysTime);
  FILETIME initFileTime;
  SystemTimeToFileTime(&initSysTime, &initFileTime);
  
 // strcpy(szPluginsFolder, szFilePath);                                    
 // strcat(szPluginsFolder, "\\*");

  for(int nNumFinaleCopy=0; nNumFinaleCopy<nFinaleNums; nNumFinaleCopy++) 
  {
   strcpy(szFilePath, finalePlugins[nNumFinaleCopy].lpszFullPath); 
                                                
   strcpy(szPluginsFolder, szFilePath);                                    
   strcat(szPluginsFolder, "\\*");

   hNewFile=FindFirstFile(szFilePath, &findNewFileData);                       
   if(hNewFile==INVALID_HANDLE_VALUE)
   {
    int nStrlen=strlen(szFilePath);
    char* szFilePathTemp=new char[MAX_PATH];
    strcpy(szFilePathTemp, szFilePath);            
    for( ; nStrlen>0; nStrlen--)
     if(szFilePathTemp[nStrlen]=='\\')
       break;
    szFilePathTemp[nStrlen]='\0';      
    hNewFile=FindFirstFile(szFilePathTemp, &findNewFileData);                       
    if(hNewFile!=INVALID_HANDLE_VALUE)
    {
     bool bVersion_2014_5=false;
     strcpy(szInstallText, "Plug-ins folder was not found for Finale ");
     for( ; nStrlen>3; nStrlen--)
      if((szFilePathTemp[nStrlen]>='0')&&(szFilePathTemp[nStrlen]<='9'))
       if((szFilePathTemp[nStrlen-1]>='0')&&(szFilePathTemp[nStrlen-1]<='9'))
        if(szFilePathTemp[nStrlen-2]=='0')
           if(szFilePathTemp[nStrlen-3]=='2')
         {
          if((szFilePathTemp[nStrlen-1]=='1')&&(szFilePathTemp[nStrlen]=='4')&&
             (szFilePathTemp[nStrlen+1]=='.')&&(szFilePathTemp[nStrlen+2]=='5'))
          {
            nStrlen+=2;                                                
            bVersion_2014_5=true; 
          }
          szFilePathTemp[nStrlen+1]='\0';
          break;
         }                                    
     if(nStrlen>3)
     {
      int nNumCharTemp=0;
      for( ; nNumCharTemp<(bVersion_2014_5?6:4); nNumCharTemp++)
        szFinaleVersion[nNumCharTemp]=szFilePathTemp[nStrlen+nNumCharTemp-(bVersion_2014_5?5:3)];
      szFinaleVersion[nNumCharTemp]='\0';           
     }
     strcat(szInstallText, szFinaleVersion);
     strcat(szInstallText, ".");
     MessageBox(hInstallWnd, szInstallText, szCaption, MB_OK | MB_ICONSTOP);
     FindClose(hNewFile);
     nNotFoundPluginsFolder++;
    }                          //end:  if(hNewFile!=INVALID_HANDLE_VALUE)
    else
      nUninstalledFinale++;
    delete[] szFilePathTemp;
    continue;
   }                         //end:  if(hNewFile==INVALID_HANDLE_VALUE)
   else
     FindClose(hNewFile);

   strcat(szFilePath, "\\*");
  
   if(!FindFile(szFilePath, szPluginName))
   {
    nInstallNums++;
    strcpy(szFilePath, finalePlugins[nNumFinaleCopy].lpszFullPath);

    if(finalePlugins[nNumFinaleCopy].version!=FINALE_2014_5)
      itoa(finalePlugins[nNumFinaleCopy].version, szFinaleVersion, 10);
    else
      strcpy(szFinaleVersion, "2014.5");

    int wchars_num =  MultiByteToWideChar(CP_UTF8, 0, szFilePath, -1, NULL, 0);
    wchar_t* wstr = new wchar_t[wchars_num];
    MultiByteToWideChar(CP_UTF8, 0, szFilePath, -1, wstr, wchars_num);

    PIDLIST_ABSOLUTE *ppidl = new PIDLIST_ABSOLUTE;
    SHParseDisplayName(wstr, NULL, ppidl, NULL, NULL);
    delete[] wstr;

    if(nFinaleNums==1)
    {
      strcpy(szInstallText, "Select an existing folder or create a new one to install ");
      strcat(szInstallText, szPluginName);
      strcat(szInstallText, ". By default it will be installed directly in the Plug-ins folder.");
    }
    else
    {                                                   //begin:  if(!(nFinaleNums==1))
     strcpy(szInstallText, "Do you want to install ");
     strcat(szInstallText, szPluginName);
     strcat(szInstallText, " in Finale ");
     strcat(szInstallText, szFinaleVersion);
     strcat(szInstallText, "?");
     int nRetValue=MessageBox(hInstallWnd, szInstallText, szCaption,
                               MB_YESNOCANCEL | MB_ICONQUESTION | MB_DEFBUTTON1);
     if(nRetValue==IDYES)
     {
      strcpy(szInstallText, "Select an existing folder or create a new one to install ");
      strcat(szInstallText, szPluginName);
      strcat(szInstallText, ". By default it will be installed directly in the Plug-ins folder.");
     }
     else
      if(nRetValue==IDNO)
      {
        delete[] finalePlugins[nNumFinaleCopy].lpszFullPath;
        continue;
      }
      else
       if(nRetValue==IDCANCEL)
       {                                                                              
         for( ; nNumFinaleCopy<nFinaleNums; nNumFinaleCopy++)
           delete[] finalePlugins[nNumFinaleCopy].lpszFullPath;
         return (int) msg.wParam;
       }
    }                                           //end:  if(!(nFinaleNums==1))

    PIDLIST_ABSOLUTE lpItem;
    int nOkCancel;
    do 
    {                       //begin:  do ... while((lpItem!=NULL)&&(nOkCancel==IDCANCEL))
     TCHAR szDir[MAX_PATH];
     BROWSEINFO bInfo;
     bInfo.hwndOwner = hInstallWnd;
     bInfo.pidlRoot = *ppidl; 
     bInfo.pszDisplayName = szDir; // Address of a buffer to receive the display name of the folder selected by the user
     bInfo.lpszTitle = szInstallText; // Title of the dialog
     bInfo.ulFlags = BIF_VALIDATE | BIF_NEWDIALOGSTYLE ;
     bInfo.lpfn = NULL;                               
     bInfo.lParam = 0;
     bInfo.iImage = -1;
      
     lpItem = SHBrowseForFolder(&bInfo);

     if(lpItem!=NULL)
     {
      SHGetPathFromIDList(lpItem, szDir);
      strcpy(szInstallMessageBoxText, szPluginName);
      strcat(szInstallMessageBoxText, " will be located in the directory \n");      
      strcat(szInstallMessageBoxText, szDir); 

      nOkCancel=MessageBox(hInstallWnd, szInstallMessageBoxText, szCaption, 
                                    MB_OKCANCEL | MB_ICONEXCLAMATION |MB_DEFBUTTON1);
      if(nOkCancel==IDCANCEL)
      {
        CleanDirectory(szPluginsFolder, &initFileTime);        
        continue;
      }
      int nPathLength=strlen(szCurrDir);
      for( ; nPathLength>0; nPathLength--)
       if(szCurrDir[nPathLength]=='\\')
         break; 
      if(nPathLength>0)
      {
       char* lpszFileName;
       lpszFileName=&szCurrDir[nPathLength];
       strcat(szDir, lpszFileName);

       if(CopyFile(szCurrDir, szDir, false))                    //27.07.15                                                  
       {                                                                
        bool bFinaleIsRunning=false;
        char szModulePath[256];
        strcpy(szModulePath, finalePlugins[nNumFinaleCopy].lpszFullPath);
        int nStrlen=strlen(szModulePath);
        for( ; nStrlen>=0; nStrlen--)
         if(szModulePath[nStrlen]=='\\')
           break;  
        szModulePath[nStrlen+1]='\0';
        strcat(szModulePath, "Finale.exe");

        HANDLE hFile=CreateFile(szModulePath, GENERIC_WRITE    |GENERIC_READ, 0, NULL, open_EXISTING,
                               FILE_ATTRIBUTE_NORMAL, NULL    );

        if(hFile== INVALID_HANDLE_VALUE)
          bFinaleIsRunning=true;
        else
          CloseHandle(hFile);

        int nFullPath=strlen(finalePlugins[nNumFinaleCopy].lpszFullPath);
        for(int nNumChar=0; nNumChar<nFullPath; nNumChar++)
         if(((char)*(finalePlugins[nNumFinaleCopy].lpszFullPath+nNumChar)=='2')&&
            ((char)*(finalePlugins[nNumFinaleCopy].lpszFullPath+nNumChar+1)=='0')&&
            ((char)*(finalePlugins[nNumFinaleCopy].lpszFullPath+nNumChar+2)>='0')&&
            ((char)*(finalePlugins[nNumFinaleCopy].lpszFullPath+nNumChar+2)<='9')&&
            ((char)*(finalePlugins[nNumFinaleCopy].lpszFullPath+nNumChar+3)>='0')&&
            ((char)*(finalePlugins[nNumFinaleCopy].lpszFullPath+nNumChar+3)<='9'))
         {
          bool bFinale_2014_5=false;
          if(((char)*(finalePlugins[nNumFinaleCopy].lpszFullPath+nNumChar+2)=='1')&&
             ((char)*(finalePlugins[nNumFinaleCopy].lpszFullPath+nNumChar+3)=='4')&&
             ((char)*(finalePlugins[nNumFinaleCopy].lpszFullPath+nNumChar+4)=='.')&&
             ((char)*(finalePlugins[nNumFinaleCopy].lpszFullPath+nNumChar+5)=='5'))
            bFinale_2014_5=true;

          int nNumCharTemp=0;
          for( ; nNumCharTemp<(bFinale_2014_5?6:4); nNumCharTemp++)            //31.01.16
            szFinaleVersion[nNumCharTemp]=(char)*(finalePlugins[nNumFinaleCopy].lpszFullPath+nNumChar+nNumCharTemp);
          szFinaleVersion[nNumCharTemp]='\0';
          break;
         }

        if(nFinaleNums==1)
         if(bFinaleIsRunning)
         { 
          strcpy(szInstallMessageBoxText, " Installation  successfully completed.\n "); 
          strcat(szInstallMessageBoxText, szPluginName);
          strcat(szInstallMessageBoxText, " will be available after restarting Finale ");
          strcat(szInstallMessageBoxText, szFinaleVersion);
          strcat(szInstallMessageBoxText, ".");
          MessageBox( hInstallWnd, szInstallMessageBoxText, szCaption, MB_OK | MB_ICONASTERISK );
         } 
         else
           MessageBox( hInstallWnd, "Installation successfully completed.", szCaption, MB_OK | MB_ICONASTERISK );
        else
        {                         //begin:  if(!(nFinaleNums==1))
         if(bFinaleIsRunning)
         { 
          strcpy(szInstallMessageBoxText, " Installation  successfully completed.\n ");
          strcat(szInstallMessageBoxText, szPluginName);
          strcat(szInstallMessageBoxText, " will be available after restarting Finale ");
          strcat(szInstallMessageBoxText, szFinaleVersion);
          strcat(szInstallMessageBoxText, ".");
         } 
         else
         {
          strcpy(szInstallMessageBoxText, szPluginName);
          strcat(szInstallMessageBoxText, " has been successfully installed."); 
         }
         MessageBox( hInstallWnd, szInstallMessageBoxText, szCaption, MB_OK | MB_ICONASTERISK );
        }                      //end:  if(!(nFinaleNums==1))
       }                  //end:  if(CopyFile(szCurrDir, szDir, false))
       else
       {
         MessageBox( hInstallWnd, "Installation failed. Try to install manually.", szCaption, MB_OK | MB_ICONSTOP );  
       }
      }                      //end:   if(nPathLength>0)
     }                     //end:   if( lpItem != NULL )
     else
       CleanDirectory(szPluginsFolder, &initFileTime);                     
    }           
    while((lpItem!=NULL)&&(nOkCancel==IDCANCEL));

    delete ppidl;
   }                   //end:   if(!FindFile(szFilePath, szPluginName)
   delete[] finalePlugins[nNumFinaleCopy].lpszFullPath;
  }                   //end:   for(int nNumFinaleCopy=0; nNumFinaleCopy<nFinaleNums; nNumFinaleCopy++) 

  if(nInstallNums==0)
   if(nFinaleNums==nUninstalledFinale+nNotFoundPluginsFolder)
    if(nNotFoundPluginsFolder>0);
    else
      MessageBox( hInstallWnd, "Finale was not found.", szCaption, MB_OK | MB_ICONSTOP ); 
   else 
   { 
     strcpy(szInstallMessageBoxText, szPluginName);
     strcat(szInstallMessageBoxText, " already installed.");
     MessageBox( hInstallWnd, szInstallMessageBoxText, szCaption, MB_OK | MB_ICONSTOP ); 
   }
 }                 //end:    if(!(nFinaleNums==0))

Don't forget to replace "YourPluginName" with your real Finale plug-in name.
You can replace at the end of _tWinMain()

return (int) msg.wParam;

to

return 0;


In InitInstance() after

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
                                     CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

insert

   hInstallWnd = hWnd;
   nCmdShow=SW_SHOWMINIMIZED;


Here are the declared above functions:

bool __stdcall  FindFile(char szFilePath[], char szFileName[])
{
  HANDLE hFile;
  WIN32_FIND_DATA findFileData;
  int nNullPos=strlen(szFilePath);

  hFile=FindFirstFile(szFilePath, &findFileData);

  if (hFile!=INVALID_HANDLE_VALUE)
  {
   do                                 //begin:  do ... while (FindNextFile(hFile, &findFileData)!=0);
    if((strcmp(findFileData.cFileName, ".")!=0)&&(strcmp(findFileData.cFileName, "..")!=0))
    {
     if(findFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
     {
       szFilePath[nNullPos-1]='\0';
       strcat(szFilePath, findFileData.cFileName); 
       strcat(szFilePath, "\\*");

       if(FindFile(szFilePath, szFileName))
       {
         FindClose(hFile);
         return true;
       }
       else
       {
         szFilePath[nNullPos-1]='*';
         szFilePath[nNullPos]='\0';
       }
     }
     else
      if(strstr(findFileData.cFileName, szFileName)!=NULL)
      {
        szFilePath[nNullPos-1]='\0';
        strcat(szFilePath, findFileData.cFileName); 
        FindClose(hFile);
        return true;
      }
    }   //end:  if((strcmp(findFileData.cFileName, ".")!=0)&&(strcmp(findFileData.cFileName, "..")!=0))
   while (FindNextFile(hFile, &findFileData)!=0);

   szFilePath[nNullPos-1]='*';
   szFilePath[nNullPos]='\0';
   FindClose(hFile);
   return false;
  }
  else
    return false;
}

//************************************************************************************************************

int __stdcall  CleanDirectory(char szFilePath[], FILETIME* lpInitFileTime)
{
  #define ERROR   -1
  WIN32_FIND_DATA findFileData;
  HANDLE hFile;
  int nNullPos;
  nNullPos=strlen(szFilePath);
  int nFilesCount=0;

  hFile=FindFirstFile(szFilePath, &findFileData);

  if (hFile!=INVALID_HANDLE_VALUE)
  {
   do                                      //begin:  do ... while (FindNextFile(hFile, &findFileData)!=0);
    if((strcmp(findFileData.cFileName, ".")!=0)&&(strcmp(findFileData.cFileName, "..")!=0))
    {
     nFilesCount++;
     if(findFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
     {
       szFilePath[nNullPos-sizeof(char)]='\0';
       strcat(szFilePath, findFileData.cFileName); 
       strcat(szFilePath, "\\*");

       int nResult=CleanDirectory(szFilePath, lpInitFileTime);
       if(nResult==ERROR)
         return ERROR;
       else
        if(nResult==0)
         if(CompareFileTime(&(findFileData.ftCreationTime), lpInitFileTime)>=0)
         {
           int nStrlen=strlen(szFilePath);
           char szFilePathTemp[MAX_PATH];
           strcpy(szFilePathTemp, szFilePath);
           szFilePathTemp[nStrlen-2]='\0';;
           RemoveDirectory(szFilePathTemp);
           nFilesCount--;
         }
     }
    }        //end:  if((strcmp(findFileData.cFileName, ".")!=0)&&(strcmp(findFileData.cFileName, "..")!=0))
   while (FindNextFile(hFile, &findFileData)!=0);

   szFilePath[nNullPos-sizeof(char)]='*';
   szFilePath[nNullPos]='\0';
   FindClose(hFile);
   return nFilesCount;
  }
  else
    return ERROR;
}

//********************************************************************************************************

VOID CALLBACK WaitTimerProc                                          
   (
    HWND hWnd,         // handle of window for timer messages
    UINT uMsg,        // WM_TIMER message
    UINT idEvent,    // timer identifier
    DWORD dwTime     // current system time
   )
{
   if(idEvent==WAIT_TIMER_IDENT)                          
   {
       KillTimer(hWnd, idEvent);
       SetEvent(hWaitEvent);    
   }
}

Post Edited (author) : 3/21/2016 1:32:28 PM (GMT-5)

Back to Top

author
Registered Member

Email Address Not AvailableClick to visit author's website.Send a Private Message to authorAIM Not AvailableICQ Not AvailableY! Not AvailableMSN Not Available
Date Joined Mar 2015
Total Posts : 30
 
   Posted 2/7/2016 10:39 AM (GMT -6)    Quote This PostAlert An Admin About This Post.
NOTE: In _tWinMain() the open_EXISTNG parameter in the function CreateFile() and the name of the function RegopenKeyEx for unknown reasons are displayed incorrectly. The first four letters in the name open_EXISTNG must be in upper case and in Win API functions RegopenKeyEx the fourth letter ' O ' must be in upper case too.

In Configuration Properties->General->Character Set you should select: Not Set

Post Edited (author) : 2/7/2016 9:57:21 AM (GMT-6)

Back to Top

author
Registered Member

Email Address Not AvailableClick to visit author's website.Send a Private Message to authorAIM Not AvailableICQ Not AvailableY! Not AvailableMSN Not Available
Date Joined Mar 2015
Total Posts : 30
 
   Posted 3/21/2016 3:11 AM (GMT -6)    Quote This PostAlert An Admin About This Post.
Your plug-ins can be updated using this utility. The user only need to click the update .exe-file (the file must be located in the same folder with your plug-in's .fxt-file) and then follow the update wizard.
If you work in Visual C++, create Win32 Project (Windows application). Via Project->...Properties...->Configuration Properties->Linker->Input->Additional Dependencies add version.lib. Then insert the following code:

#include "Shlobj.h"
#include "WinNT.h"
#include "KtmW32.h"        
#include "Shellapi.h"     

#define FINALE_EARLIEST_VERSION 2004                        //Finale 2004
#define FINALE_LATEST_VERSION   2015                        //Finale 2014.5
#define FINALE_2007             2007
#define FINALE_2014_5           2015
#define MISSING_VERSION         2013
#define WINDOWS_VISTA           6 
#define WAIT_TIMER_IDENT        999
#define SHELL_EXECUTE_WAIT_TIME 300

Declare the global variables and functions:

HANDLE hWaitEvent;
HWND hUpdateWnd;
int nOSVersion;

bool __stdcall  FindFile(char szFilePath[], char szFileName[]);
VOID CALLBACK WaitTimerProc(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime);

In _tWinMain() delete the Main message loop


    // Main message loop:

    while (GetMessage(&msg, NULL, 0, 0))
    {
        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }

and instead insert the following code:

 char szPluginName[]="YourPluginName";  // replace "YourPluginName" with your real Finale plug-in name!!!
 char szFilePath[MAX_PATH];
 DWORD dwSizeFilePath=sizeof(szFilePath); 
 LONG lResult;
 HKEY  hKeyResult=0;
 char szSubkey[128];
 char szFinaleVersion[16];
 DWORD dwType;
 char szUpdateText[256];
 bool bCloseFinale=false;
 int nUpdateNums=0;
 bool bUpdate=false;
 char szCurrDir[256];
 DWORD dwCurrDirLehgth;
 WIN32_FIND_DATA findFileData, findNewFileData;
 union TPluginVersionInfoData
 {
   unsigned int dwData;
   BYTE bData;
 };
 TPluginVersionInfoData pluginVersionInfoNew, pluginVersionInfo; 

 char szCaption[256];
 strcpy(szCaption, "Update ");
 strcat(szCaption, szPluginName);

 LPOSVERSIONINFO lpVersionInformation=new OSVERSIONINFO;
 lpVersionInformation->dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
 GetVersionEx(lpVersionInformation);
 nOSVersion=(int)lpVersionInformation->dwMajorVersion;
 delete lpVersionInformation;

 dwCurrDirLehgth=GetCurrentDirectory(sizeof(szCurrDir), szCurrDir);
 strcat(szCurrDir, "\\");
 strcat(szCurrDir, szPluginName);
 strcat(szCurrDir, "*.fxt");
 HANDLE hNewFile=FindFirstFile(szCurrDir, &findNewFileData);

 if (hNewFile!=INVALID_HANDLE_VALUE)
 {
   szCurrDir[dwCurrDirLehgth+1]='\0';
   strcat(szCurrDir, findNewFileData.cFileName);
   FindClose(hNewFile);

   DWORD dwVersionInfoSize;                                                           
   BYTE *pVersionInfo = NULL;
   VS_FIXEDFILEINFO  *pFileInfo = NULL;
   UINT  nLenFileInfo = 0;

   dwVersionInfoSize = GetFileVersionInfoSize( szCurrDir, NULL );

   pVersionInfo = new BYTE[ dwVersionInfoSize ];
   GetFileVersionInfo( szCurrDir, 0, dwVersionInfoSize, pVersionInfo );
   VerQueryValue( pVersionInfo, TEXT("\\"), (LPVOID*) &pFileInfo, &nLenFileInfo );

   DWORD dwLeftMost = HIWORD(pFileInfo->dwFileVersionMS);      
   DWORD dwSecondLeft = LOWORD(pFileInfo->dwFileVersionMS);    
   DWORD dwSecondRight = HIWORD(pFileInfo->dwFileVersionLS);   
   DWORD dwRightMost = LOWORD(pFileInfo->dwFileVersionLS);     

   pluginVersionInfoNew.bData[0]=(BYTE)dwRightMost;
   pluginVersionInfoNew.bData=(BYTE)dwSecondRight;
   pluginVersionInfoNew.bData=(BYTE)dwSecondLeft;
   pluginVersionInfoNew.bData=(BYTE)dwLeftMost;

   delete[]  pVersionInfo;
 }                                  //end:  if (hNewFile!=INVALID_HANDLE_VALUE)
 else
 {
   MessageBox( hUpdateWnd, "The update file was not found.", szCaption, MB_OK | MB_ICONSTOP ); 
   return (int) msg.wParam;
 }

 if(nOSVersion>=WINDOWS_VISTA)
 {
    HANDLE hMutexControl=0;
    HANDLE hMutex=CreateMutex(NULL, true, "UpdateFinalePluginMutex");
    int nResult=GetLastError();
    if(nResult==ERROR_ALREADY_EXISTS)
      hMutexControl=CreateMutex(NULL, true, "UpdateFinalePluginMutexControl");   
    else
    {
      char szUpdateModuleFileName[256];
      GetModuleFileName(NULL, szUpdateModuleFileName, sizeof(szUpdateModuleFileName));

      HINSTANCE hInstanceSE=ShellExecute(NULL, "runas", szUpdateModuleFileName, 0, 0, SW_SHOWNORMAL);
      //The app re-runs itself as admin 
//-------------------------------------------------------------------------------------------------------
      if((int)hInstanceSE<32)
      {
        ReleaseMutex(hMutex);
        CloseHandle(hMutex);
        MessageBox( hUpdateWnd, "Update failed. Try to update manually.", szCaption, MB_OK | MB_ICONSTOP );
        return 0;
      }
//------------------------------------------------------------------------------------------------------
      bool bRepeat=true;
      do
      {
        hWaitEvent=CreateEvent(NULL, true, false, NULL);
       MSG uMessage;
       DWORD dwResult;
       bool bDone=false;
       SetTimer(hUpdateWnd, WAIT_TIMER_IDENT, SHELL_EXECUTE_WAIT_TIME, (TIMERPROC)WaitTimerProc);
              
       while( !bDone )
       {
        dwResult = MsgWaitForMultipleObjects( 1, &hWaitEvent, false, INFINITE, QS_ALLINPUT );
        if(dwResult==WAIT_OBJECT_0 + 1)
         while( PeekMessage( &uMessage, NULL, 0, 0, PM_REMOVE ) )
          if( uMessage.message == WM_QUIT )
            bDone = true;
          else
            DispatchMessage( &uMessage );
         else
             break;
       }
       ResetEvent(hWaitEvent);
       CloseHandle(hWaitEvent);   
//------------------------------------------------------------------------------------------------------
       hMutexControl = openMutex(SYNCHRONIZE, FALSE, "UpdateFinalePluginMutexControl");/////////???????
       if(hMutexControl!=0)
       {
         bRepeat=false;   
         ReleaseMutex(hMutexControl);
         CloseHandle(hMutexControl);
       }
      }
      while(bRepeat);

      ReleaseMutex(hMutex);
      CloseHandle(hMutex);
//-------------------------------------------------------------------------------------------------------
      return 0;  
    }                                //end:  if(!(nResult==ERROR_ALREADY_EXISTS))
 }                                    //end:  if(nOSVersion>=WINDOWS_VISTA)

 for(int nVersion=FINALE_LATEST_VERSION; nVersion>=FINALE_EARLIEST_VERSION; nVersion--)
  if(nVersion!=MISSING_VERSION)                       
  {                                                 //find all Finale versions on the computer
   if(nVersion>FINALE_2007)
   {
    strcpy(szSubkey, "SOFTWARE\\MakeMusic\\Finale"); 
   
    if(nVersion!=FINALE_2014_5)
      itoa(nVersion, szFinaleVersion, 10);
    else
      strcpy(szFinaleVersion, "2014.5");

    strcat(szSubkey, szFinaleVersion);
    lResult=RegopenKeyEx(HKEY_LOCAL_MACHINE, szSubkey, NULL, KEY_QUERY_VALUE, &hKeyResult);
    if(lResult==ERROR_SUCCESS)
    {
     lResult=RegQueryValueEx(hKeyResult, "InstallDir", NULL, &dwType, (LPBYTE)szFilePath, &dwSizeFilePath); 
     RegCloseKey(hKeyResult);
    }                                         //end:  if(lResult==ERROR_SUCCESS)
   }
   else
    if(nVersion==FINALE_2007)
    {
     strcpy(szSubkey, "SOFTWARE\\MakeMusic\\Finale"); 
     itoa(nVersion, szFinaleVersion, 10);
     strcat(szSubkey, szFinaleVersion);
     strcat(szSubkey, "\\InstallPath");
     lResult=RegopenKeyEx(HKEY_LOCAL_MACHINE, szSubkey, NULL, KEY_QUERY_VALUE, &hKeyResult);
     if(lResult==ERROR_SUCCESS)
     { 
      lResult=RegQueryValueEx(hKeyResult, "", NULL, &dwType, (LPBYTE)szFilePath, &dwSizeFilePath);

      RegCloseKey(hKeyResult);
      for(int n=0; n<dwSizeFilePath-4; n++)
       if((szFilePath[n]=='2')&&(szFilePath[n+1]=='0')&&(szFilePath[n+2]=='0')&&(szFilePath[n+3]=='7'))
         szFilePath[n+4]='\0';
     }                                          //end:  if(lResult==ERROR_SUCCESS)
    }                                          //end:  if(nVersion==FINALE_2007)
    else
    {                                               //begin:  if(nVersion<FINALE_2007)    
     strcpy(szSubkey, "SOFTWARE\\CodaMusic\\Finale"); 
     itoa(nVersion, szFinaleVersion, 10);
     strcat(szSubkey, szFinaleVersion);
     strcat(szSubkey, "\\InstallPath");
     lResult=RegopenKeyEx(HKEY_LOCAL_MACHINE, szSubkey, NULL, KEY_QUERY_VALUE, &hKeyResult);
     if(lResult==ERROR_SUCCESS)
     {
      lResult=RegQueryValueEx(hKeyResult, "", NULL, &dwType, (LPBYTE)szFilePath, &dwSizeFilePath);
                                  
      RegCloseKey(hKeyResult);
      for(int n=0; n<dwSizeFilePath-4; n++)
       if((szFilePath[n]=='2')&&(szFilePath[n+1]=='0')&&(szFilePath[n+2]=='0')&&
           ((szFilePath[n+3]=='4')||(szFilePath[n+3]=='5')||(szFilePath[n+3]=='6')))
         szFilePath[n+4]='\0';
     }                                      //end:  if(lResult==ERROR_SUCCESS)
    }                                     //end:  if(nVersion<FINALE_2007)

   if((lResult==ERROR_SUCCESS)&&(dwType==REG_SZ))
   {
    strcat(szFilePath, "\\Plug-ins\\*");
    if(FindFile(szFilePath, szPluginName))
    {
      DWORD dwVersionInfoSize;                                                           
      BYTE *pVersionInfo = NULL;
      VS_FIXEDFILEINFO  *pFileInfo = NULL;
      UINT  nLenFileInfo = 0;

      dwVersionInfoSize = GetFileVersionInfoSize( szFilePath, NULL );
      pVersionInfo = new BYTE[ dwVersionInfoSize ];
      GetFileVersionInfo( szFilePath, 0, dwVersionInfoSize, pVersionInfo );
      VerQueryValue( pVersionInfo, TEXT("\\"), (LPVOID*) &pFileInfo, &nLenFileInfo );

      DWORD dwLeftMost = HIWORD(pFileInfo->dwFileVersionMS);      
      DWORD dwSecondLeft = LOWORD(pFileInfo->dwFileVersionMS);    
      DWORD dwSecondRight = HIWORD(pFileInfo->dwFileVersionLS);   
      DWORD dwRightMost = LOWORD(pFileInfo->dwFileVersionLS);     

      pluginVersionInfo.bData[0]=(BYTE)dwRightMost;
      pluginVersionInfo.bData=(BYTE)dwSecondRight;
      pluginVersionInfo.bData=(BYTE)dwSecondLeft;
      pluginVersionInfo.bData=(BYTE)dwLeftMost;

      delete[]  pVersionInfo;

      if(pluginVersionInfo.dwData!=pluginVersionInfoNew.dwData)
      {
        SetFileAttributes(szFilePath, FILE_ATTRIBUTE_NORMAL);
        if(DeleteFile(szFilePath))                             
        {
          int nNullPos=strlen(szFilePath);
          for( ; nNullPos>=0; nNullPos--)
           if(szFilePath[nNullPos]=='\\')
             break;
          szFilePath[nNullPos+1]='\0';
          strcat(szFilePath, findNewFileData.cFileName);
          CopyFile(szCurrDir, szFilePath, false);                           
          bUpdate=true;
        }
        else
        {
          bCloseFinale=true;
          break; 
        }
      }
      nUpdateNums++;
    }
   }        //end:   if((lResult==ERROR_SUCCESS)&&(dwType==REG_SZ))
 }         //end:   for(int nVersion=FINALE_LAST_VERSION; nVersion>=FINALE_EARLIEST_VERSION; nVersion--)

 if(bCloseFinale)
 {
   strcpy(szUpdateText, "Close Finale ");
   strcat(szUpdateText, szFinaleVersion);
   strcat(szUpdateText, " and restart Update.");
   MessageBox( hUpdateWnd, szUpdateText, szCaption, MB_OK | MB_ICONSTOP );  
 }
 else
  if(nUpdateNums==0)
  {
    strcpy(szUpdateText, szPluginName);
    strcat(szUpdateText, " was not found.");
    MessageBox( hUpdateWnd, szUpdateText, szCaption, MB_OK | MB_ICONSTOP );  
  }
  else
   if(bUpdate)
     MessageBox( hUpdateWnd, "Update successfully completed.", szCaption, MB_OK | MB_ICONASTERISK );
   else
   {
     strcpy(szUpdateText, "You have the latest version of ");
     strcat(szUpdateText, szPluginName);
     strcat(szUpdateText, ".");
     MessageBox( hUpdateWnd, szUpdateText, szCaption, MB_OK | MB_ICONSTOP );
   }

Don't forget to replace "YourPluginName" with your real Finale plug-in name.
You can replace at the end of _tWinMain()

return (int) msg.wParam;

to

return 0;

In InitInstance() after

   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
                                     CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

insert


   hInstallWnd = hWnd;
   nCmdShow=SW_SHOWMINIMIZED;

Here are the declared above functions:

bool __stdcall  FindFile(char szFilePath[], char szFileName[])
{
  HANDLE hFile;
  WIN32_FIND_DATA findFileData;
  int nNullPos=strlen(szFilePath);

  hFile=FindFirstFile(szFilePath, &findFileData);

  if (hFile!=INVALID_HANDLE_VALUE)
  {
   do                                 //begin:  do ... while (FindNextFile(hFile, &findFileData)!=0);
    if((strcmp(findFileData.cFileName, ".")!=0)&&(strcmp(findFileData.cFileName, "..")!=0))
    {
     if(findFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
     {
       szFilePath[nNullPos-1]='\0';
       strcat(szFilePath, findFileData.cFileName); 
       strcat(szFilePath, "\\*");

       if(FindFile(szFilePath, szFileName))
       {
         FindClose(hFile);
         return true;
       }
       else
       {
         szFilePath[nNullPos-1]='*';
         szFilePath[nNullPos]='\0';
       }
     }
     else
      if(strstr(findFileData.cFileName, szFileName)!=NULL)
      {
        szFilePath[nNullPos-1]='\0';
        strcat(szFilePath, findFileData.cFileName); 
        FindClose(hFile);
        return true;
      }
    }   //end:  if((strcmp(findFileData.cFileName, ".")!=0)&&(strcmp(findFileData.cFileName, "..")!=0))
   while (FindNextFile(hFile, &findFileData)!=0);

   szFilePath[nNullPos-1]='*';
   szFilePath[nNullPos]='\0';
   FindClose(hFile);
   return false;
  }
  else
    return false;
}

//************************************************************************************************************

VOID CALLBACK WaitTimerProc                                          
   (
    HWND hWnd,         // handle of window for timer messages
    UINT uMsg,        // WM_TIMER message
    UINT idEvent,    // timer identifier
    DWORD dwTime     // current system time
   )
{
   if(idEvent==WAIT_TIMER_IDENT)                          
   {
       KillTimer(hWnd, idEvent);
       SetEvent(hWaitEvent);    
   }
}
Back to Top

author
Registered Member

Email Address Not AvailableClick to visit author's website.Send a Private Message to authorAIM Not AvailableICQ Not AvailableY! Not AvailableMSN Not Available
Date Joined Mar 2015
Total Posts : 30
 
   Posted 3/21/2016 3:33 AM (GMT -6)    Quote This PostAlert An Admin About This Post.
Your plug-ins can be removed by this uninstaller. The user only need to click the uninstaller .exe-file and then follow the uninstall wizard.
If you work in Visual C++, create Win32 Project (Windows application). Add the following code:

#include "Shlobj.h"
#include "WinNT.h"
#include "KtmW32.h"        
#include "Shellapi.h"     

#define FINALE_EARLIEST_VERSION 2004                        //Finale 2004
#define FINALE_LATEST_VERSION   2015                        //Finale 2014.5
#define FINALE_2007             2007
#define FINALE_2014_5           2015
#define MISSING_VERSION         2013
#define WINDOWS_XP              5
#define WINDOWS_VISTA           6 
#define WAIT_TIMER_IDENT        999
#define SHELL_EXECUTE_WAIT_TIME 300

Then declare the global variables and functions:

HWND hUninstallWnd;
HANDLE hWaitEvent;
int nOSVersion;

bool __stdcall FindFile(char szFilePath[], char szFileName[]);
VOID CALLBACK WaitTimerProc(HWND hWnd, UINT uMsg, UINT idEvent, DWORD dwTime);

In _tWinMain() delete the Main message loop



    // Main message loop:

    while (GetMessage(&msg, NULL, 0, 0))
    {
        if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }


and instead insert the following code:

 char szPluginName[]="YourPluginName";  // replace "YourPluginName" with your real Finale plug-in name!!!
 char szCaption[256];
 strcpy(szCaption, "Uninstall ");
 strcat(szCaption, szPluginName);
 char szFilePath[MAX_PATH];
 DWORD dwSizeFilePath=sizeof(szFilePath); 
 LONG lResult;
 HKEY  hKeyResult=0;
 char szSubkey[128];
 char szFinaleVersion[16];
 DWORD dwType;
 char szUninstallText[256];
 WIN32_FIND_DATA findFileData;
 struct 
 {
  char* lpszFullPath;
  FILETIME creationTime; 
 } 
 plugins[24];
 int nPluginNums=0;
 int nDeletedPluginNums=0;

 LPOSVERSIONINFO lpVersionInformation=new OSVERSIONINFO;
 lpVersionInformation->dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
 GetVersionEx(lpVersionInformation);
 nOSVersion=(int)lpVersionInformation->dwMajorVersion;
 delete lpVersionInformation;

//--------------------------------------------------------------------------------------------------------------
 if(nOSVersion>=WINDOWS_VISTA)
 {
    HANDLE hMutexControl=0;
    HANDLE hMutex=CreateMutex(NULL, true, "UninstallFinalePluginMutex");
    int nResult=GetLastError();
    if(nResult==ERROR_ALREADY_EXISTS)
      hMutexControl=CreateMutex(NULL, true, "UninstallFinalePluginMutexControl");   
    else
    {
      char szUninstallModuleFileName[256];
      GetModuleFileName(NULL, szUninstallModuleFileName, sizeof(szUninstallModuleFileName));

      HINSTANCE hInstanceSE=ShellExecute(NULL, "runas", szUninstallModuleFileName, 0, 0, SW_SHOWNORMAL);
      //The app re-runs itself as admin 
//-------------------------------------------------------------------------------------------------------
      if((int)hInstanceSE<32)
      {
        ReleaseMutex(hMutex);
        CloseHandle(hMutex);
        MessageBox( hUninstallWnd, "Uninstall failed. Try to uninstall manually.", szCaption, MB_OK | MB_ICONSTOP );
        return 0;
      }
//------------------------------------------------------------------------------------------------------
      bool bRepeat=true;
      do
      {
        hWaitEvent=CreateEvent(NULL, true, false, NULL);
       MSG uMessage;
       DWORD dwResult;
       bool bDone=false;
       SetTimer(hUninstallWnd, WAIT_TIMER_IDENT, SHELL_EXECUTE_WAIT_TIME, (TIMERPROC)WaitTimerProc);
              
       while( !bDone )
       {
        dwResult = MsgWaitForMultipleObjects( 1, &hWaitEvent, false, INFINITE, QS_ALLINPUT );
        if(dwResult==WAIT_OBJECT_0 + 1)
         while( PeekMessage( &uMessage, NULL, 0, 0, PM_REMOVE ) )
          if( uMessage.message == WM_QUIT )
            bDone = true;
          else
            DispatchMessage( &uMessage );
         else
             break;
       }
       ResetEvent(hWaitEvent);
       CloseHandle(hWaitEvent);   
//------------------------------------------------------------------------------------------------------
       hMutexControl = openMutex(SYNCHRONIZE, FALSE, "UninstallFinalePluginMutexControl");/////////???????
       if(hMutexControl!=0)
       {
         bRepeat=false;   
         ReleaseMutex(hMutexControl);
         CloseHandle(hMutexControl);
       }
      }
      while(bRepeat);

      ReleaseMutex(hMutex);
      CloseHandle(hMutex);
//-------------------------------------------------------------------------------------------------------
      return 0;  
    }                                //end:  if(!(nResult==ERROR_ALREADY_EXISTS))
 }                                    //end:  if(nOSVersion>=WINDOWS_VISTA)

//----------------------------------------------------------------------------------------------------------------------

 for(int nVersion=FINALE_LATEST_VERSION; nVersion>=FINALE_EARLIEST_VERSION; nVersion--)
  if(nVersion!=MISSING_VERSION)                       
  {                                                 //find all Finale versions on the computer
   if(nVersion>FINALE_2007)
   {
    strcpy(szSubkey, "SOFTWARE\\MakeMusic\\Finale"); 
   
    if(nVersion!=FINALE_2014_5)
      itoa(nVersion, szFinaleVersion, 10);
    else
      strcpy(szFinaleVersion, "2014.5");

    strcat(szSubkey, szFinaleVersion);
    lResult=RegopenKeyEx(HKEY_LOCAL_MACHINE, szSubkey, NULL, KEY_QUERY_VALUE, &hKeyResult);
    if(lResult==ERROR_SUCCESS)
    {
     lResult=RegQueryValueEx(hKeyResult, "InstallDir", NULL, &dwType, (LPBYTE)szFilePath, &dwSizeFilePath); 
     RegCloseKey(hKeyResult);
    }              //end:  if(lResult==ERROR_SUCCESS)
   }
   else
    if(nVersion==FINALE_2007)
    {
     strcpy(szSubkey, "SOFTWARE\\MakeMusic\\Finale"); 
     itoa(nVersion, szFinaleVersion, 10);
     strcat(szSubkey, szFinaleVersion);
     strcat(szSubkey, "\\InstallPath");
     lResult=RegopenKeyEx(HKEY_LOCAL_MACHINE, szSubkey, NULL, KEY_QUERY_VALUE, &hKeyResult);
     if(lResult==ERROR_SUCCESS)
     { 
      lResult=RegQueryValueEx(hKeyResult, "", NULL, &dwType, (LPBYTE)szFilePath, &dwSizeFilePath);

      RegCloseKey(hKeyResult);
      for(int n=0; n<dwSizeFilePath-4; n++)
       if((szFilePath[n]=='2')&&(szFilePath[n+1]=='0')&&(szFilePath[n+2]=='0')&&(szFilePath[n+3]=='7'))
         szFilePath[n+4]='\0';
     }                           //end:  if(lResult==ERROR_SUCCESS)
    }                           //end:  if(nVersion==FINALE_2007)
    else
    {                           //begin:  if(nVersion<FINALE_2007)    
     strcpy(szSubkey, "SOFTWARE\\CodaMusic\\Finale"); 
     itoa(nVersion, szFinaleVersion, 10);
     strcat(szSubkey, szFinaleVersion);
     strcat(szSubkey, "\\InstallPath");
     lResult=RegopenKeyEx(HKEY_LOCAL_MACHINE, szSubkey, NULL, KEY_QUERY_VALUE, &hKeyResult);
     if(lResult==ERROR_SUCCESS)
     {
      lResult=RegQueryValueEx(hKeyResult, "", NULL, &dwType, (LPBYTE)szFilePath, &dwSizeFilePath);
                                  
      RegCloseKey(hKeyResult);
      for(int n=0; n<dwSizeFilePath-4; n++)
       if((szFilePath[n]=='2')&&(szFilePath[n+1]=='0')&&(szFilePath[n+2]=='0')&&
           ((szFilePath[n+3]=='4')||(szFilePath[n+3]=='5')||(szFilePath[n+3]=='6')))
         szFilePath[n+4]='\0';
     }                           //end:  if(lResult==ERROR_SUCCESS)
    }                           //end:  if(nVersion<FINALE_2007)

   if((lResult==ERROR_SUCCESS)&&(dwType==REG_SZ))
   {
    strcat(szFilePath, "\\Plug-ins\\*");
    if(FindFile(szFilePath, szPluginName))
    {
      plugins[nPluginNums].lpszFullPath=new char[256];
      strcpy(plugins[nPluginNums].lpszFullPath, szFilePath); 
      plugins[nPluginNums].creationTime=findFileData.ftCreationTime;
      nPluginNums++;
    }
   }        //end:   if((lResult==ERROR_SUCCESS)&&(dwType==REG_SZ))
 }         //end:   for(int nVersion=FINALE_LAST_VERSION; nVersion>=2004; nVersion--)

 if(nPluginNums==0)
 {
   strcpy(szUninstallText,  szPluginName);
   strcat(szUninstallText, " was not found.");
   MessageBox( hUninstallWnd, szUninstallText, szCaption, MB_OK | MB_ICONSTOP );  
 }
 else
 {
   for(int nNum=0; nNum<nPluginNums; nNum++)
   {
     if(nPluginNums==1)
     {
      strcpy(szUninstallText,  "Are you sure you want to remove ");
      strcat(szUninstallText,  szPluginName);
      strcat(szUninstallText,  "?");
     }
     else
     {
        strcpy(szUninstallText, "Are you sure you want to remove ");
        strcat(szUninstallText,  szPluginName);
        strcat(szUninstallText,  " from Finale ");
        int nFullPath=strlen(plugins[nNum].lpszFullPath);

        for(int n=0; n<nFullPath; n++)
         if(((char)*(plugins[nNum].lpszFullPath+n)=='2')&&
            ((char)*(plugins[nNum].lpszFullPath+n+1)=='0')&&
            ((char)*(plugins[nNum].lpszFullPath+n+2)>='0')&&
            ((char)*(plugins[nNum].lpszFullPath+n+2)<='9')&&
            ((char)*(plugins[nNum].lpszFullPath+n+3)>='0')&&
            ((char)*(plugins[nNum].lpszFullPath+n+3)<='9'))
         {
           szFinaleVersion[0]=(char)*(plugins[nNum].lpszFullPath+n);
           szFinaleVersion=(char)*(plugins[nNum].lpszFullPath+n+1);
           szFinaleVersion=(char)*(plugins[nNum].lpszFullPath+n+2);
           szFinaleVersion=(char)*(plugins[nNum].lpszFullPath+n+3);
           szFinaleVersion='\0';
           if(((char)*(plugins[nNum].lpszFullPath+n+2)=='1')&&
              ((char)*(plugins[nNum].lpszFullPath+n+3)=='4')&&
              ((char)*(plugins[nNum].lpszFullPath+n+4)=='.')&&
              ((char)*(plugins[nNum].lpszFullPath+n+5)=='5'))
             strcat(szFinaleVersion, ".5"); 

           strcat(szUninstallText, szFinaleVersion); 
           strcat(szUninstallText, "?");
           break;
         }
     }
     int nDialogRetValue=MessageBox( hUninstallWnd, szUninstallText, szCaption,
                                     MB_YESNOCANCEL | MB_ICONQUESTION | MB_DEFBUTTON1 );

     if(nDialogRetValue==IDYES)
     {
      WIN32_FIND_DATA findDirData;
      HANDLE hDir;

      SetFileAttributes(plugins[nNum].lpszFullPath, FILE_ATTRIBUTE_NORMAL);
      if(DeleteFile(plugins[nNum].lpszFullPath))  
      {
//************************************** if you want to delete the empty folder *****************************//begin
        ULONGLONG qwFileTime, qwDirTime;
        qwFileTime = (((ULONGLONG) plugins[nNum].creationTime.dwHighDateTime) << 32) + 
                                   plugins[nNum].creationTime.dwLowDateTime;
        qwFileTime>>=24;
        int nNullPos=strlen(plugins[nNum].lpszFullPath);
        for( ; nNullPos>=0; nNullPos--)
         if((char)*(plugins[nNum].lpszFullPath+nNullPos)=='\\')
         {
           (char)*(plugins[nNum].lpszFullPath+nNullPos)='\0';
           break;
         }

        hDir=FindFirstFile(plugins[nNum].lpszFullPath, &findDirData);
        if (hDir!=INVALID_HANDLE_VALUE)
        {
          qwDirTime = (((ULONGLONG) findDirData.ftCreationTime.dwHighDateTime) << 32) + 
                                    findDirData.ftCreationTime.dwLowDateTime;
          qwDirTime>>=24;
          if(qwFileTime-qwDirTime<600)       //if the folder was created in less than 10min before the file 
            RemoveDirectory(plugins[nNum].lpszFullPath);

          FindClose(hDir);
        }
//****************************************************************************************************************//end
        nDeletedPluginNums++;
        MessageBox( hUninstallWnd, "Uninstall successfully completed.", szCaption, MB_OK | MB_ICONASTERISK );
      }
      else
      {
        strcpy(szUninstallText, "Close Finale ");
        strcat(szUninstallText, szFinaleVersion);
        strcat(szUninstallText, " and restart Uninstall.");
        MessageBox( hUninstallWnd, szUninstallText, szCaption, MB_OK | MB_ICONASTERISK );
        for( ; nNum<nPluginNums; nNum++)
         delete[] plugins[nNum].lpszFullPath;
        break;
      }
     }
     else
      if(nDialogRetValue==IDCANCEL)
      {
        for( ; nNum<nPluginNums; nNum++)
         delete[] plugins[nNum].lpszFullPath;
        break;
      }

     delete[] plugins[nNum].lpszFullPath; 
   }                                       //end:   for(int nNum=0; nNum<nPluginNums; nNum++)

//************************** if your plug-in created the registry keys or ini-files ***************************//begin
   if(nDeletedPluginNums==nPluginNums)
   {
     RegDeleteKey(HKEY_CURRENT_USER, "SOFTWARE\\YourPluginName");  //delete subkey YourPluginName from 
                                                                   //the registry key HKEY_CURRENT_USER
     RegDeleteKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\YourPluginName");  //delete subkey YourPluginName from
                                                                    //the registry key HKEY_LOCAL_MACHINE  
     LPVOID lpvEnv;                                   
     lpvEnv = GetEnvironmentStrings();
     char* szPluginIniName=new char[MAX_PATH];
     char* szPluginAllUsersIniName=new char[MAX_PATH];                           

     GetEnvironmentVariable("APPDATA", szPluginIniName, MAX_PATH);  
     GetEnvironmentVariable("ALLUSERSPROFILE", szPluginAllUsersIniName, MAX_PATH);
     if(nOSVersion==WINDOWS_XP)
       strcat(szPluginAllUsersIniName, "\\Application Data");

     FreeEnvironmentStrings((LPTSTR)lpvEnv);
     char* szPathTemp=new char[256];

     strcpy(szPathTemp, szPluginIniName);
     strcat(szPathTemp, "\\YourName");
     strcat(szPathTemp, "\\YOURPLUGINNAME.INI");
     if(DeleteFile(szPathTemp))                    //delete the file YOURPLUGINNAME.INI from APPDATA   
     {
       strcpy(szPathTemp, szPluginIniName);
       strcat(szPathTemp, "\\YourName");
       RemoveDirectory(szPathTemp);                   //delete the folder YourFolderName  from APPDATA
     }   

     strcpy(szPathTemp, szPluginAllUsersIniName);
     strcat(szPathTemp, "\\YourName");
     strcat(szPathTemp, "\\YOURPLUGINNAME.INI");
     if(DeleteFile(szPathTemp))                //delete the file YOURPLUGINNAME.INI from ALLUSERSPROFILE
     {
       strcpy(szPathTemp, szPluginAllUsersIniName);
       strcat(szPathTemp, "\\YourName");
       RemoveDirectory(szPathTemp);                //delete the folder YourFolderName from ALLUSERSPROFILE
     }

     delete[] szPathTemp;
     delete[] szPluginIniName;
     delete[] szPluginAllUsersIniName;
   }                                      //end:  if(nDeletedPluginNums==nPluginNums)
//**************************************************************************************************************//end
 }                                     //end:  if(nPluginNums>0)

Don't forget to replace "YourPluginName" and "YourFolderName" with the real names.
You can replace at the end of _tWinMain()


return (int) msg.wParam;


to


return 0;


In InitInstance() after


   hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
                                     CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);


insert



   hInstallWnd = hWnd;
   nCmdShow=SW_SHOWMINIMIZED;


Here are the declared above functions:

bool __stdcall  FindFile(char szFilePath[], char szFileName[])
{
  HANDLE hFile;
  WIN32_FIND_DATA findFileData;
  int nNullPos=strlen(szFilePath);

  hFile=FindFirstFile(szFilePath, &findFileData);

  if (hFile!=INVALID_HANDLE_VALUE)
  {
   do                                 //begin:  do ... while (FindNextFile(hFile, &findFileData)!=0);
    if((strcmp(findFileData.cFileName, ".")!=0)&&(strcmp(findFileData.cFileName, "..")!=0))
    {
     if(findFileData.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY)
     {
       szFilePath[nNullPos-1]='\0';
       strcat(szFilePath, findFileData.cFileName); 
       strcat(szFilePath, "\\*");

       if(FindFile(szFilePath, szFileName))
       {
         FindClose(hFile);
         return true;
       }
       else
       {
         szFilePath[nNullPos-1]='*';
         szFilePath[nNullPos]='\0';
       }
     }
     else
      if(strstr(findFileData.cFileName, szFileName)!=NULL)
      {
        szFilePath[nNullPos-1]='\0';
        strcat(szFilePath, findFileData.cFileName); 
        FindClose(hFile);
        return true;
      }
    }   //end:  if((strcmp(findFileData.cFileName, ".")!=0)&&(strcmp(findFileData.cFileName, "..")!=0))
   while (FindNextFile(hFile, &findFileData)!=0);

   szFilePath[nNullPos-1]='*';
   szFilePath[nNullPos]='\0';
   FindClose(hFile);
   return false;
  }
  else
    return false;
}

//************************************************************************************************

VOID CALLBACK WaitTimerProc                                          
   (
    HWND hWnd,         // handle of window for timer messages
    UINT uMsg,        // WM_TIMER message
    UINT idEvent,    // timer identifier
    DWORD dwTime     // current system time
   )
{
   if(idEvent==WAIT_TIMER_IDENT)                          
   {
       KillTimer(hWnd, idEvent);
       SetEvent(hWaitEvent);    
   }
}

Post Edited (author) : 3/21/2016 1:37:19 PM (GMT-5)

Back to Top
You cannot post new topics in this forum. You cannot reply to topics in this forum. Printable Version
   
Forum Information
Currently it is Tuesday, December 19, 2023 6:03 PM (GMT -6)
There are a total of 403,820 posts in 58,165 threads.
In the last 3 days there were 0 new threads and 0 reply posts. View Active Threads