main
syneffort 1 year ago
parent 4434f6f70e
commit f0f7291a21
  1. 2
      ChromeStarter/ChromeStarter/ChromeStarter.csproj
  2. 35
      ChromeStarter/ChromeStarter/MainWindow.xaml
  3. 71
      ChromeStarter/ChromeStarter/MainWindow.xaml.cs
  4. 29
      ChromeStarter/ChromeStarter/Models/PlanCollection.cs

@ -76,7 +76,7 @@
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="Models\ProfilePlanCollection.cs" />
<Compile Include="Models\PlanCollection.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>

@ -6,41 +6,38 @@
xmlns:local="clr-namespace:ChromeStarter"
xmlns:model="clr-namespace:ChromeStarter.Models"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="500"
Title="Chrome Starter" Height="450" Width="500"
MinHeight="450" MinWidth="500"
Icon="/Resources/Icon.ico">
<Window.DataContext>
<model:ProfilePlanCollection/>
<model:PlanCollection/>
</Window.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="30"/>
<RowDefinition Height="*"/>
<RowDefinition Height="30"/>
<RowDefinition Height="50"/>
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Center">
<StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Left">
<Label Content="Path: "/>
<TextBox x:Name="tbChromePath" Width="350" Margin="10 0 0 0" VerticalAlignment="Center"/>
<Button x:Name="btnFindChromePath" Content="..." Width="30" Margin="10 0 0 0" VerticalAlignment="Center"
Click="btnFindChromePath_Click"/>
</StackPanel>
<ListView Grid.Row="1" x:Name="lvProfiles" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto" Margin="5" ItemsSource="{Binding ProfilePlans}">
<Label Grid.Row="1" x:Name="lbProfileLabel" Content="Target Profile: 0"/>
<ListView Grid.Row="2" x:Name="lvProfiles" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto" Margin="5" ItemsSource="{Binding Plans}">
<ListView.View>
<GridView>
<GridViewColumn Header="Profile" Width="Auto">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" HorizontalAlignment="Center" TextAlignment="Center"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn x:Name="gvcStartPage" Header="Start Page" Width="420">
<GridViewColumn x:Name="gvcStartPage" Header="Start Page" Width="{Binding ElementName=lvProfiles, Path=ActualWidth}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding StartPage, Mode=TwoWay}" Width="{Binding ElementName=gvcStartPage, Path=ActualWidth}" BorderThickness="0" TextAlignment="Left"/>
<TextBox Text="{Binding StartPage, Mode=TwoWay}" Width="{Binding ElementName=lvProfiles, Path=ActualWidth}" TextAlignment="Left"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
@ -48,6 +45,16 @@
</ListView.View>
</ListView>
<Button Grid.Row="2" x:Name="btnStart" Content="Start" Click="btnStart_Click"/>
<Grid Grid.Row="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" x:Name="btnAddStartpage" Margin="10 3 10 3" Content="Add new start page" Click="btnAddStartpage_Click"/>
<Button Grid.Column="1" x:Name="btnRemoveStartpage" Margin="10 3 10 3" Content="Remove last start page" Click="btnRemoveStartpage_Click"/>
</Grid>
<Button Grid.Row="4" x:Name="btnStart" Content="Start" Margin="0 10 0 0" Click="btnStart_Click"/>
</Grid>
</Window>

