diff --git a/build/linux/platform_specific_code/juce_linux_Files.cpp b/build/linux/platform_specific_code/juce_linux_Files.cpp index fb4db05359..39f2bd243f 100644 --- a/build/linux/platform_specific_code/juce_linux_Files.cpp +++ b/build/linux/platform_specific_code/juce_linux_Files.cpp @@ -294,6 +294,12 @@ bool File::setAsCurrentWorkingDirectory() const throw() return chdir (getFullPathName().toUTF8()) == 0; } +//============================================================================== +const String File::getVersion() const throw() +{ + return String::empty; // xxx not yet implemented +} + //============================================================================== const File File::getLinkedTarget() const throw() { diff --git a/build/macosx/platform_specific_code/juce_mac_Files.mm b/build/macosx/platform_specific_code/juce_mac_Files.mm index cb3bfb2552..eeaba4762a 100644 --- a/build/macosx/platform_specific_code/juce_mac_Files.mm +++ b/build/macosx/platform_specific_code/juce_mac_Files.mm @@ -330,6 +330,30 @@ bool File::setAsCurrentWorkingDirectory() const throw() return chdir (getFullPathName().toUTF8()) == 0; } +//============================================================================== +const String File::getVersion() const throw() +{ + const ScopedAutoReleasePool pool; + String result; + + NSBundle* bundle = [NSBundle bundleWithPath: juceStringToNS (getFullPathName())]; + + if (bundle != 0) + { + NSDictionary* info = [bundle infoDictionary]; + + if (info != 0) + { + NSString* name = [info valueForKey: @"CFBundleShortVersionString"]; + + if (name != nil) + result = nsStringToJuce (name); + } + } + + return result; +} + //============================================================================== const File File::getLinkedTarget() const throw() { diff --git a/build/win32/platform_specific_code/juce_win32_Files.cpp b/build/win32/platform_specific_code/juce_win32_Files.cpp index d8ca9eae81..94c990e295 100644 --- a/build/win32/platform_specific_code/juce_win32_Files.cpp +++ b/build/win32/platform_specific_code/juce_win32_Files.cpp @@ -524,6 +524,35 @@ bool File::setAsCurrentWorkingDirectory() const throw() return SetCurrentDirectory (getFullPathName()) != FALSE; } + +//============================================================================== +const String File::getVersion() const throw() +{ + String result; + + DWORD handle = 0; + DWORD bufferSize = GetFileVersionInfoSize (getFullPathName(), &handle); + void* buffer = juce_calloc (bufferSize); + + if (GetFileVersionInfo (getFullPathName(), 0, bufferSize, buffer)) + { + VS_FIXEDFILEINFO* vffi; + UINT len = 0; + + if (VerQueryValue (buffer, _T("\\"), (LPVOID*) &vffi, &len)) + { + result.printf (T("%d.%d.%d.%d"), + HIWORD (vffi->dwFileVersionMS), + LOWORD (vffi->dwFileVersionMS), + HIWORD (vffi->dwFileVersionLS), + LOWORD (vffi->dwFileVersionLS)); + } + } + + juce_free (buffer); + return result; +} + //============================================================================== const File File::getLinkedTarget() const throw() { diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index 38a93518d8..3286c874ea 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -240405,6 +240405,33 @@ bool File::setAsCurrentWorkingDirectory() const throw() return SetCurrentDirectory (getFullPathName()) != FALSE; } +const String File::getVersion() const throw() +{ + String result; + + DWORD handle = 0; + DWORD bufferSize = GetFileVersionInfoSize (getFullPathName(), &handle); + void* buffer = juce_calloc (bufferSize); + + if (GetFileVersionInfo (getFullPathName(), 0, bufferSize, buffer)) + { + VS_FIXEDFILEINFO* vffi; + UINT len = 0; + + if (VerQueryValue (buffer, _T("\\"), (LPVOID*) &vffi, &len)) + { + result.printf (T("%d.%d.%d.%d"), + HIWORD (vffi->dwFileVersionMS), + LOWORD (vffi->dwFileVersionMS), + HIWORD (vffi->dwFileVersionLS), + LOWORD (vffi->dwFileVersionLS)); + } + } + + juce_free (buffer); + return result; +} + const File File::getLinkedTarget() const throw() { File result (*this); @@ -254599,6 +254626,11 @@ bool File::setAsCurrentWorkingDirectory() const throw() return chdir (getFullPathName().toUTF8()) == 0; } +const String File::getVersion() const throw() +{ + return String::empty; // xxx not yet implemented +} + const File File::getLinkedTarget() const throw() { char buffer [4096]; @@ -264629,6 +264661,29 @@ bool File::setAsCurrentWorkingDirectory() const throw() return chdir (getFullPathName().toUTF8()) == 0; } +const String File::getVersion() const throw() +{ + const ScopedAutoReleasePool pool; + String result; + + NSBundle* bundle = [NSBundle bundleWithPath: juceStringToNS (getFullPathName())]; + + if (bundle != 0) + { + NSDictionary* info = [bundle infoDictionary]; + + if (info != 0) + { + NSString* name = [info valueForKey: @"CFBundleShortVersionString"]; + + if (name != nil) + result = nsStringToJuce (name); + } + } + + return result; +} + const File File::getLinkedTarget() const throw() { FSRef ref; diff --git a/juce_amalgamated.h b/juce_amalgamated.h index 59e3d10434..d9063beae5 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -6405,6 +6405,14 @@ public: */ bool setCreationTime (const Time& newTime) const throw(); + /** If possible, this will try to create a version string for the given file. + + The OS may be able to look at the file and give a version for it - e.g. with + executables, bundles, dlls, etc. If no version is available, this will + return an empty string. + */ + const String getVersion() const throw(); + /** Creates an empty file if it doesn't already exist. If the file that this object refers to doesn't exist, this will create a file diff --git a/src/juce_core/io/files/juce_File.h b/src/juce_core/io/files/juce_File.h index 5953f77128..b80e7878f1 100644 --- a/src/juce_core/io/files/juce_File.h +++ b/src/juce_core/io/files/juce_File.h @@ -404,6 +404,14 @@ public: */ bool setCreationTime (const Time& newTime) const throw(); + /** If possible, this will try to create a version string for the given file. + + The OS may be able to look at the file and give a version for it - e.g. with + executables, bundles, dlls, etc. If no version is available, this will + return an empty string. + */ + const String getVersion() const throw(); + //============================================================================== /** Creates an empty file if it doesn't already exist.