svnno****@sourc*****
svnno****@sourc*****
2010年 8月 29日 (日) 23:12:56 JST
Revision: 4065 http://sourceforge.jp/projects/ttssh2/svn/view?view=rev&revision=4065 Author: maya Date: 2010-08-29 23:12:56 +0900 (Sun, 29 Aug 2010) Log Message: ----------- svnversion.h の更新をしなくてもよいときには更新しないようにした Modified Paths: -------------- trunk/installer/build.bat trunk/teraterm/svnrev/svnrev.cpp trunk/teraterm/ttpdlg/ttpdlg.vcproj -------------- next part -------------- Modified: trunk/installer/build.bat =================================================================== --- trunk/installer/build.bat 2010-08-29 11:31:46 UTC (rev 4064) +++ trunk/installer/build.bat 2010-08-29 14:12:56 UTC (rev 4065) @@ -13,9 +13,7 @@ devenv /build release ..\teraterm\ttermpro.sln /project svnrev /projectconfig release :svnrev -pushd ..\teraterm -release\svnrev.exe > ttpdlg\svnversion.h -popd +..\teraterm\release\svnrev.exe :build devenv /%BUILD% release ..\teraterm\ttermpro.sln Modified: trunk/teraterm/svnrev/svnrev.cpp =================================================================== --- trunk/teraterm/svnrev/svnrev.cpp 2010-08-29 11:31:46 UTC (rev 4064) +++ trunk/teraterm/svnrev/svnrev.cpp 2010-08-29 14:12:56 UTC (rev 4065) @@ -9,54 +9,115 @@ using namespace std; -int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) -{ - int nRetCode = 0; +// Get revision fron "entries" file. +int get_svn_revision(char *path) { + BOOL ret; + CStdioFile csf; + CString cs, filename; + int format = -1; int revision = -1; - if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) - { - nRetCode = 1; + filename = path; + filename += "\\.svn\\entries"; // [top of source tree]\.svn\entries + + ret = csf.Open(filename, CFile::modeRead); + if (ret == FALSE) { + return -1; } - else - { - BOOL ret; - CStdioFile csf; - CString cs; - int format = -1; - - // [top of source tree]\.svn\entries - ret = csf.Open("..\\..\\.svn\\entries", CFile::modeRead); - if (ret == FALSE) { - nRetCode = 1; - } - else { - csf.SeekToBegin(); - // line 1 - csf.ReadString(cs); - format = atoi(cs); + csf.SeekToBegin(); - if (format == 8 || format == 9 || format == 10) { - // skip line 2 name, 3 kind - csf.ReadString(cs); - csf.ReadString(cs); + // line 1 + csf.ReadString(cs); + format = atoi(cs); - // line 4 revision - csf.ReadString(cs); - revision = atoi(cs); - } + if (format == 8 || format == 9 || format == 10) { + // skip line 2 name, 3 kind + csf.ReadString(cs); + csf.ReadString(cs); - csf.Close(); - } + // line 4 revision + csf.ReadString(cs); + revision = atoi(cs); } - if (nRetCode == 0) { - printf("#define SVNVERSION %d\n", revision); + csf.Close(); + + return revision; +} + +BOOL write_svn_revesion(char *path, int revision) { + BOOL ret; + CStdioFile csf; + CString cs, filename; + int file_revision = -1; + + filename = path; + filename += "\\teraterm\\ttpdlg\\svnversion.h"; + + + // read current file + ret = csf.Open(filename, CFile::modeRead); + if (ret == TRUE) { + csf.SeekToBegin(); + csf.ReadString(cs); + csf.Close(); + + ret = sscanf_s(cs, "#define SVNVERSION %d", &file_revision); } + + // compare revisions + if (file_revision >= revision) { + return TRUE; + } + + ret = csf.Open(filename, CFile::modeWrite | CFile::modeCreate); + if (ret == FALSE) { + return FALSE; + } + + if (revision >= 1) { + cs.Format("#define SVNVERSION %d\n", revision); + csf.WriteString(cs); + } else { - printf("#undef SVNVERSION\n"); + cs.Format("#undef SVNVERSION\n"); + csf.WriteString(cs); } - return nRetCode; + csf.Close(); + + return TRUE; } + +int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) +{ + int nRetCode = 0; + int revision = -1; + char path[MAX_PATH * 2]; + int i, len; + + if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)) { + return 1; + } + + GetModuleFileName(::GetModuleHandle(NULL), path, sizeof(path)); + len = (int)strlen(path); + for (i=len; i>=0; i--) { + if (path[i] == '\\') { + break; + } + path[i] = '\0'; + } + SetCurrentDirectory(path); // teraterm\debug or teraterm\release + SetCurrentDirectory("..\\..\\"); // top of source tree + GetCurrentDirectory(sizeof(path), path); + + revision = get_svn_revision(path); + + if (!write_svn_revesion(path, revision)) { + return 1; + } + + return 0; +} Modified: trunk/teraterm/ttpdlg/ttpdlg.vcproj =================================================================== --- trunk/teraterm/ttpdlg/ttpdlg.vcproj 2010-08-29 11:31:46 UTC (rev 4064) +++ trunk/teraterm/ttpdlg/ttpdlg.vcproj 2010-08-29 14:12:56 UTC (rev 4065) @@ -25,7 +25,7 @@ > <Tool Name="VCPreBuildEventTool" - CommandLine="$(OutDir)\svnrev.exe > "$(InputDir)svnversion.h"" + CommandLine="$(OutDir)\svnrev.exe" /> <Tool Name="VCCustomBuildTool" @@ -126,7 +126,7 @@ > <Tool Name="VCPreBuildEventTool" - CommandLine="$(OutDir)\svnrev.exe > "$(InputDir)svnversion.h"" + CommandLine="$(OutDir)\svnrev.exe" /> <Tool Name="VCCustomBuildTool"