Browse Source

Added a File::getVersion() method

tags/2021-05-28
jules 17 years ago
parent
commit
b89cc9dcc7
6 changed files with 130 additions and 0 deletions
  1. +6
    -0
      build/linux/platform_specific_code/juce_linux_Files.cpp
  2. +24
    -0
      build/macosx/platform_specific_code/juce_mac_Files.mm
  3. +29
    -0
      build/win32/platform_specific_code/juce_win32_Files.cpp
  4. +55
    -0
      juce_amalgamated.cpp
  5. +8
    -0
      juce_amalgamated.h
  6. +8
    -0
      src/juce_core/io/files/juce_File.h

+ 6
- 0
build/linux/platform_specific_code/juce_linux_Files.cpp View File

@@ -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()
{


+ 24
- 0
build/macosx/platform_specific_code/juce_mac_Files.mm View File

@@ -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()
{


+ 29
- 0
build/win32/platform_specific_code/juce_win32_Files.cpp View File

@@ -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()
{


+ 55
- 0
juce_amalgamated.cpp View File

@@ -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;


+ 8
- 0
juce_amalgamated.h View File

@@ -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


+ 8
- 0
src/juce_core/io/files/juce_File.h View File

@@ -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.


Loading…
Cancel
Save