Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions AMDOpenCLDeviceDetection/AMDOpenCLDeviceDetection.vcxproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
Expand All @@ -22,31 +22,32 @@
<ProjectGuid>{F4D88D6A-2321-4431-AFD1-8B6A1760358B}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>AMDOpenCLDeviceDetection</RootNamespace>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down
612 changes: 408 additions & 204 deletions NiceHashMiner/Devices/ComputeDeviceManager.cs

Large diffs are not rendered by default.

164 changes: 117 additions & 47 deletions NiceHashMiner/Forms/Components/DevicesListViewEnableControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,31 @@
using NiceHashMiner.Devices;
using NiceHashMiner.Configs;
using NiceHashMiner.Interfaces;
using NiceHashMiner.Utils;

namespace NiceHashMiner.Forms.Components {
public partial class DevicesListViewEnableControl : UserControl {
namespace NiceHashMiner.Forms.Components
{
public partial class DevicesListViewEnableControl : UserControl
{

private const int ENABLED = 0;
private const int DEVICE = 1;

private class DefaultDevicesColorSeter : IListItemCheckColorSetter {
private class DefaultDevicesColorSeter : IListItemCheckColorSetter
{
private static Color ENABLED_COLOR = Color.White;
private static Color DISABLED_COLOR = Color.DarkGray;
public void LviSetColor(ListViewItem lvi) {
public void LviSetColor(ListViewItem lvi)
{
var cdvo = lvi.Tag as ComputeDevice;
if (cdvo != null) {
if(cdvo.Enabled) {
if (cdvo != null)
{
if (cdvo.Enabled)
{
lvi.BackColor = ENABLED_COLOR;
} else {
}
else
{
lvi.BackColor = DISABLED_COLOR;
}
}
Expand All @@ -39,26 +48,36 @@ public void LviSetColor(ListViewItem lvi) {
// disable checkboxes when in benchmark mode
private bool _isInBenchmark = false;
// helper for benchmarking logic
public bool IsInBenchmark {
public bool IsInBenchmark
{
get { return _isInBenchmark; }
set {
if (value) {
set
{
if (value)
{
_isInBenchmark = value;
listViewDevices.CheckBoxes = false;
} else {
}
else
{
_isInBenchmark = value;
listViewDevices.CheckBoxes = true;
}
}
}
private bool _isMining = false;
public bool IsMining {
public bool IsMining
{
get { return _isMining; }
set {
if (value) {
set
{
if (value)
{
_isMining = value;
listViewDevices.CheckBoxes = false;
} else {
}
else
{
_isMining = value;
listViewDevices.CheckBoxes = true;
}
Expand All @@ -68,15 +87,17 @@ public bool IsMining {
public bool IsBenchmarkForm = false;
public bool IsSettingsCopyEnabled = false;

public string FirstColumnText {
public string FirstColumnText
{
get { return listViewDevices.Columns[ENABLED].Text; }
set { if (value != null) listViewDevices.Columns[ENABLED].Text = value; }
}


public bool SaveToGeneralConfig { get; set; }

public DevicesListViewEnableControl() {
public DevicesListViewEnableControl()
{
InitializeComponent();

SaveToGeneralConfig = false;
Expand All @@ -87,34 +108,43 @@ public DevicesListViewEnableControl() {
BenchmarkCalculation = null;
}

public void SetIListItemCheckColorSetter(IListItemCheckColorSetter listItemCheckColorSetter) {
public void SetIListItemCheckColorSetter(IListItemCheckColorSetter listItemCheckColorSetter)
{
_listItemCheckColorSetter = listItemCheckColorSetter;
}

public void SetAlgorithmsListView(AlgorithmsListView algorithmsListView) {
public void SetAlgorithmsListView(AlgorithmsListView algorithmsListView)
{
_algorithmsListView = algorithmsListView;
}

public void ResetListItemColors() {
foreach (ListViewItem lvi in listViewDevices.Items) {
if (_listItemCheckColorSetter != null) {
public void ResetListItemColors()
{
foreach (ListViewItem lvi in listViewDevices.Items)
{
if (_listItemCheckColorSetter != null)
{
_listItemCheckColorSetter.LviSetColor(lvi);
}
}
}

public void SetComputeDevices(List<ComputeDevice> computeDevices) {
public void SetComputeDevices(List<ComputeDevice> computeDevices)
{
// to not run callbacks when setting new
bool tmp_SaveToGeneralConfig = SaveToGeneralConfig;
SaveToGeneralConfig = false;
listViewDevices.BeginUpdate();
listViewDevices.Items.Clear();
// set devices
foreach (var computeDevice in computeDevices) {
foreach (var computeDevice in computeDevices)
{
ListViewItem lvi = new ListViewItem();
//lvi.SubItems.Add(computeDevice.Name);
lvi.Checked = computeDevice.Enabled;
lvi.Text = computeDevice.GetFullName();

lvi.Text = SettingsUtil.Translate(computeDevice.UUID, computeDevice.GetFullName());

lvi.Tag = computeDevice;
listViewDevices.Items.Add(lvi);
_listItemCheckColorSetter.LviSetColor(lvi);
Expand All @@ -125,20 +155,24 @@ public void SetComputeDevices(List<ComputeDevice> computeDevices) {
SaveToGeneralConfig = tmp_SaveToGeneralConfig;
}

public void ResetComputeDevices(List<ComputeDevice> computeDevices) {
public void ResetComputeDevices(List<ComputeDevice> computeDevices)
{
SetComputeDevices(computeDevices);
}

public void InitLocale() {
public void InitLocale()
{
listViewDevices.Columns[ENABLED].Text = International.GetText("ListView_Device"); //International.GetText("ListView_Enabled");
//listViewDevices.Columns[DEVICE].Text = International.GetText("ListView_Device");
}

private void listViewDevicesItemChecked(object sender, ItemCheckedEventArgs e) {
private void listViewDevicesItemChecked(object sender, ItemCheckedEventArgs e)
{
var CDevice = e.Item.Tag as ComputeDevice;
CDevice.Enabled = e.Item.Checked;

if (SaveToGeneralConfig) {
if (SaveToGeneralConfig)
{
ConfigManager.GeneralConfigFileCommit();
}
var lvi = e.Item as ListViewItem;
Expand All @@ -147,24 +181,51 @@ private void listViewDevicesItemChecked(object sender, ItemCheckedEventArgs e) {
if (BenchmarkCalculation != null) BenchmarkCalculation.CalcBenchmarkDevicesAlgorithmQueue();
}

public void SetDeviceSelectionChangedCallback(ListViewItemSelectionChangedEventHandler callback) {
public void SetDeviceSelectionChangedCallback(ListViewItemSelectionChangedEventHandler callback)
{
listViewDevices.ItemSelectionChanged += callback;
}

private void listViewDevices_MouseClick(object sender, MouseEventArgs e) {
private void listViewDevices_MouseClick(object sender, MouseEventArgs e)
{
if (IsInBenchmark) return;
if (IsMining) return;
if (e.Button == MouseButtons.Right) {
if (listViewDevices.FocusedItem.Bounds.Contains(e.Location) == true) {
if (IsMining) return;
if (e.Button == MouseButtons.Right)
{
if (listViewDevices.FocusedItem.Bounds.Contains(e.Location) == true)
{
contextMenuStrip1.Items.Clear();
if (IsSettingsCopyEnabled) {

var tsi = new ToolStripMenuItem("Rename", null, (o, args) =>
{
var d = listViewDevices.FocusedItem;

var renameForm = new Form_DeviceRename();
renameForm.SetCurrentName(d.Text);

if (renameForm.ShowDialog() == DialogResult.OK)
{
d.Text = renameForm.NewName;
SettingsUtil.SetNameForDevice(d.Text, (d.Tag as ComputeDevice).UUID);
SettingsUtil.SaveSettings();
}
});

contextMenuStrip1.Items.Add(tsi);

if (IsSettingsCopyEnabled)
{
var CDevice = listViewDevices.FocusedItem.Tag as ComputeDevice;

var sameDevTypes = ComputeDeviceManager.Avaliable.GetSameDevicesTypeAsDeviceWithUUID(CDevice.UUID);
if (sameDevTypes.Count > 0) {
if (sameDevTypes.Count > 0)
{
var copyBenchItem = new ToolStripMenuItem();
//copyBenchItem.DropDownItems
foreach (var cDev in sameDevTypes) {
if (cDev.Enabled) {
foreach (var cDev in sameDevTypes)
{
if (cDev.Enabled)
{
var copyBenchDropDownItem = new ToolStripMenuItem();
copyBenchDropDownItem.Text = cDev.Name;
copyBenchDropDownItem.Checked = cDev.UUID == CDevice.BenchmarkCopyUUID;
Expand All @@ -177,17 +238,21 @@ private void listViewDevices_MouseClick(object sender, MouseEventArgs e) {
contextMenuStrip1.Items.Add(copyBenchItem);
}
}

contextMenuStrip1.Show(Cursor.Position);
}
}
}
}

private void toolStripMenuItemCopySettings_Click(object sender, EventArgs e) {
private void toolStripMenuItemCopySettings_Click(object sender, EventArgs e)
{
var CDevice = listViewDevices.FocusedItem.Tag as ComputeDevice;
ToolStripMenuItem item = sender as ToolStripMenuItem;
if(item != null) {
if (item != null)
{
var uuid = item.Tag as string;
if (uuid != null) {
if (uuid != null)
{
var copyBenchCDev = ComputeDeviceManager.Avaliable.GetDeviceWithUUID(uuid);
CDevice.BenchmarkCopyUUID = uuid;

Expand All @@ -196,7 +261,8 @@ private void toolStripMenuItemCopySettings_Click(object sender, EventArgs e) {
International.GetText("DeviceListView_ContextMenu_CopySettings_Confirm_Dialog_Msg"), copyBenchCDev.GetFullName(), CDevice.GetFullName()),
International.GetText("DeviceListView_ContextMenu_CopySettings_Confirm_Dialog_Title"),
MessageBoxButtons.YesNo);
if(result == DialogResult.Yes) {
if (result == DialogResult.Yes)
{
// just copy
CDevice.CopyBenchmarkSettingsFrom(copyBenchCDev);
if (_algorithmsListView != null) _algorithmsListView.RepaintStatus(CDevice.Enabled, CDevice.UUID);
Expand All @@ -205,15 +271,19 @@ private void toolStripMenuItemCopySettings_Click(object sender, EventArgs e) {
}
}

private void DevicesListViewEnableControl_Resize(object sender, EventArgs e) {
private void DevicesListViewEnableControl_Resize(object sender, EventArgs e)
{
// only one
foreach (ColumnHeader ch in listViewDevices.Columns) {
foreach (ColumnHeader ch in listViewDevices.Columns)
{
ch.Width = this.Width - 10;
}
}

public void SetFirstSelected() {
if (listViewDevices.Items.Count > 0) {
public void SetFirstSelected()
{
if (listViewDevices.Items.Count > 0)
{
this.listViewDevices.Items[0].Selected = true;
this.listViewDevices.Select();
}
Expand Down
Loading