Skip to content

Commit 08a6e2b

Browse files
committed
Latest release with fixing #79 #74
1 parent 6ade412 commit 08a6e2b

15 files changed

+66945
-118
lines changed

ScreenSaver/Caching.cs

+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using System.IO;
2+
using System;
3+
using System.ComponentModel;
4+
using System.Threading.Tasks;
5+
using System.Net;
6+
7+
public class Caching
8+
{
9+
public static string TempFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Aerial\\temp");
10+
public static string CacheFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Aerial");
11+
public static int DelayAmount = 1000 * 10; // 10 seconds.
12+
13+
/// <summary>
14+
/// Init cache. Clear partially downloaded files from temp folder.
15+
/// </summary>
16+
internal static void Setup()
17+
{
18+
// Ensure folders exist
19+
DirectoryInfo cacheDirectory = Directory.CreateDirectory(CacheFolder);
20+
DirectoryInfo tempDirectory = Directory.CreateDirectory(TempFolder);
21+
22+
foreach (var file in Directory.CreateDirectory(TempFolder).GetFiles())
23+
{
24+
file.Delete();
25+
}
26+
}
27+
28+
private static void OnDownloadFileComplete(object sender, AsyncCompletedEventArgs e)
29+
{
30+
var filename = e.UserState.ToString();
31+
var tempPath = Path.Combine(TempFolder, filename);
32+
if (e.Cancelled == false && e.Error == null)
33+
{
34+
Directory.Move(tempPath, Path.Combine(CacheFolder, filename));
35+
} else
36+
{
37+
// attempt to remove partially downloaded file
38+
File.Delete(filename);
39+
}
40+
}
41+
42+
internal static bool IsHit(string url)
43+
{
44+
string filename = Path.GetFileName(url);
45+
return File.Exists(Path.Combine(CacheFolder, filename));
46+
}
47+
48+
internal static bool IsCaching(string url)
49+
{
50+
string filename = Path.GetFileName(url);
51+
return File.Exists(Path.Combine(TempFolder, filename));
52+
}
53+
54+
internal static string Get(string url)
55+
{
56+
string filename = Path.GetFileName(url);
57+
return Path.Combine(CacheFolder, filename);
58+
}
59+
60+
internal static void StartDelayedCache(string url)
61+
{
62+
if (EnsureEnoughSpace())
63+
{
64+
Task.Delay(DelayAmount).ContinueWith(t =>
65+
{
66+
if (!IsCaching(url))
67+
{
68+
using (WebClient client = new WebClient())
69+
{
70+
client.DownloadFileCompleted += new AsyncCompletedEventHandler(OnDownloadFileComplete);
71+
string filename = Path.GetFileName(url);
72+
client.DownloadFileAsync(new Uri(url), Path.Combine(TempFolder, filename), filename);
73+
}
74+
}
75+
});
76+
}
77+
}
78+
79+
/// <summary>
80+
/// Ensures the drive with user folder has more than 1 gig space left.
81+
/// </summary>
82+
/// <returns></returns>
83+
private static bool EnsureEnoughSpace()
84+
{
85+
foreach (var drive in DriveInfo.GetDrives())
86+
{
87+
if (CacheFolder.StartsWith(drive.Name))
88+
return drive.TotalFreeSpace > 1000000000;
89+
}
90+
return true; // ?
91+
}
92+
}

ScreenSaver/Program.cs

+2-21
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static void Main(string[] args)
3939
Application.EnableVisualStyles();
4040
Application.SetCompatibleTextRenderingDefault(false);
4141

42-
ClearPartialDownloads();
42+
Caching.Setup();
4343

