Skip to content

Commit

Permalink
Cleared some trash +
Browse files Browse the repository at this point in the history
* Full-portable settings file. Without binding to computer name.
* HotFix for creating new cookie on first login.
  • Loading branch information
Maxx53 committed May 29, 2014
1 parent 83f7f45 commit f3e652d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 53 deletions.
11 changes: 8 additions & 3 deletions scr/SCMBot/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ private void Main_Load(object sender, EventArgs e)
settingsForm.intLangComboBox.DisplayMember = "NativeName";
settingsForm.intLangComboBox.ValueMember = "Name";

steam_srch.cookieCont = (CookieContainer)LoadBinary(cockPath);
//Hotfix
var cook = (CookieContainer)LoadBinary(cockPath);

if (cook == null)
cook = new CookieContainer();

steam_srch.cookieCont = cook;
steam_srch.scanID = 0;
filterTypeBox.SelectedIndex = 1;

Expand Down Expand Up @@ -745,15 +751,13 @@ public void Event_Message(object sender, object data, int searchId, flag myflag,

case flag.Inventory_Loaded:


SetInvFilter();

label4.Text = filteredInvList.Count.ToString();
button1.Enabled = true;

if (searchId == 0)
{

FillInventoryList();

SellButton.Enabled = true;
Expand All @@ -763,6 +767,7 @@ public void Event_Message(object sender, object data, int searchId, flag myflag,
}
else
{
InventoryList.Items.Clear();
button2.Enabled = false;
MessageBox.Show("Inventory section is empty!", Strings.Attention, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
Expand Down
56 changes: 6 additions & 50 deletions scr/SCMBot/PortableSettingsProvider.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using System.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System;
using System.Configuration;
using System.Windows.Forms;
using System.Collections.Specialized;
Expand All @@ -13,8 +10,6 @@ namespace SCMBot
public sealed class PortableSettingsProvider : SettingsProvider, IApplicationSettingsProvider
{
private const string _rootNodeName = "settings";
private const string _localSettingsNodeName = "localSettings";
private const string _globalSettingsNodeName = "globalSettings";
private const string _className = "PortableSettingsProvider";
private XmlDocument _xmlDocument;

Expand All @@ -26,28 +21,6 @@ private string _filePath
}
}

private XmlNode _localSettingsNode
{
get
{
XmlNode settingsNode = GetSettingsNode(_localSettingsNodeName);
XmlNode machineNode = settingsNode.SelectSingleNode(Environment.MachineName.ToLowerInvariant());

if (machineNode == null)
{
machineNode = _rootDocument.CreateElement(Environment.MachineName.ToLowerInvariant());
settingsNode.AppendChild(machineNode);
}

return machineNode;
}
}

private XmlNode _globalSettingsNode
{
get { return GetSettingsNode(_globalSettingsNodeName); }
}

private XmlNode _rootNode
{
get { return _rootDocument.SelectSingleNode(_rootNodeName); }
Expand Down Expand Up @@ -132,15 +105,12 @@ public override SettingsPropertyValueCollection GetPropertyValues(SettingsContex

private void SetValue(SettingsPropertyValue propertyValue)
{
XmlNode targetNode = IsGlobal(propertyValue.Property)
? _globalSettingsNode
: _localSettingsNode;

XmlNode settingNode = targetNode.SelectSingleNode(string.Format("setting[@name='{0}']", propertyValue.Name));
XmlNode settingNode = _rootNode.SelectSingleNode(string.Format("setting[@name='{0}']", propertyValue.Name));

if (settingNode != null)
{
//Fix for binary serialiezed setting
//Fix for binary serialized setting
if (propertyValue.SerializedValue is byte[])
settingNode.InnerText = Convert.ToBase64String((byte[])propertyValue.SerializedValue);
else
Expand All @@ -157,32 +127,20 @@ private void SetValue(SettingsPropertyValue propertyValue)

settingNode.InnerText = propertyValue.SerializedValue.ToString();

targetNode.AppendChild(settingNode);
_rootNode.AppendChild(settingNode);
}
}

private string GetValue(SettingsProperty property)
{
XmlNode targetNode = IsGlobal(property) ? _globalSettingsNode : _localSettingsNode;
XmlNode settingNode = targetNode.SelectSingleNode(string.Format("setting[@name='{0}']", property.Name));
XmlNode settingNode = _rootNode.SelectSingleNode(string.Format("setting[@name='{0}']", property.Name));

if (settingNode == null)
return property.DefaultValue != null ? property.DefaultValue.ToString() : string.Empty;

return settingNode.InnerText;
}

private bool IsGlobal(SettingsProperty property)
{
foreach (DictionaryEntry attribute in property.Attributes)
{
if ((Attribute)attribute.Value is SettingsManageabilityAttribute)
return true;
}

return false;
}

private XmlNode GetSettingsNode(string name)
{
XmlNode settingsNode = _rootNode.SelectSingleNode(name);
Expand All @@ -207,9 +165,6 @@ public XmlDocument GetBlankXmlDocument()

public void Reset(SettingsContext context)
{
_localSettingsNode.RemoveAll();
_globalSettingsNode.RemoveAll();

_xmlDocument.Save(_filePath);
}

Expand All @@ -221,6 +176,7 @@ public SettingsPropertyValue GetPreviousVersion(SettingsContext context, Setting

public void Upgrade(SettingsContext context, SettingsPropertyCollection properties)
{
// do nothing
}
}
}

0 comments on commit f3e652d

Please sign in to comment.