diff --git a/RecordSplitter.aps b/RecordSplitter.aps new file mode 100644 index 0000000..19d9301 Binary files /dev/null and b/RecordSplitter.aps differ diff --git a/RecordSplitter.cpp b/RecordSplitter.cpp new file mode 100644 index 0000000..0aefa59 --- /dev/null +++ b/RecordSplitter.cpp @@ -0,0 +1,196 @@ +/************************** +2014 adocilesloth@gmail.com +***************************/ +/************************************************* +Note: Will drop ~3 secs between recording switches +**************************************************/ +#include "RecordSplitter.h" +#include "timer.h" + +#include +#include + +using namespace std; + +ifstream settings; +HINSTANCE hInstance; + +HANDLE RecThread; +bool active; +long int loops; + +INT_PTR CALLBACK ConfigDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + int hours, mins, secs; + + wstring path = OBSGetPluginDataPath().Array(); + settings.open(path + L"\\RecordingSplitter.ini"); + settings >> active; + settings >> hours; + settings >> mins; + settings >> secs; + settings.close(); + + switch (message) + { + case WM_INITDIALOG: + { + SendMessage(GetDlgItem(hWnd, IDC_ENBL), BM_SETCHECK, active ? BST_CHECKED : BST_UNCHECKED, 0); + SetDlgItemInt(hWnd, IDC_EHRS, hours, NULL); + SendMessage(GetDlgItem(hWnd, IDC_SHRS), UDM_SETRANGE32, 0, 24); + SetDlgItemInt(hWnd, IDC_EMIN, mins, NULL); + SendMessage(GetDlgItem(hWnd, IDC_SMIN), UDM_SETRANGE32, 0, 60); + SetDlgItemInt(hWnd, IDC_ESEC, secs, NULL); + SendMessage(GetDlgItem(hWnd, IDC_SSEC), UDM_SETRANGE32, 0, 60); + if(active) + { + EnableWindow(GetDlgItem(hWnd, IDC_EHRS), true); + EnableWindow(GetDlgItem(hWnd, IDC_EMIN), true); + EnableWindow(GetDlgItem(hWnd, IDC_ESEC), true); + } + else + { + EnableWindow(GetDlgItem(hWnd, IDC_EHRS), false); + EnableWindow(GetDlgItem(hWnd, IDC_EMIN), false); + EnableWindow(GetDlgItem(hWnd, IDC_ESEC), false); + } + } + case WM_COMMAND: + switch (LOWORD(wParam)) + { + case IDOK: + { + active = SendMessage(GetDlgItem(hWnd, IDC_ENBL), BM_GETCHECK, 0, 0) == BST_CHECKED; + hours = GetDlgItemInt(hWnd, IDC_EHRS, NULL, NULL); + mins = GetDlgItemInt(hWnd, IDC_EMIN, NULL, NULL); + secs = GetDlgItemInt(hWnd, IDC_ESEC, NULL, NULL); + + if(hours == 0 && mins == 0 && secs < 10) //min splitting time is 30 secs + { + secs = 10; + } + + ofstream create(path + L"\\RecordingSplitter.ini"); + create << active << endl; + create << hours << endl; + create << mins << endl; + create << secs << endl; + create.close(); + + loops = ((hours * 60 * 60) + (mins * 60) + secs) * 10; + EndDialog(hWnd, LOWORD(wParam)); + break; + } + case IDCANCEL: + EndDialog(hWnd, LOWORD(wParam)); + break; + + case IDC_ENBL: + { + bool benbl = SendMessage(GetDlgItem(hWnd, IDC_ENBL), BM_GETCHECK, 0, 0) == BST_CHECKED; + if(benbl) + { + EnableWindow(GetDlgItem(hWnd, IDC_EHRS), true); + EnableWindow(GetDlgItem(hWnd, IDC_EMIN), true); + EnableWindow(GetDlgItem(hWnd, IDC_ESEC), true); + } + else + { + EnableWindow(GetDlgItem(hWnd, IDC_EHRS), false); + EnableWindow(GetDlgItem(hWnd, IDC_EMIN), false); + EnableWindow(GetDlgItem(hWnd, IDC_ESEC), false); + } + } + } + } + return 0; +} + +void ConfigPlugin(HWND hWnd) +{ + DialogBox(hInstance, MAKEINTRESOURCE(IDD_RECCFG), hWnd, ConfigDlgProc); +} + +bool LoadPlugin() +{ + wstring path = OBSGetPluginDataPath().Array(); + settings.open(path + L"\\RecordingSplitter.ini"); + + int hours, mins, secs; + + if (!settings.is_open()) + { + ofstream create(path + L"\\RecordingSplitter.ini"); + create << "1" << endl; + create << "0" << endl; //hours + create << "30" << endl; //mins + create << "0"; //secs + create.close(); //stop using settings file + + active = true; + hours = 0; + mins = 30; + secs = 0; + } + else + { + settings >> active; + settings >> hours; + settings >> mins; + settings >> secs; + settings.close(); + } + + loops = ((hours * 60 * 60) + (mins * 60) + secs) * 10; + + AppWarning(TEXT("Record Splitter Loaded")); + return true; +} + +void UnloadPlugin() +{ +} + +CTSTR GetPluginName() +{ + return TEXT("Recording Splitter"); +} + +CTSTR GetPluginDescription() +{ + return TEXT("Splits Recordings into smaller files\n\n NOTE: There will be around 5 seconds of lost footage between the split recordings"); +} + +void OnStartRecording() +{ + if(active) + { + WaitForSingleObject(RecThread, INFINITE); + long int* t = new long int(loops); + RecThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)StartTimer, t, 0, 0); + } + return; +} + +void OnStopRecording() +{ + if(active) + { + if(!OBSGetRecording()) + { + StopTimer(); + WaitForSingleObject(RecThread, INFINITE); + ResetTimer(); + return; + } + } + return; +} + +BOOL CALLBACK DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + if (fdwReason == DLL_PROCESS_ATTACH) + hInstance = hinstDLL; + + return TRUE; +} \ No newline at end of file diff --git a/RecordSplitter.h b/RecordSplitter.h new file mode 100644 index 0000000..e822c52 --- /dev/null +++ b/RecordSplitter.h @@ -0,0 +1,18 @@ +/************************** +2014 adocilesloth@gmail.com +***************************/ +#pragma once +#include "OBSApi.h" +#include "ending.h" +#include "resource1.h" + +//entry points +extern "C" __declspec(dllexport) void ConfigPlugin(HWND); + +extern "C" __declspec(dllexport) bool LoadPlugin(); +extern "C" __declspec(dllexport) void UnloadPlugin(); +extern "C" __declspec(dllexport) CTSTR GetPluginName(); +extern "C" __declspec(dllexport) CTSTR GetPluginDescription(); + +extern "C" __declspec(dllexport) void OnStartRecording(); +extern "C" __declspec(dllexport) void OnStopRecording(); \ No newline at end of file diff --git a/RecordSplitter.rc b/RecordSplitter.rc new file mode 100644 index 0000000..2079968 Binary files /dev/null and b/RecordSplitter.rc differ diff --git a/RecordSplitter.vcxproj b/RecordSplitter.vcxproj new file mode 100644 index 0000000..1bf2d20 --- /dev/null +++ b/RecordSplitter.vcxproj @@ -0,0 +1,207 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {BA99758B-8ABF-4D8C-BD4B-BEE9CAB31A22} + RecordSplitter + MFCDLLProj + + + + DynamicLibrary + true + Unicode + Dynamic + + + DynamicLibrary + true + Unicode + Dynamic + + + DynamicLibrary + false + true + Unicode + Dynamic + + + DynamicLibrary + false + true + Unicode + Dynamic + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;_USRDLL;%(PreprocessorDefinitions) + + + Windows + true + .\RecordSplitter.def + + + false + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Use + Level3 + Disabled + WIN32;_WINDOWS;_DEBUG;_USRDLL;%(PreprocessorDefinitions) + + + Windows + true + .\RecordSplitter.def + + + false + _DEBUG;%(PreprocessorDefinitions) + + + 0x0409 + _DEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + + + Level3 + NotUsing + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;_USRDLL;%(PreprocessorDefinitions) + ;../OBSApi;%(AdditionalLibraryDirectories) + + + Windows + true + true + true + + + ../OBSApi/Release;%(AdditionalLibraryDirectories) + OBSApi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + false + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + copy $(OutDir)$(ProjectName).dll ..\rundir\plugins + + + + + Level3 + NotUsing + MaxSpeed + true + true + WIN32;_WINDOWS;NDEBUG;_USRDLL;%(PreprocessorDefinitions) + ;../OBSApi;%(AdditionalLibraryDirectories) + + + Windows + true + true + true + + + ../OBSApi/x64/Release;%(AdditionalLibraryDirectories) + OBSApi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + false + NDEBUG;%(PreprocessorDefinitions) + + + 0x0409 + NDEBUG;%(PreprocessorDefinitions) + $(IntDir);%(AdditionalIncludeDirectories) + + + copy $(OutDir)$(ProjectName).dll ..\rundir\plugins + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/RecordSplitter.vcxproj.filters b/RecordSplitter.vcxproj.filters new file mode 100644 index 0000000..468948b --- /dev/null +++ b/RecordSplitter.vcxproj.filters @@ -0,0 +1,44 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Resource Files + + + \ No newline at end of file diff --git a/RecordSplitter.vcxproj.user b/RecordSplitter.vcxproj.user new file mode 100644 index 0000000..ace9a86 --- /dev/null +++ b/RecordSplitter.vcxproj.user @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/ending.h b/ending.h new file mode 100644 index 0000000..5e208e3 --- /dev/null +++ b/ending.h @@ -0,0 +1,42 @@ +/***************************** +2014 +*****************************/ +#ifndef ENDING_H +#define ENDING_H + +#include "OBSApi.h" + +class ending +{ + DWORD WaitResult; + HANDLE Mutex; + bool ended; +public: + ending() + { + ended = false; + Mutex = CreateMutex(NULL, false, NULL); + } + + void now() + { + WaitResult = WaitForSingleObject(Mutex, INFINITE); + ended = true; + ReleaseMutex(Mutex); + } + void nolonger() + { + WaitResult = WaitForSingleObject(Mutex, INFINITE); + ended = false; + ReleaseMutex(Mutex); + } + bool state() + { + WaitResult = WaitForSingleObject(Mutex, INFINITE); + bool b = ended; + ReleaseMutex(Mutex); + return b; + } +}; + +#endif //ENDING_H \ No newline at end of file diff --git a/resource1.h b/resource1.h new file mode 100644 index 0000000..854ba0c Binary files /dev/null and b/resource1.h differ diff --git a/timer.cpp b/timer.cpp new file mode 100644 index 0000000..22132c3 --- /dev/null +++ b/timer.cpp @@ -0,0 +1,41 @@ +/************************** +2014 adocilesloth@gmail.com +***************************/ +#include "timer.h" + +using namespace std; + +ending closed; + +DWORD WINAPI StartTimer(LPVOID t) +{ + long int loops = *static_cast(t); + delete t; + long int i = 1; + + while(!closed.state() && i < loops) + { + Sleep(100); + i++; + } + + if(!closed.state()) + { + OBSStartStopRecording(); + //Sleep(50); + OBSStartStopRecording(); + } + return 0; +} + +void StopTimer() +{ + closed.now(); + return; +} + +void ResetTimer() +{ + closed.nolonger(); + return; +} \ No newline at end of file diff --git a/timer.h b/timer.h new file mode 100644 index 0000000..9c77790 --- /dev/null +++ b/timer.h @@ -0,0 +1,9 @@ +/************************** +2014 adocilesloth@gmail.com +***************************/ + +#include "RecordSplitter.h" + +DWORD WINAPI StartTimer(LPVOID); +void StopTimer(); +void ResetTimer(); \ No newline at end of file