Skip to content

Commit

Permalink
Add validation to avoid copy trophies with date/time lower than the l…
Browse files Browse the repository at this point in the history
…ast sync trophy
  • Loading branch information
jhonathanc committed May 19, 2021
1 parent b516a8e commit 05014fb
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 6 deletions.
27 changes: 24 additions & 3 deletions PS3TrophyIsGood/CopyFrom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,16 @@ public Pair(int id, long date)
}
}

public CopyFrom()
private DateTime lastSyncTrophyTime;

public CopyFrom(DateTime lastSyncTrophyTime)
{
InitializeComponent();
this.lastSyncTrophyTime = lastSyncTrophyTime;
groupBox1.Visible = false;
}

private IEnumerable<long> _times;

public List<long> Times
{
get
Expand Down Expand Up @@ -107,7 +109,26 @@ private void button1_Click(object sender, EventArgs e)
else if (Regex.IsMatch(textBox1.Text,"https://psntrophyleaders.com/user/view/" + "\\S+/\\S+"))
{
_times = checkBox1.Checked ? smartCopy() : copyFrom();
if (!_times.Any(t => DateTime.Compare(t.TimeStampToDateTime(), DateTime.Now) > 0) || (MessageBox.Show(Properties.strings.CopyHasDateGreaterThanCurrent, Properties.strings.Danger, MessageBoxButtons.YesNo) == DialogResult.Yes))
var hasDateGreaterThanCurrent = _times.Any(t => DateTime.Compare(t.TimeStampToDateTime(), DateTime.Now) > 0);
var hasDateLowerThanLastSync = _times.Any(t => DateTime.Compare(lastSyncTrophyTime, t.TimeStampToDateTime()) > 0);

if (hasDateGreaterThanCurrent && hasDateLowerThanLastSync)
{
if ((MessageBox.Show(Properties.strings.CopyHasDateLowerThanLastSync, Properties.strings.Danger, MessageBoxButtons.YesNo) == DialogResult.Yes)
&& (MessageBox.Show(Properties.strings.CopyHasDateGreaterThanCurrent, Properties.strings.Danger, MessageBoxButtons.YesNo) == DialogResult.Yes))
DialogResult = DialogResult.OK;
}
else if (hasDateGreaterThanCurrent)
{
if (MessageBox.Show(Properties.strings.CopyHasDateGreaterThanCurrent, Properties.strings.Danger, MessageBoxButtons.YesNo) == DialogResult.Yes)
DialogResult = DialogResult.OK;
}
else if (hasDateLowerThanLastSync)
{
if (MessageBox.Show(Properties.strings.CopyHasDateLowerThanLastSync, Properties.strings.Danger, MessageBoxButtons.YesNo) == DialogResult.Yes)
DialogResult = DialogResult.OK;
}
else
DialogResult = DialogResult.OK;
}
else MessageBox.Show(Properties.strings.CantFindGame);
Expand Down
2 changes: 1 addition & 1 deletion PS3TrophyIsGood/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public Form1()
toolStripComboBox2.Items.AddRange(profiles);
toolStripComboBox2.SelectedIndex = 0;
dateTimePicker1.CustomFormat = Properties.strings.DateFormatString;
copyFrom = new CopyFrom();
}

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
Expand Down Expand Up @@ -439,6 +438,7 @@ private void OpenFile(string path_in)
ps3Time = lastSyncTrophyTime;
dtpForm = new DateTimePickForm(ps3Time);
dtpfForInstant = new DateTimePickForm(ps3Time);
copyFrom = new CopyFrom(ps3Time);

RefreshComponents();
isOpen = true;
Expand Down
9 changes: 9 additions & 0 deletions PS3TrophyIsGood/Properties/strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions PS3TrophyIsGood/Properties/strings.pt-BR.resx
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,7 @@
<data name="CopyHasDateGreaterThanCurrent" xml:space="preserve">
<value>Alguns troféus ficarão com a data/hora maior que a atual. Deseja continuar?</value>
</data>
<data name="CopyHasDateLowerThanLastSync" xml:space="preserve">
<value>Alguns troféus ficarão com a data/hora menor que a data/hora do último troféu sincronizado. Deseja continuar?</value>
</data>
</root>
7 changes: 5 additions & 2 deletions PS3TrophyIsGood/Properties/strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,12 @@
<value>"{0}" was not found. Please, select a valid trophy folder.</value>
</data>
<data name="SelectedDateGreaterThanCurrent" xml:space="preserve">
<value>Selected date/time is greater than the current. Are you sure?</value>
<value>Selected date/time is greater than the current date/time. Continue?</value>
</data>
<data name="CopyHasDateGreaterThanCurrent" xml:space="preserve">
<value>Some trophies will have date/time greater than the current. Are you sure?</value>
<value>Some trophies will have date/time greater than the current date/time. Continue?</value>
</data>
<data name="CopyHasDateLowerThanLastSync" xml:space="preserve">
<value>Some trophies will have date/time lower than the last synchronized trophy. Continue?</value>
</data>
</root>
3 changes: 3 additions & 0 deletions PS3TrophyIsGood/Properties/strings.zh-Hant.resx
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,7 @@
<data name="CopyHasDateGreaterThanCurrent" xml:space="preserve">
<value>某些獎杯的日期/時間將大於當前日期/時間。 你確定嗎?</value>
</data>
<data name="CopyHasDateLowerThanLastSync" xml:space="preserve">
<value>某些獎杯的日期/時間會比上次同步獎杯的日期/時間低。 繼續?</value>
</data>
</root>

0 comments on commit 05014fb

Please sign in to comment.