Codice PHP:
// BATCH.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <string.h>
#include <sstream>
#include <tchar.h>
#include <stdio.h>
#define P _tcprintf
#define T TEXT
#define PUT(text) P(T(text))
#define PUTL(textEng,textIta) P(L(T(textEng),T(textIta)))
#define LT(textEng,textIta) L(T(textEng),T(textIta))
#define Sl Sleep
#define S _tcscanf
#define _ENGLISH 1
#define _ITALIAN 2
BOOL SetLanguage();
BOOL SetBatchPath();
BOOL CreateListOfBatch();
TCHAR * szAppName = T("BATCH UTILITY EDITION 1.0 © 2010 [NO GRAPHICAL USER INTERFACE]");
TCHAR szFinalBatchPath[MAX_PATH];
short unsigned int fLanguage;
FILE * FLanguage;
FILE * FBatchPath;
FILE * FListOfBatch;
HANDLE hFind;
WIN32_FIND_DATA wfd;
inline TCHAR * L (TCHAR * szEng, TCHAR * szIta)
{
return fLanguage == _ENGLISH ? szEng : szIta;
}
inline TCHAR * AdjustStringBug(TCHAR * szStringToAdjust)
{
TCHAR szStringAdjusted [MAX_PATH];
for(int i = 0, j = 0; i < MAX_PATH; i++)
{
switch(szStringToAdjust[i])
{
case 0x0008 : if(j != 0)j--; //Se il carattere è backspace cancella un carattere, ma solo se la stringa ha almeno un carattere
break;
case 0 : szStringAdjusted[j] = szStringToAdjust[i];
return szStringAdjusted;
default : szStringAdjusted[j] = szStringToAdjust[i];
j++;
break;
}
}
return T("ERROR");
}
//Per gestire la lingua o italiana o inglese....
//Forse un po' rudimentale ma lavora...:)
using namespace std;
int _tmain(int argc, TCHAR *argv[])
{
//Questo blocco di codice serve per impostare la lingua dl programma
{
FLanguage = fopen("Language.ini","r+");
if(FLanguage == NULL) SetLanguage();
else
{
TCHAR * szBufferFLanguage;
szBufferFLanguage = new TCHAR [10];
_ftscanf(FLanguage,T("%s"),szBufferFLanguage);
if(szBufferFLanguage[0] == '1') fLanguage = _ENGLISH;
if(szBufferFLanguage[0] == '2') fLanguage = _ITALIAN;
delete [] szBufferFLanguage;
}
fclose(FLanguage);
}
//Questo blocco di codice serve per impostare il percorso dove si trovano i file batch
FBatchPath = fopen("BatchPath.ini","r+");
{
if(FBatchPath == NULL)
{
if(!SetBatchPath()) PUTL("\n\n\tFATAL ERROR!\nA fatal error has occured in the setting of the batch patch.\n\
However software may be able to work correctly.",
"\n\n\tERRORE FATALE!\nIl programma ha riscontrato un errore fatale nella configurazione del percorso dei file batch\n\
Comunque è possibile che il software lavori correttamente.");
CreateListOfBatch();
}
else
{
FBatchPath = _tfopen(T("BatchPath.ini"),T("r+"));
TCHAR * szBufferFBatchPath;
szBufferFBatchPath = new TCHAR [MAX_PATH];
_ftscanf(FLanguage,T("%s"),szBufferFBatchPath);
_tcscpy(szFinalBatchPath,szBufferFBatchPath);
delete [] szBufferFBatchPath;
}
fclose(FBatchPath);
fclose(FListOfBatch);
}
PUTL("Welcom in BATCH UTILITY EDITION 1.0 © 2010 [NO GRAPHICAL USER INTERFACE]\n",
"Benvenuto in BATCH UTILITY EDITION 1.0 © 2010 [NO INTERFACCIA GRAFICA]\n");
PUT("\n");
_tsystem(T("PAUSE"));
return EXIT_SUCCESS;
}
BOOL SetLanguage()
{
P(T("%s\n"),szAppName);
P(T("First Time Configuration\n"));
gRetryLanguageSetting: //Da evitare ma funziona anche qui
try
{
int iLanguageChoice;
P(T("Select the language: 1 English, 2 Italian "));
S(T("%i"),&iLanguageChoice);
//Ovviamente se dqai un'input di carattere va tutto in balla...
//Non ho mai capito come sistemare.... -.^"
if(iLanguageChoice == 1)
{
fLanguage = _ENGLISH;
P(T("\nThe main language is setted as English\n"));
//Funzione deprecata....
FLanguage = fopen("Language.ini","w");
_ftprintf(FLanguage,T("%s"),T("1"));
return TRUE;
}
else if (iLanguageChoice == 2)
{
fLanguage = _ITALIAN;
P(T("\nIl linguaggio principale scelto è l'Italiano\n"));
//Funzione deprecata....
FLanguage = _tfopen(T("Language.ini"),T("w"));
_ftprintf(FLanguage,T("%s"),T("2"));
return TRUE;
}
else throw(T("You have to insert correctly the number\n\n"));
}
catch(const TCHAR * szErrorDetails)
{
P(szErrorDetails);
goto gRetryLanguageSetting;
}
}
BOOL SetBatchPath()
{
//Per stabilire il percorso dei file batch
GRetryBatchPathSetting:
try
{
TCHAR * szPathBatchFiles;
szPathBatchFiles = new TCHAR [MAX_PATH];
PUTL("Please enter the full path of the folder where your batch files are stored\n\
example: C:\\Users\\myFolderName\\desktop\\myBatchFiles\n",
"Perfavore digiti il percorso completo della cartella dove sono situati i toui file batch\n\
esempio: C:\\Users\\NomeCartella\\desktop\\MieiFileBatch\n");
S(T("%s"),szPathBatchFiles);
P(T("\nThis is the path %s\n"),szPathBatchFiles);
szPathBatchFiles = AdjustStringBug(szPathBatchFiles);
if(!_tcscmp(szPathBatchFiles,T("ERROR")))
return FALSE;
//Nella stringa ci sono dei difetti: per esempio premendo il tasto BACKSPACE nella stringa si aggiunge il carattere '\c', che va tolto manualmente
hFind = FindFirstFile (szPathBatchFiles, &wfd);
P(T("wfd.cFileName = %s\n"),wfd.cFileName);
P(T("(int)hFind = %i\n"),(int)hFind);
if((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY)
{
PUTL("\nThe path is valid\n","\nIl percorso è valido\n");
_tcscpy(szFinalBatchPath,szPathBatchFiles);
FBatchPath = _tfopen(T("BatchPath.ini"),T("w"));
//_ftprintf(FBatchPath,T("%s"),szPathBatchFiles);
_fputts(szFinalBatchPath,FBatchPath);
P(T("This is the merd!%s\n"),szPathBatchFiles);
//ERRORE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< QUI IN QUESTO BLOCCO C'E' ERRORE IN RUN TIME.....MA LA COSA SUBDOLA E' CHE NON CRASHA....SEMPLICEMENTE NON LAVORA PIU'....xD
delete [] szPathBatchFiles;
FindClose(hFind);
return TRUE;
}
else if((int)hFind == -1)//Il file o la directory non esistono
throw(LT("\nThe inserted path doesn't exist, please retry.\n\n","\nIl percorso inserito non esiste, perfavore riprovare.\n\n"));
else
throw(LT("\nThe inserted path is corresponds to a file, you have to insert the path of a folder, not of a file.\n\n",
"\nIl percorso inserito corrisponde ad un file, è necessario inserire il percorso di una cartella, non di un file.\n\n"));
}
catch(const TCHAR * szErrorDetails)
{
P(szErrorDetails);
goto GRetryBatchPathSetting;
}
}
BOOL CreateListOfBatch()
{
TCHAR * szFinalBatchPathFind;
szFinalBatchPathFind = new TCHAR [MAX_PATH];
_tcscpy(szFinalBatchPathFind,szFinalBatchPath);
_tcscat(szFinalBatchPathFind,T("\\*"));
hFind = FindFirstFile (szFinalBatchPathFind, &wfd);
if(
wfd.cFileName[_tcslen(wfd.cFileName) - 3] == T('.') &&
wfd.cFileName[_tcslen(wfd.cFileName) - 3] == T('b') &&
wfd.cFileName[_tcslen(wfd.cFileName) - 2] == T('a') &&
wfd.cFileName[_tcslen(wfd.cFileName) - 1] == T('t')
)
{
FListOfBatch = _tfopen(T("ListOfBatch.ini"),T("a"));
_ftprintf(FListOfBatch,T("%s\n"),wfd.cFileName);
}
while(!FindNextFile(hFind, &wfd))
{
if(
wfd.cFileName[_tcslen(wfd.cFileName) - 3] == T('.') &&
wfd.cFileName[_tcslen(wfd.cFileName) - 3] == T('b') &&
wfd.cFileName[_tcslen(wfd.cFileName) - 2] == T('a') &&
wfd.cFileName[_tcslen(wfd.cFileName) - 1] == T('t')
)
{
FListOfBatch = _tfopen(T("ListOfBatch.ini"),T("a"));
_ftprintf(FListOfBatch,T("%s\n"),wfd.cFileName);
}
}
return TRUE;
}