diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 222a39d36c..7ede5128bb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -958,7 +958,6 @@ set (PCH_SOURCES stats.cpp stringtable.cpp teaminfo.cpp - tempfiles.cpp v_blend.cpp v_collection.cpp v_draw.cpp @@ -1179,6 +1178,7 @@ add_executable( zdoom WIN32 MACOSX_BUNDLE ${PCH_SOURCES} x86.cpp strnatcmp.c + tmpfileplus.c zstring.cpp math/asin.c math/atan.c diff --git a/src/sound/i_music.cpp b/src/sound/i_music.cpp index b66e5d0968..19db0161db 100644 --- a/src/sound/i_music.cpp +++ b/src/sound/i_music.cpp @@ -59,7 +59,6 @@ extern void ChildSigHandler (int signum); #include "s_sound.h" #include "m_swap.h" #include "i_cd.h" -#include "tempfiles.h" #include "templates.h" #include "stats.h" #include "timidity/timidity.h" diff --git a/src/sound/i_musicinterns.h b/src/sound/i_musicinterns.h index 9bf9f8aede..7bc5a31e5d 100644 --- a/src/sound/i_musicinterns.h +++ b/src/sound/i_musicinterns.h @@ -1,5 +1,4 @@ -#include "tempfiles.h" #include "oplsynth/opl_mus_player.h" #include "c_cvars.h" #include "mus2midi.h" diff --git a/src/sound/mididevices/music_timiditypp_mididevice.cpp b/src/sound/mididevices/music_timiditypp_mididevice.cpp index b0ce41eade..d4c03534d4 100644 --- a/src/sound/mididevices/music_timiditypp_mididevice.cpp +++ b/src/sound/mididevices/music_timiditypp_mididevice.cpp @@ -42,6 +42,7 @@ #include "cmdlib.h" #include "templates.h" #include "version.h" +#include "tmpfileplus.h" #ifndef _WIN32 #include @@ -81,13 +82,12 @@ public: protected: bool LaunchTimidity(); - FTempFileName DiskName; + char* DiskName; #ifdef _WIN32 HANDLE ReadWavePipe; HANDLE WriteWavePipe; HANDLE ChildProcess; FString CommandLine; - size_t LoopPos; bool Validated; bool ValidateTimidity(); #else // _WIN32 @@ -166,7 +166,7 @@ CUSTOM_CVAR (Int, timidity_frequency, 44100, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) //========================================================================== TimidityPPMIDIDevice::TimidityPPMIDIDevice(const char *args) - : DiskName("zmid"), + : DiskName(nullptr), #ifdef _WIN32 ReadWavePipe(INVALID_HANDLE_VALUE), WriteWavePipe(INVALID_HANDLE_VALUE), ChildProcess(INVALID_HANDLE_VALUE), @@ -194,12 +194,6 @@ TimidityPPMIDIDevice::TimidityPPMIDIDevice(const char *args) CommandLine += "\" "; } #endif - - if (DiskName == NULL) - { - Printf(PRINT_BOLD, "Could not create temp music file\n"); - return; - } } //========================================================================== @@ -210,6 +204,12 @@ TimidityPPMIDIDevice::TimidityPPMIDIDevice(const char *args) TimidityPPMIDIDevice::~TimidityPPMIDIDevice () { + if (nullptr != DiskName) + { + remove(DiskName); + free(DiskName); + } + #if _WIN32 if (WriteWavePipe != INVALID_HANDLE_VALUE) { @@ -252,17 +252,12 @@ bool TimidityPPMIDIDevice::Preprocess(MIDIStreamer *song, bool looping) return false; } - // Tell TiMidity++ whether it should loop or not -#ifdef _WIN32 - CommandLine.LockBuffer()[LoopPos] = looping ? 'l' : ' '; - CommandLine.UnlockBuffer(); -#endif Looping = looping; // Write MIDI song to temporary file song->CreateSMF(midi, looping ? 0 : 1); - f = fopen(DiskName, "wb"); + f = tmpfileplus(nullptr, "zmid", &DiskName, 1); if (f == NULL) { Printf(PRINT_BOLD, "Could not open temp music file\n"); @@ -275,6 +270,16 @@ bool TimidityPPMIDIDevice::Preprocess(MIDIStreamer *song, bool looping) { Printf(PRINT_BOLD, "Could not write temp music file\n"); } + +#ifdef _WIN32 + CommandLine.AppendFormat("-o - -Ors%c%c%c -id%c %s", + timidity_stereo ? 'S' : 'M', + timidity_8bit ? '8' : '1', + timidity_byteswap ? 'x' : ' ', + looping ? 'l' : ' ', + DiskName); +#endif + return false; } @@ -342,20 +347,6 @@ int TimidityPPMIDIDevice::Open(MidiCallback callback, void *userdata) } } -#ifdef _WIN32 - CommandLine += "-o - -Ors"; - CommandLine += timidity_stereo ? 'S' : 'M'; - CommandLine += timidity_8bit ? '8' : '1'; - if (timidity_byteswap) - { - CommandLine += 'x'; - } - - LoopPos = CommandLine.Len() + 4; - - CommandLine += " -idl "; - CommandLine += DiskName.GetName(); -#endif return 0; } @@ -463,12 +454,12 @@ bool TimidityPPMIDIDevice::ValidateTimidity() bool TimidityPPMIDIDevice::LaunchTimidity () { -#ifdef _WIN32 - if (CommandLine.IsEmpty()) + if (ExeName.IsEmpty() || nullptr == DiskName) { return false; } +#ifdef _WIN32 DPrintf (DMSG_NOTIFY, "cmd: \x1cG%s\n", CommandLine.GetChars()); STARTUPINFO startup = { sizeof(startup), }; @@ -516,11 +507,6 @@ bool TimidityPPMIDIDevice::LaunchTimidity () } return false; #else - if (ExeName.IsEmpty()) - { - return false; - } - if (WavePipe[0] != -1 && WavePipe[1] == -1 && Stream != NULL) { // Timidity was previously launched, so the write end of the pipe @@ -579,7 +565,7 @@ bool TimidityPPMIDIDevice::LaunchTimidity () arglist.push_back("-"); arglist.push_back(outmodearg.c_str()); arglist.push_back(ifacearg.c_str()); - arglist.push_back(DiskName.GetName()); + arglist.push_back(DiskName); DPrintf(DMSG_NOTIFY, "Timidity EXE: \x1cG%s\n", exename); int i = 1; diff --git a/src/sound/oalsound.cpp b/src/sound/oalsound.cpp index b9b0a1b104..c2867804d3 100644 --- a/src/sound/oalsound.cpp +++ b/src/sound/oalsound.cpp @@ -57,7 +57,6 @@ #include "i_module.h" #include "i_music.h" #include "i_musicinterns.h" -#include "tempfiles.h" #include "cmdlib.h" FModule OpenALModule{"OpenAL"}; diff --git a/src/tempfiles.cpp b/src/tempfiles.cpp deleted file mode 100644 index 6ac782ccf0..0000000000 --- a/src/tempfiles.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* -** tempfiles.cpp -** Temporary name generator. Deletes the temporary file when deconstructed. -** -**--------------------------------------------------------------------------- -** Copyright 1998-2006 Randy Heit -** All rights reserved. -** -** Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions -** are met: -** -** 1. Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** 2. Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in the -** documentation and/or other materials provided with the distribution. -** 3. The name of the author may not be used to endorse or promote products -** derived from this software without specific prior written permission. -** -** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -**--------------------------------------------------------------------------- -** -*/ - -#include -#include -#include "tempfiles.h" - -FTempFileName::FTempFileName (const char *prefix) -{ -// Under Linux, ld will complain that tempnam is dangerous, and -// mkstemp should be used instead. However, there is no mkstemp -// under VC++, and even if there was, I still need to know the -// file name so that it can be used as input to Timidity. - - Name = tempnam (NULL, prefix); -} - -FTempFileName::~FTempFileName () -{ - if (Name != NULL) - { - remove (Name); - free (Name); - Name = NULL; - } -} diff --git a/src/tempfiles.h b/src/tempfiles.h deleted file mode 100644 index fe267d71a4..0000000000 --- a/src/tempfiles.h +++ /dev/null @@ -1,61 +0,0 @@ -/* -** tempfiles.h -** -**--------------------------------------------------------------------------- -** Copyright 1998-2006 Randy Heit -** All rights reserved. -** -** Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions -** are met: -** -** 1. Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** 2. Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in the -** documentation and/or other materials provided with the distribution. -** 3. The name of the author may not be used to endorse or promote products -** derived from this software without specific prior written permission. -** -** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -**--------------------------------------------------------------------------- -** -*/ - -#ifndef __TEMPFILES_H__ -#define __TEMPFILES_H__ - -#ifdef _MSC_VER -#pragma once -#endif - -#include - -// Returns a file name suitable for use as a temp file. -// If you create a file with this name (and presumably you -// will), it will be deleted automatically by this class's -// destructor. - -class FTempFileName -{ -public: - FTempFileName (const char *prefix=NULL); - ~FTempFileName (); - - operator const char * () { return Name; } - const char * GetName () const { return Name; } - -private: - char *Name; -}; - -#endif //__TEMPFILES_H__