4444
if (args.Length > 0)
4545
{
@@ -128,7 +128,7 @@ static void ShowScreenSaver()
128128
var multiscreenDisabled = new RegSettings().MultiscreenDisabled;
129129
foreach (Screen screen in Screen.AllScreens)
130130
{
131-
ScreenSaverForm screensaver = new ScreenSaverForm(screen.Bounds);
131+
ScreenSaverForm screensaver = new ScreenSaverForm(screen.Bounds, i == 0);
132132

133133
// disable video on multi-displays (3+) except the first
134134
if (Screen.AllScreens.Length > 2 && screen != Screen.PrimaryScreen && multiscreenDisabled)
@@ -138,24 +138,5 @@ static void ShowScreenSaver()
138138
screensaver.Show();
139139
}
140140
}
141-
142-
/// <summary>
143-
/// Clear partially downloaded movs from temp folder
144-
/// </summary>
145-
static void ClearPartialDownloads()
146-
{
147-
string tempFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Temp\\Aerial");
148-
string[] filenames = Directory.GetFiles(tempFolder, "*.mov", SearchOption.TopDirectoryOnly);
149-
foreach (string filename in filenames)
150-
{
151-
try
152-
{
153-
File.Delete(Path.Combine(tempFolder, filename));
154-
}
155-
catch (IOException ioe)
156-
{
157-
}
158-
}
159-
}
160141
}
161142
}

ScreenSaver/Properties/Settings.Designer.cs

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ScreenSaver/RegSettings.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class RegSettings
88
public bool DifferentMoviesOnDual = false;
99
public bool UseTimeOfDay = true;
1010
public bool MultiscreenDisabled = true;
11-
public bool CacheVideos = false;
11+
public bool CacheVideos = true;
1212

1313
public RegSettings()
1414
{

ScreenSaver/ScreenSaver.csproj

+7-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<AppDesignerFolder>Properties</AppDesignerFolder>
1111
<RootNamespace>Aerial</RootNamespace>
1212
<AssemblyName>AerialScreenSaverV3</AssemblyName>
13-
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
13+
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
1414
<TargetFrameworkProfile>
1515
</TargetFrameworkProfile>
1616
<FileAlignment>512</FileAlignment>
@@ -79,6 +79,7 @@
7979
</ItemGroup>
8080
<ItemGroup>
8181
<Compile Include="AerialEntities.cs" />
82+
<Compile Include="Caching.cs" />
8283
<Compile Include="IgnoreMouseClickMessageFilter.cs" />
8384
<Compile Include="NativeMethods.cs" />
8485
<Compile Include="RegSettings.cs" />
@@ -130,7 +131,7 @@
130131
<VersionMinor>0</VersionMinor>
131132
<Lcid>0</Lcid>
132133
<WrapperTool>aximp</WrapperTool>
133-
<Isolated>False</Isolated>
134+
<Isolated>True</Isolated>
134135
<Private>False</Private>
135136
<EmbedInteropTypes>False</EmbedInteropTypes>
136137
</COMReference>
@@ -159,20 +160,19 @@
159160
<VersionMinor>0</VersionMinor>
160161
<Lcid>0</Lcid>
161162
<WrapperTool>tlbimp</WrapperTool>
162-
<Isolated>False</Isolated>
163+
<Isolated>True</Isolated>
163164
<EmbedInteropTypes>True</EmbedInteropTypes>
164165
<Private>False</Private>
165166
</COMReference>
166167
</ItemGroup>
167168
<ItemGroup>
168169
<Content Include="bridge.ico" />
170+
<None Include="bridge.png" />
169171
<EmbeddedResource Include="libs\AxInterop.WMPLib.dll" />
170172
<EmbeddedResource Include="libs\Interop.MediaPlayer.dll" />
171173
<EmbeddedResource Include="libs\Interop.WMPLib.dll" />
172174
</ItemGroup>
173-
<ItemGroup>
174-
<Folder Include="Movies\" />
175-
</ItemGroup>
175+
<ItemGroup />
176176
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
177177
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
178178
Other similar extension points exist, see Microsoft.Common.targets.
@@ -181,4 +181,4 @@
181181
<Target Name="AfterBuild">
182182
</Target>
183183
-->
184-
</Project>
184+
</Project>

ScreenSaver/ScreenSaver.csproj.user

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@
44
<StartArguments>/w</StartArguments>
55
</PropertyGroup>
66
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'All|AnyCPU'">
7-
<StartArguments>
8-
</StartArguments>
7+
<StartArguments>/w</StartArguments>
98
<EnableUnmanagedDebugging>true</EnableUnmanagedDebugging>
109
</PropertyGroup>
1110
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
12-
<StartArguments>/s</StartArguments>
11+
<StartArguments>/w</StartArguments>
1312
<EnableUnmanagedDebugging>true</EnableUnmanagedDebugging>
1413
</PropertyGroup>
1514
<PropertyGroup>

ScreenSaver/ScreenSaverForm.Designer.cs

+5-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)