Skip to content

Commit

Permalink
Map migration prompt, new site API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowberryHN committed Jan 9, 2023
1 parent 300b590 commit 9d8bf15
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 12 deletions.
29 changes: 28 additions & 1 deletion CardboardLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,25 @@
<OutputType>WinExe</OutputType>
<RootNamespace>CardboardLauncher</RootNamespace>
<AssemblyName>CardboardLauncher</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -110,5 +125,17 @@
<EmbeddedResource Include="res\close_click.png" />
<EmbeddedResource Include="res\close.png" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.8">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.8 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
2 changes: 2 additions & 0 deletions MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 33 additions & 5 deletions MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ public partial class mainForm : Form

private Config config;

private string api_url = @"https://harpnetstudios.com/hnid/api/";

private string migratePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "My Games", "Project Crimson Alpha");
private string mapMigratePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "My Games", "Carmine Impact Alpha", "packages", "base");

private DialogResult DisplayMessage(string text, string origin = null, MessageBoxButtons buttons = MessageBoxButtons.OK, MessageBoxIcon icon = MessageBoxIcon.None)
{
Expand All @@ -44,7 +47,7 @@ private void ValidateSteam()

//Clipboard.SetText(BitConverter.ToString(ticket.Data).Replace("-", ""));

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"https://harpnetstudios.com/hnid/api/v1/game/auth/steam?ticket=" + BitConverter.ToString(ticket.Data).Replace("-", "") + "&id=" + LauncherInfo.gameId);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(api_url+@"steam/AuthSession?ticket=" + BitConverter.ToString(ticket.Data).Replace("-", "") + "&id=" + LauncherInfo.gameId);
request.Timeout = 15000; // hopefully will make the launcher more responsive when the servers are down
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string content = new StreamReader(response.GetResponseStream()).ReadToEnd();
Expand Down Expand Up @@ -133,7 +136,7 @@ private bool GrabInfo(string token)
if (token=="" || technicalIssues) return false;
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"https://harpnetstudios.com/hnid/api/v1/game/auth/login?id=" + LauncherInfo.gameId);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(api_url+@"v1/game/login?game=" + LauncherInfo.gameId);
request.Timeout = 15000; // hopefully will make the launcher more responsive when the servers are down
WebHeaderCollection whc = request.Headers;
whc.Add("X-Game-Token: "+token);
Expand Down Expand Up @@ -225,6 +228,9 @@ public mainForm()
if(config.homeDir == "") config.homeDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "My Games", "Carmine Impact Alpha");
if(config.homeDir == migratePath && Directory.Exists(migratePath)) PromptMigration();
else if(Directory.Exists(migratePath)) PromptMigration();

if (Directory.Exists(mapMigratePath)) PromptMapMigration();

homeDirBox.Text = config.homeDir;
qConnectServBox.Text = config.qConnectServ;

Expand Down Expand Up @@ -253,9 +259,25 @@ public void PromptMigration()
{
DisplayMessage(string.Format("Migration failed! Please report this in the Discord server.\n\nError details: {0}", e.Message), "Migration Wizard", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

}

public void PromptMapMigration()
{
var migrateMessage = DisplayMessage("We've detected you're upgrading from an older version. Would you like to migrate your custom map folder?", "Migration Wizard", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (migrateMessage == DialogResult.No) return;
try
{
string folder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "My Games", "Carmine Impact Alpha", "packages", "maps");
Directory.Move(mapMigratePath, folder);
SaveConfig();
DisplayMessage("Successfully migrated custom map folder!", "Migration Wizard", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception e)
{
DisplayMessage(string.Format("Migration failed! Please report this in the Discord server.\n\nError details: {0}", e.Message), "Migration Wizard", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

public void displayMessage(String message)
{
DisplayMessage(message, "Webpage");
Expand Down Expand Up @@ -331,7 +353,7 @@ private void playButton_Click(object sender, EventArgs e)
launchToken = "OFFLINE";
if(!technicalIssues)
{
DialogResult offlineMessage = DisplayMessage("Hey, you are about to start the game in OFFLINE mode!\n\nTo experience all that the game has to offer, including multiplayer, please log into your HNID account.\n\nAre you sure you want to continue?", "Offline Mode Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
DialogResult offlineMessage = DisplayMessage("Hey, you are about to start the game in OFFLINE mode!\n\nTo experience all that the game has to offer, including multiplayer, "+(isTokenSet() ? "please disable offline mode." : "please log into your HNID account.")+"\n\nAre you sure you want to launch in offline mode?", "Offline Mode Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (offlineMessage == DialogResult.No) return;
}
}
Expand All @@ -340,7 +362,7 @@ private void playButton_Click(object sender, EventArgs e)
ProcessStartInfo gameProcess = new ProcessStartInfo();
gameProcess.FileName = Path.Combine("bin" + (use64bit ? "64" : ""), "cardboard_msvc.exe");
gameProcess.Arguments = "-c" + launchToken + " -q\"" + config.homeDir + "\" -glog.txt" + (qConnectChkBox.Checked&&!playOfflineChkBox.Checked ? " -x\"connect "+config.qConnectServ+"\"" : "");


// Attempt to start process with correct arguments
try
Expand Down Expand Up @@ -372,6 +394,7 @@ private void mainForm_Load(object sender, EventArgs e)
private void webLauncher_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
webLauncher.Document.BackColor = this.BackColor;
this.webLauncher.ScrollBarsEnabled = false;
if(e.Url.ToString() == "about:blank") { return; }

string extForce = "#_force";
Expand Down Expand Up @@ -499,5 +522,10 @@ private void playOfflineChkBox_CheckedChanged(object sender, EventArgs e)
playButton.Enabled = false;
}
}

private void webLauncher_Loaded(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (!webLauncher.Visible && !technicalIssues) webLauncher.Visible = true;
}
}
}
6 changes: 3 additions & 3 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Cardboard Game Launcher")]
[assembly: AssemblyCopyright("Copyright © HarpNet Studios 2021")]
[assembly: AssemblyCopyright("Copyright © HarpNet Studios 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// 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.4.0.0")]
[assembly: AssemblyFileVersion("1.4.0.0")]
[assembly: AssemblyVersion("1.4.2.0")]
[assembly: AssemblyFileVersion("1.4.2.0")]
2 changes: 1 addition & 1 deletion Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1"/></startup>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup>
</configuration>

0 comments on commit 9d8bf15

Please sign in to comment.