forked from master131/iFakeLocation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
2,680 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.vs/ | ||
iFakeLocation/bin/ | ||
iFakeLocation/obj/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
Oops, something went wrong.