Skip to content

Commit

Permalink
Cleaned up source code
Browse files Browse the repository at this point in the history
  • Loading branch information
Toyz committed Mar 28, 2017
1 parent d8e573a commit 84aaf06
Show file tree
Hide file tree
Showing 13 changed files with 284 additions and 127 deletions.
48 changes: 48 additions & 0 deletions BNetHelper/BNetHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;

namespace BNetHelper
{
public class BNetHelper
{
private WebClient bnetWebClient;

public BNetHelper()
{
bnetWebClient = new WebClient();
}

public (List<Dictionary<string, string>> games, List<string> headers) GetData(string gameCode, DownloadMode mode)
{
var url = $"http://us.patch.battle.net:1119/{gameCode}/{mode.ToString()}?nocache={DateTime.Now.Millisecond}";

List<string> fileData = bnetWebClient.DownloadString(url).Trim().Lines().ToList();

List<Dictionary<string, string>> CreatedFileData = new List<Dictionary<string, string>>();
string[] headers = fileData[0].Split('|');
fileData.RemoveAt(0);

for(int i = 0; i < headers.Length; i++)
{
headers[i] = headers[i].Split('!')[0].SplitCamelCase();
}

for (int i = 0; i < fileData.Count; i++)
{
Dictionary<string, string> item = new Dictionary<string, string>();

string[] line = fileData[i].Split('|');
for (int h = 0; h < headers.Length; h++)
{
item.Add(headers[h], line[h]);
}

CreatedFileData.Add(item);
}

return (games: CreatedFileData, headers: headers.ToList());
}
}
}
56 changes: 56 additions & 0 deletions BNetHelper/BNetHelper.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E00CB2D8-3E12-4EC5-B836-51CBBE2AD41F}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BNetHelper</RootNamespace>
<AssemblyName>BNetHelper</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.ValueTuple, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.ValueTuple.4.3.0\lib\netstandard1.0\System.ValueTuple.dll</HintPath>
</Reference>
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="BNetHelper.cs" />
<Compile Include="DownloadMode.cs" />
<Compile Include="Ext.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
8 changes: 8 additions & 0 deletions BNetHelper/DownloadMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace BNetHelper
{
public enum DownloadMode
{
versions,
bgdl
}
}
26 changes: 26 additions & 0 deletions BNetHelper/Ext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Text.RegularExpressions;

namespace BNetHelper
{
public static class Ext
{
public static string[] Lines(this string source)
{
return source.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
}

public static string SplitCamelCase(this string str)
{
return Regex.Replace(
Regex.Replace(
str,
@"(\P{Ll})(\P{Ll}\p{Ll})",
"$1 $2"
),
@"(\p{Ll})(\P{Ll})",
"$1 $2"
);
}
}
}
36 changes: 36 additions & 0 deletions BNetHelper/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("BNetHelper")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BNetHelper")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("e00cb2d8-3e12-4ec5-b836-51cbbe2ad41f")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
4 changes: 4 additions & 0 deletions BNetHelper/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="System.ValueTuple" version="4.3.0" targetFramework="net462" />
</packages>
6 changes: 6 additions & 0 deletions BNetVersionWatcher.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BNetVersionWatcher", "BNetV
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Version Viewer", "Version Viewer\Version Viewer.csproj", "{0F9A5708-9516-45BD-8C68-7EBECFEF2AD4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BNetHelper", "BNetHelper\BNetHelper.csproj", "{E00CB2D8-3E12-4EC5-B836-51CBBE2AD41F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -21,6 +23,10 @@ Global
{0F9A5708-9516-45BD-8C68-7EBECFEF2AD4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0F9A5708-9516-45BD-8C68-7EBECFEF2AD4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0F9A5708-9516-45BD-8C68-7EBECFEF2AD4}.Release|Any CPU.Build.0 = Release|Any CPU
{E00CB2D8-3E12-4EC5-B836-51CBBE2AD41F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E00CB2D8-3E12-4EC5-B836-51CBBE2AD41F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E00CB2D8-3E12-4EC5-B836-51CBBE2AD41F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E00CB2D8-3E12-4EC5-B836-51CBBE2AD41F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 3 additions & 3 deletions Version Viewer/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
</startup>
</configuration>
</configuration>
Loading

0 comments on commit 84aaf06

Please sign in to comment.