2020-12-19 19:14:40 -05:00
|
|
|
|
using System;
|
2020-12-23 06:34:31 -05:00
|
|
|
|
using System.Diagnostics;
|
2020-12-19 19:14:40 -05:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
using auto_creamapi.Model;
|
2020-12-23 06:34:31 -05:00
|
|
|
|
using auto_creamapi.POCOs;
|
2020-12-22 09:20:40 -05:00
|
|
|
|
using auto_creamapi.Utils;
|
2020-12-19 19:14:40 -05:00
|
|
|
|
using Microsoft.Win32;
|
|
|
|
|
|
|
|
|
|
namespace auto_creamapi
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for MainWindow.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class MainWindow
|
|
|
|
|
{
|
|
|
|
|
private const string DefaultLangSelection = "english";
|
|
|
|
|
private static CacheModel _cacheModel;
|
|
|
|
|
private static CreamConfigModel _configModel;
|
|
|
|
|
private static CreamDllModel _dllModel;
|
|
|
|
|
|
|
|
|
|
public MainWindow()
|
|
|
|
|
{
|
|
|
|
|
_cacheModel = CacheModel.Instance;
|
|
|
|
|
_configModel = CreamConfigModel.Instance;
|
|
|
|
|
_dllModel = CreamDllModel.Instance;
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
_cacheModel.Languages.ForEach(x => Lang.Items.Add(x));
|
|
|
|
|
Lang.SelectedItem = DefaultLangSelection;
|
|
|
|
|
SteamDb.IsChecked = true;
|
2020-12-23 06:34:31 -05:00
|
|
|
|
Status.Text = "Ready.";
|
2020-12-19 19:14:40 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Looks up the AppID of the specified game.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void Search_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var app = _cacheModel.GetAppByName(Game.Text);
|
|
|
|
|
if (app != null)
|
|
|
|
|
{
|
2020-12-23 06:34:31 -05:00
|
|
|
|
Game.Text = app.Name;
|
2020-12-19 19:14:40 -05:00
|
|
|
|
AppId.Text = app.AppId.ToString();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var listOfAppsByName = _cacheModel.GetListOfAppsByName(Game.Text);
|
|
|
|
|
var searchWindow = new SearchResultWindow(listOfAppsByName);
|
|
|
|
|
searchWindow.Show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DllPath_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MyOpenFile();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Opens a file chooser to select the path to steam_api(64).dll.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void OpenFile_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
MyOpenFile();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MyOpenFile()
|
|
|
|
|
{
|
2020-12-23 06:34:31 -05:00
|
|
|
|
Status.Text = "Waiting for file...";
|
2020-12-19 19:14:40 -05:00
|
|
|
|
var dialog = new OpenFileDialog
|
|
|
|
|
{
|
|
|
|
|
Filter = "SteamAPI DLL|steam_api.dll;steam_api64.dll|" +
|
|
|
|
|
"All files (*.*)|*.*",
|
|
|
|
|
Multiselect = false,
|
|
|
|
|
Title = "Select SteamAPI DLL..."
|
|
|
|
|
};
|
|
|
|
|
if (dialog.ShowDialog() == true)
|
|
|
|
|
{
|
|
|
|
|
//Console.WriteLine(dialog.FileName);
|
|
|
|
|
var filePath = dialog.FileName;
|
|
|
|
|
DllPath.Text = filePath;
|
|
|
|
|
var dirPath = Path.GetDirectoryName(filePath);
|
|
|
|
|
if (dirPath != null)
|
|
|
|
|
{
|
|
|
|
|
_configModel.ReadFile(Path.Combine(dirPath, "cream_api.ini"));
|
|
|
|
|
ResetFormData();
|
|
|
|
|
_dllModel.TargetPath = dirPath;
|
|
|
|
|
_dllModel.CheckExistence();
|
|
|
|
|
CheckExistance();
|
2020-12-23 06:34:31 -05:00
|
|
|
|
Status.Text = "Ready.";
|
2020-12-19 19:14:40 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets a list of DLCs for the specified AppID.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private async void GetListOfDlc_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2020-12-23 06:34:31 -05:00
|
|
|
|
Status.Text = "Trying to get DLC...";
|
2020-12-19 19:14:40 -05:00
|
|
|
|
if (int.TryParse(AppId.Text, out var appId))
|
|
|
|
|
{
|
2020-12-22 09:20:40 -05:00
|
|
|
|
if (appId > 0)
|
|
|
|
|
{
|
2020-12-23 06:34:31 -05:00
|
|
|
|
var app = new SteamApp() {AppId = appId, Name = Game.Text};
|
|
|
|
|
var task = _cacheModel.GetListOfDlc(app,
|
2020-12-22 09:20:40 -05:00
|
|
|
|
SteamDb.IsChecked != null && (bool) SteamDb.IsChecked);
|
2020-12-23 06:34:31 -05:00
|
|
|
|
var listOfDlc = await task;
|
2020-12-22 09:20:40 -05:00
|
|
|
|
var result = "";
|
2020-12-23 06:34:31 -05:00
|
|
|
|
if (task.IsCompletedSuccessfully)
|
|
|
|
|
{
|
|
|
|
|
listOfDlc.Sort((app1, app2) => app1.AppId.CompareTo(app2.AppId));
|
|
|
|
|
listOfDlc.ForEach(x => result += $"{x.AppId}={x.Name}\n");
|
|
|
|
|
ListOfDlcs.Text = result;
|
|
|
|
|
Status.Text = $"Got DLC for AppID {appId}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Status.Text = $"Could not get DLC for AppID {appId}";
|
|
|
|
|
}
|
2020-12-22 09:20:40 -05:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-12-23 06:34:31 -05:00
|
|
|
|
Status.Text = $"Could not get DLC for AppID {appId}";
|
2020-12-22 09:20:40 -05:00
|
|
|
|
MyLogger.Log.Error($"GetListOfDlc: Invalid AppID {appId}");
|
|
|
|
|
}
|
2020-12-19 19:14:40 -05:00
|
|
|
|
}
|
2020-12-23 06:34:31 -05:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Status.Text = $"Could not get DLC: Invalid AppID {appId}";
|
|
|
|
|
MyLogger.Log.Error($"GetListOfDlc: Invalid AppID {appId}");
|
|
|
|
|
}
|
2020-12-19 19:14:40 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Saves form data to cream_api.ini.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void Save_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2020-12-23 06:34:31 -05:00
|
|
|
|
Status.Text = "Saving...";
|
2020-12-19 19:14:40 -05:00
|
|
|
|
_configModel.SetConfigData(
|
|
|
|
|
Convert.ToInt32(AppId.Text),
|
|
|
|
|
Lang.SelectedItem.ToString(),
|
|
|
|
|
UnlockAll.IsChecked != null && (bool) UnlockAll.IsChecked,
|
|
|
|
|
ExtraProtection.IsChecked != null && (bool) ExtraProtection.IsChecked,
|
|
|
|
|
ForceOffline.IsChecked != null && (bool) ForceOffline.IsChecked,
|
|
|
|
|
ListOfDlcs.Text
|
|
|
|
|
);
|
|
|
|
|
_configModel.SaveFile();
|
|
|
|
|
_dllModel.Save();
|
|
|
|
|
CheckExistance();
|
2020-12-23 06:34:31 -05:00
|
|
|
|
Status.Text = "Saving successful.";
|
2020-12-19 19:14:40 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Resets form data.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void Reset_Click(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2020-12-23 06:34:31 -05:00
|
|
|
|
Status.Text = "Resetting...";
|
2020-12-19 19:14:40 -05:00
|
|
|
|
ResetFormData();
|
|
|
|
|
CheckExistance();
|
2020-12-23 06:34:31 -05:00
|
|
|
|
Status.Text = "Resetting successful.";
|
2020-12-19 19:14:40 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets app name on id change
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="keyEventArgs"></param>
|
|
|
|
|
private void AppId_OnTextChanged(object sender, KeyEventArgs keyEventArgs)
|
|
|
|
|
{
|
|
|
|
|
SetNameById();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetNameById()
|
|
|
|
|
{
|
|
|
|
|
if (int.TryParse(AppId.Text, out var appId))
|
|
|
|
|
{
|
2020-12-22 09:20:40 -05:00
|
|
|
|
if (appId > 0)
|
|
|
|
|
{
|
|
|
|
|
var app = _cacheModel.GetAppById(appId);
|
|
|
|
|
if (app != null)
|
|
|
|
|
{
|
|
|
|
|
Game.Text = app.Name;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-12-23 06:34:31 -05:00
|
|
|
|
Game.Text = "";
|
|
|
|
|
AppId.Text = "";
|
2020-12-22 09:20:40 -05:00
|
|
|
|
MyLogger.Log.Error($"No app found for ID {appId}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2020-12-23 06:34:31 -05:00
|
|
|
|
Game.Text = "";
|
|
|
|
|
AppId.Text = "";
|
2020-12-22 09:20:40 -05:00
|
|
|
|
MyLogger.Log.Error($"SetNameById: Invalid AppID {appId}");
|
|
|
|
|
}
|
2020-12-19 19:14:40 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ResetFormData()
|
|
|
|
|
{
|
|
|
|
|
AppId.Text = _configModel.Config.AppId.ToString();
|
|
|
|
|
Lang.SelectedItem = _configModel.Config.Language;
|
|
|
|
|
UnlockAll.IsChecked = _configModel.Config.UnlockAll; // public bool UnlockAll;
|
|
|
|
|
ExtraProtection.IsChecked = _configModel.Config.ExtraProtection; // public bool ExtraProtection;
|
|
|
|
|
ForceOffline.IsChecked = _configModel.Config.ForceOffline; // public bool ForceOffline;
|
|
|
|
|
// public Dictionary<int, string> DlcList;
|
|
|
|
|
var dlcListString = "";
|
|
|
|
|
if (_configModel.Config.DlcList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var (id, name) in _configModel.Config.DlcList)
|
|
|
|
|
{
|
|
|
|
|
dlcListString += $"{id}={name},\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ListOfDlcs.Text = dlcListString;
|
|
|
|
|
SetNameById();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckExistance()
|
|
|
|
|
{
|
2020-12-23 06:34:31 -05:00
|
|
|
|
CreamApiApplied.IsChecked = _dllModel.CreamApiApplied();
|
|
|
|
|
ConfigExists.IsChecked = _configModel.ConfigExists();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Hyperlink_RequestNavigate(object sender, System.Windows.Navigation.RequestNavigateEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// for .NET Core you need to add UseShellExecute = true
|
|
|
|
|
// see https://docs.microsoft.com/dotnet/api/system.diagnostics.processstartinfo.useshellexecute#property-value
|
|
|
|
|
// UseShellExecute = true;
|
|
|
|
|
Status.Text = "Opening URL...";
|
|
|
|
|
if (int.TryParse(AppId.Text, out var appId))
|
|
|
|
|
{
|
|
|
|
|
if (appId > 0)
|
|
|
|
|
{
|
|
|
|
|
var searchTerm = appId;//$"{Game.Text.Replace(" ", "+")}+{appId}";
|
|
|
|
|
var destinationUrl =
|
|
|
|
|
"https://cs.rin.ru/forum/search.php?keywords=" +
|
|
|
|
|
searchTerm +
|
|
|
|
|
"&terms=any&fid[]=10&sf=firstpost&sr=topics&submit=Search";
|
|
|
|
|
var uri = new Uri(destinationUrl);
|
|
|
|
|
var process = new ProcessStartInfo(uri.AbsoluteUri)
|
|
|
|
|
{
|
|
|
|
|
UseShellExecute = true
|
|
|
|
|
};
|
|
|
|
|
Process.Start(process);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MyLogger.Log.Error($"OpenURL: Invalid AppID {appId}");
|
|
|
|
|
Status.Text = $"Could not open URL: Invalid AppID {appId}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
MyLogger.Log.Error($"OpenURL: Invalid AppID {appId}");
|
|
|
|
|
Status.Text = $"Could not open URL: Invalid AppID {appId}";
|
|
|
|
|
}
|
2020-12-19 19:14:40 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|