Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
master131 committed Apr 2, 2019
1 parent cf8b20e commit 7e70354
Show file tree
Hide file tree
Showing 32 changed files with 2,680 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vs/
iFakeLocation/bin/
iFakeLocation/obj/
25 changes: 25 additions & 0 deletions iFakeLocation.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.168
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "iFakeLocation", "iFakeLocation\iFakeLocation.csproj", "{139BC197-DD38-4377-9967-B0DC2CCC730F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{139BC197-DD38-4377-9967-B0DC2CCC730F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{139BC197-DD38-4377-9967-B0DC2CCC730F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{139BC197-DD38-4377-9967-B0DC2CCC730F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{139BC197-DD38-4377-9967-B0DC2CCC730F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {986B8B4A-402D-41E9-B2AE-386E3BCAE174}
EndGlobalSection
EndGlobal
69 changes: 69 additions & 0 deletions iFakeLocation/DeveloperImageHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Linq;

namespace iFakeLocation
{
static class DeveloperImageHelper
{
private class WebClientEx : WebClient
{
protected override WebRequest GetWebRequest(Uri address)
{
HttpWebRequest request = base.GetWebRequest(address) as HttpWebRequest;
if (request != null) request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;
return request;
}
}

private static readonly WebClient WebClient = new WebClientEx();
private static readonly Dictionary<string, string> VersionToImageUrl = new Dictionary<string, string>();

private const string ImagePath = "DeveloperImages";

public static bool HasImageForDevice(DeviceInformation device)
{
string[] p;
return HasImageForDevice(device, out p);
}

public static string GetSoftwareVersion(DeviceInformation device)
{
var ver = ((string)device.Properties["ProductVersion"]).Split('.');
return ver[0] + "." + ver[1];
}

public static bool HasImageForDevice(DeviceInformation device, out string[] paths)
{
var verStr = GetSoftwareVersion(device);
var a = Path.Combine(ImagePath, verStr, "DeveloperDiskImage.dmg");
var b = a + ".signature";
paths = new[] { a, b };
return File.Exists(a) && File.Exists(b);
}

public static Tuple<string, string>[] GetLinksForDevice(DeviceInformation device)
{
var verStr = GetSoftwareVersion(device);

// Populate URLs for developer images from Github
if (VersionToImageUrl.Count == 0)
{
WebClient.Headers["Accept"] = "application/json";
WebClient.Headers["X-Requested-With"] = "XMLHttpRequest";
var response = WebClient.DownloadString("https://github.com/xushuduo/Xcode-iOS-Developer-Disk-Image/tree-list/6718c0ced4dadf28ecc8411fddce32f4f779db9f");
var paths = response.Split('"').Where(s => s.EndsWith(".dmg", StringComparison.InvariantCultureIgnoreCase)).ToArray();
foreach (var path in paths)
VersionToImageUrl.Add(path.Split('/')[1].Split(' ')[0], "https://github.com/xushuduo/Xcode-iOS-Developer-Disk-Image/raw/master/" + path);
}

string ss;
return VersionToImageUrl.TryGetValue(verStr, out ss) ? new[] {
new Tuple<string, string>(ss, Path.Combine(ImagePath, verStr, "DeveloperDiskImage.dmg")),
new Tuple<string, string>(ss + ".signature", Path.Combine(ImagePath, verStr, "DeveloperDiskImage.dmg.signature"))
} : null;
}
}
}
Loading

0 comments on commit 7e70354

Please sign in to comment.