|
|
|
@ -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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|