@ -31,7 +31,8 @@ namespace ChromeStarter
private string _chromePath;
string _savePath;
private ProfilePlanCollection _profilePlanCollection;
private List<string> _userProfileNames;
private PlanCollection _profilePlanCollection;
public MainWindow()
{
@ -43,7 +44,7 @@ namespace ChromeStarter
{
_chromePath = ConfigurationManager.AppSettings[CHROME_PATH_KEY];
_savePath = $@"{AppDomain.CurrentDomain.BaseDirectory}\cache.json";
_profilePlanCollection = this.DataContext as ProfilePlanCollection;
_profilePlanCollection = this.DataContext as PlanCollection;
if (!string.IsNullOrEmpty(_chromePath) )
tbChromePath.Text = _chromePath;
@ -61,26 +62,24 @@ namespace ChromeStarter
return;
}
List<string> profiles = GetProfiles(localChromeUserDataPath);
if (profiles == null || profiles.Count < 1)
_userProfileNames = GetProfiles(localChromeUserDataPath);
lbProfileLabel.Content = $"Target Profile: {_userProfileNames.Count}";
if (_userProfileNames == null || _userProfileNames.Count < 1)
{
ShowErrorMessage("사용자 프로필을 확인할 수 없습니다. 크롬에서 사용자 프로필을 생성하십시오.");
return;
}
Dictionary<string, ProfilePlan> cache = new Dictionary<string, ProfilePlan>();
List<string> cache = new List<string>();
if (File.Exists(_savePath))
{
string jsonString = File.ReadAllText(_savePath);
cache = JsonConvert.DeserializeObject<Dictionary<string, ProfilePlan>>(jsonString);
cache = JsonConvert.DeserializeObject<List<string>>(jsonString);
}
foreach (string profile in profiles)
foreach (string startPage in cache)
{
if (cache.ContainsKey(profile))
_profilePlanCollection.ProfilePlans.Add(new ProfilePlan() { Name = profile, StartPage = cache[profile].StartPage });
else
_profilePlanCollection.ProfilePlans.Add(new ProfilePlan() { Name = profile });
_profilePlanCollection.Plans.Add(new Plan() { StartPage = startPage });
}
}
@ -105,12 +104,12 @@ namespace ChromeStarter
MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
private void SavePlanCache(ProfilePlanCollection profilePlanCollection)
private void SavePlanCache(PlanCollection planCollection)
{
Dictionary<string, ProfilePlan> cache = new Dictionary<string, ProfilePlan>();
foreach (var profilePlan in profilePlanCollection.ProfilePlans)
List<string> cache = new List<string>();
foreach (var profilePlan in planCollection.Plans)
{
cache.Add(profilePlan.Name, profilePlan);
cache.Add(profilePlan.StartPage);
}
string jsonString = JsonConvert.SerializeObject(cache);
@ -137,13 +136,37 @@ namespace ChromeStarter
{
try
{
if (_profilePlanCollection == null || _profilePlanCollection.GetCommandParameter().Count < 1)
if (string.IsNullOrEmpty(tbChromePath.Text))
{
ShowErrorMessage("사용자 프로필 계획을 생성할 수 없습니다.");
ShowErrorMessage("크롬 실행파일 위치를 설정해야합니다.");
return;
}
foreach (string profilePlan in _profilePlanCollection.GetCommandParameter())
if (_profilePlanCollection == null)
{
ShowErrorMessage("실행 계획을 생성할 수 없습니다.");
return;
}
List<Plan> removeTarget = new List<Plan>();
foreach (Plan plan in _profilePlanCollection.Plans)
{
if (string.IsNullOrEmpty(plan.StartPage))
removeTarget.Add(plan);
}
foreach (Plan plan in removeTarget)
{
_profilePlanCollection.Plans.Remove(plan);
}
List<string> parameters = _profilePlanCollection.GetCommandParameter(_userProfileNames);
if (parameters.Count < 1)
{
ShowErrorMessage("실행 계획 파라미터를 생성할 수 없습니다.");
return;
}
foreach (string profilePlan in parameters)
{
Process.Start(tbChromePath.Text, profilePlan);
}
@ -155,5 +178,17 @@ namespace ChromeStarter
ShowErrorMessage(ex.Message);
}
}
private void btnAddStartpage_Click(object sender, RoutedEventArgs e)
{
_profilePlanCollection.Plans.Add(new Plan() { StartPage = "" });
}
private void btnRemoveStartpage_Click(object sender, RoutedEventArgs e)
{
Plan lastPlan = _profilePlanCollection.Plans.LastOrDefault();
if (lastPlan != null)
_profilePlanCollection.Plans.Remove(lastPlan);
}
}
}

@ -8,24 +8,24 @@ using System.Threading.Tasks;
namespace ChromeStarter.Models
{
public class ProfilePlanCollection : INotifyPropertyChanged
public class PlanCollection : INotifyPropertyChanged
{
private ObservableCollection<ProfilePlan> _profilePlans;
private ObservableCollection<Plan> _plans;
public event PropertyChangedEventHandler PropertyChanged;
public ProfilePlanCollection()
public PlanCollection()
{
_profilePlans = new ObservableCollection<ProfilePlan>();
_plans = new ObservableCollection<Plan>();
}
public ObservableCollection<ProfilePlan> ProfilePlans
public ObservableCollection<Plan> Plans
{
get { return _profilePlans; }
get { return _plans; }
set
{
_profilePlans = value;
OnPropertyChanged(nameof(this.ProfilePlans));
_plans = value;
OnPropertyChanged(nameof(this.Plans));
}
}
@ -35,21 +35,24 @@ namespace ChromeStarter.Models
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
public List<string> GetCommandParameter()
public List<string> GetCommandParameter(List<string> profileNames)
{
List<string> parameters = new List<string>();
foreach (ProfilePlan plan in _profilePlans)
foreach (string profileName in profileNames)
{
parameters.Add($"--profile-directory=\"{plan.Name}\" {plan.StartPage}");
foreach (Plan plan in _plans)
{
parameters.Add($"--profile-directory=\"{profileName}\" {plan.StartPage}");
}
}
return parameters;
}
}
public class ProfilePlan
public class Plan
{
public string Name { get; set; }
public string StartPage { get; set; }
}
}
Loading…
Cancel
Save