Skip to content

Commit

Permalink
スタートアップにEpgTimerSrvのショートカットを作成できるようにする
Browse files Browse the repository at this point in the history
  • Loading branch information
xtne6f committed Jan 10, 2016
1 parent 58da7d1 commit 6aa2b3e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
5 changes: 3 additions & 2 deletions EpgTimer/EpgTimer/Setting/SetBasicView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
<Button Content="開く" Height="23" Margin="485,221,0,0" Name="button_rec_open" VerticalAlignment="Top" HorizontalAlignment="Left" Width="44" Click="button_rec_open_Click" />
<Button Content="追加" Height="23" Margin="535,221,0,0" Name="button_rec_add" VerticalAlignment="Top" Click="button_rec_add_Click" HorizontalAlignment="Left" Width="44" />
<Label Content="※ 録画中やEPG取得中に設定を変更すると正常動作しなくなる可能性があります。" Height="28" HorizontalAlignment="Left" Margin="12,278,0,0" Name="label4" VerticalAlignment="Top" Foreground="Red" />
<Button Content="スタートアップにショートカットを作成する" Height="23" HorizontalAlignment="Left" Margin="12,333,0,0" Name="button_shortCut" VerticalAlignment="Top" Width="265" Click="button_shortCut_Click" />
<Label Content="※ 削除時は手動で行ってください" Height="28" HorizontalAlignment="Left" Margin="12,360,0,0" Name="label5" VerticalAlignment="Top" />
<Label Content="スタートアップにショートカットを作成する" Height="28" HorizontalAlignment="Left" Margin="12,331,0,0" Name="label5" VerticalAlignment="Top" />
<Button Content="EpgTimer.exe" Height="23" HorizontalAlignment="Left" Margin="273,333,0,0" Name="button_shortCut" VerticalAlignment="Top" Width="140" Click="button_shortCut_Click" />
<Button Content="EpgTimerSrv.exe" Height="23" HorizontalAlignment="Left" Margin="419,333,0,0" Name="button_shortCutSrv" VerticalAlignment="Top" Width="160" Click="button_shortCutSrv_Click" />
</Grid>
</TabItem>
<TabItem Header="チューナー" Name="tabItem2">
Expand Down
42 changes: 36 additions & 6 deletions EpgTimer/EpgTimer/Setting/SetBasicView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public SetBasicView()
textBox_recFolder.IsEnabled = false;
button_rec_open.IsEnabled = false;
button_rec_add.IsEnabled = false;
button_shortCutSrv.IsEnabled = false;
}

try
Expand All @@ -69,6 +70,10 @@ public SetBasicView()
}
}
}
button_shortCut.Content = (string)button_shortCut.Content + (File.Exists(
System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "EpgTime.lnk")) ? "を解除" : "");
button_shortCutSrv.Content = (string)button_shortCutSrv.Content + (File.Exists(
System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "EpgTimerSrv.lnk")) ? "を解除" : "");

string[] files = Directory.GetFiles(SettingPath.SettingFolderPath, "*.ChSet4.txt");
SortedList<Int32, TunerInfo> tunerInfo = new SortedList<Int32, TunerInfo>();
Expand Down Expand Up @@ -501,13 +506,37 @@ private void button_shortCut_Click(object sender, RoutedEventArgs e)
{
try
{
Assembly myAssembly = Assembly.GetEntryAssembly();
string targetPath = myAssembly.Location;
string shortcutPath = System.IO.Path.Combine(
Environment.GetFolderPath(System.Environment.SpecialFolder.Startup),
@"EpgTime.lnk");
string shortcutPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "EpgTime.lnk");
if (File.Exists(shortcutPath))
{
File.Delete(shortcutPath);
}
else
{
CreateShortCut(shortcutPath, Assembly.GetEntryAssembly().Location, "");
}
button_shortCut.Content = ((string)button_shortCut.Content).Replace("を解除", "") + (File.Exists(shortcutPath) ? "を解除" : "");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
}
}

CreateShortCut(shortcutPath, targetPath, "");
private void button_shortCutSrv_Click(object sender, RoutedEventArgs e)
{
try
{
string shortcutPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), "EpgTimerSrv.lnk");
if (File.Exists(shortcutPath))
{
File.Delete(shortcutPath);
}
else
{
CreateShortCut(shortcutPath, System.IO.Path.Combine(SettingPath.ModulePath, "EpgTimerSrv.exe"), "");
}
button_shortCutSrv.Content = ((string)button_shortCutSrv.Content).Replace("を解除", "") + (File.Exists(shortcutPath) ? "を解除" : "");
}
catch (Exception ex)
{
Expand All @@ -534,6 +563,7 @@ private void CreateShortCut(String path, String targetPath, String description)
Type shortcutType = shell.GetType();
// TargetPathプロパティをセットする
shortcutType.InvokeMember("TargetPath", BindingFlags.SetProperty, null, shortCut, new object[] { targetPath });
shortcutType.InvokeMember("WorkingDirectory", BindingFlags.SetProperty, null, shortCut, new object[] { System.IO.Path.GetDirectoryName(targetPath) });
// Descriptionプロパティをセットする
shortcutType.InvokeMember("Description", BindingFlags.SetProperty, null, shortCut, new object[] { description });
// Saveメソッドを実行する
Expand Down

0 comments on commit 6aa2b3e

Please sign in to comment.