Skip to content
This repository has been archived by the owner on Jun 22, 2021. It is now read-only.

Commit

Permalink
Added new Launch Overlay to menu
Browse files Browse the repository at this point in the history
Stopped multiple instances of the radio status display being loaded
  • Loading branch information
Ciaran Fisher committed Oct 29, 2015
1 parent 933ae47 commit 8b06f82
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 1 deletion.
34 changes: 33 additions & 1 deletion Plugin/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "RadioUpdate.h"
#include "RadioUpdateCommand.h"
#include "json/json.h"
#include "RegHelper.h"

#include <tchar.h>
#include <winsock2.h>
Expand Down Expand Up @@ -814,6 +815,33 @@ namespace SimpleRadio
this->updateThread = thread(&Plugin::UpdateCheckThread, this);
}

void Plugin::launchOverlay()
{
//find registry entry

string path = RegHelper().readSRPath();

if (path != "")
{
path = path + "\\DCS-SimpleRadio.exe";

std::wstring exePath(path.begin(), path.end());
LPCWSTR exePathWSTR = exePath.c_str();

ShellExecute(NULL, L"open", exePathWSTR,
NULL, NULL, SW_SHOWNORMAL);
}
else
{
MessageBox(
NULL,
(LPCWSTR)L"Couldn't Find DCS-SimpleRadio.exe! Reinstall or Launch Manually",
(LPCWSTR)L"Error",
MB_ICONWARNING
);
}
}

int Plugin::recvfromTimeOutUDP(SOCKET socket, long sec, long usec)
{
// Setup timeval variable
Expand Down Expand Up @@ -1508,8 +1536,9 @@ void ts3plugin_initMenus(struct PluginMenuItem*** menuItems, char** menuIcon) {
*/


BEGIN_CREATE_MENUS(1)
BEGIN_CREATE_MENUS(2)
CREATE_MENU_ITEM(PLUGIN_MENU_TYPE_GLOBAL, 1, "Check For Update", "");
CREATE_MENU_ITEM(PLUGIN_MENU_TYPE_GLOBAL, 2, "Show Radio Status", "");
END_CREATE_MENUS;


Expand All @@ -1524,6 +1553,9 @@ void ts3plugin_onMenuItemEvent(uint64 serverConnectionHandlerID, enum PluginMenu
case 1:
plugin.checkForUpdate();
break;
case 2:
plugin.launchOverlay();
break;
default:
break;
}
Expand Down
2 changes: 2 additions & 0 deletions Plugin/Plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ namespace SimpleRadio

void checkForUpdate();

void launchOverlay();

private:
char* pluginId;

Expand Down
2 changes: 2 additions & 0 deletions Plugin/Plugin.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@
<ClInclude Include="RadioInformation.h" />
<ClInclude Include="RadioUpdate.h" />
<ClInclude Include="RadioUpdateCommand.h" />
<ClInclude Include="RegHelper.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="ts3_functions.h" />
<ClInclude Include="UDPDiscovery.h" />
Expand All @@ -356,6 +357,7 @@
<ClCompile Include="Plugin.cpp" />
<ClCompile Include="RadioUpdate.cpp" />
<ClCompile Include="RadioUpdateCommand.cpp" />
<ClCompile Include="RegHelper.cpp" />
<ClCompile Include="UDPDiscovery.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions Plugin/Plugin.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
<ClInclude Include="UDPDiscovery.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RegHelper.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="Plugin.cpp">
Expand All @@ -83,6 +86,9 @@
<ClCompile Include="UDPDiscovery.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="RegHelper.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="Plugin.rc">
Expand Down
51 changes: 51 additions & 0 deletions Plugin/RegHelper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include "RegHelper.h"



RegHelper::RegHelper()
{
}


RegHelper::~RegHelper()
{
}

std::string RegHelper::readSRPath()
{


HKEY hKey = 0;
DWORD bufferSize = 512;
LPVOID regBuffer = new char[bufferSize];
DWORD dwType = 0;
if (RegOpenKey(HKEY_CURRENT_USER, L"SOFTWARE\\DCS-SimpleRadio", &hKey) == ERROR_SUCCESS)
{
dwType = REG_SZ;
if (RegQueryValueEx(hKey, L"SRPath", 0, &dwType, (BYTE*)regBuffer, &bufferSize) == ERROR_SUCCESS)
{

//its a 2 Byte CHAR!
WCHAR *locationStr = reinterpret_cast<WCHAR *>(regBuffer);
locationStr[bufferSize] = 0; //add terminator

//convert to widestring
std::wstring ws(locationStr);
//convert to normal string
std::string str(ws.begin(), ws.end());


RegCloseKey(hKey);

delete[] regBuffer;
return str;
}

RegCloseKey(hKey);
}

delete[] regBuffer;

return "";

}
18 changes: 18 additions & 0 deletions Plugin/RegHelper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <iostream>
#include <string>
#include <Windows.h>



class RegHelper
{
public:
RegHelper();
~RegHelper();

std::string readSRPath();

};

24 changes: 24 additions & 0 deletions RadioGui/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Sockets;
Expand Down Expand Up @@ -48,6 +49,11 @@ public MainWindow()

InitializeComponent();

if(Is_SimpleRadio_running())
{
Close();
}

//allows click and drag anywhere on the window
this.containerPanel.MouseLeftButtonDown += WrapPanel_MouseLeftButtonDown;

Expand All @@ -64,6 +70,24 @@ public MainWindow()

}

/// <summary>
/// Only allow one instance of SimpleRadio
/// </summary>
/// <returns></returns>
private bool Is_SimpleRadio_running()
{
int i = 0;
foreach (Process clsProcess in Process.GetProcesses())
{
if (clsProcess.ProcessName.ToLower().Equals("dcs-simpleradio"))
{
i++;
}
}

return i > 1;
}

private void SetupRadioStatus()
{
//setup UDP
Expand Down

0 comments on commit 8b06f82

Please sign in to comment.