Skip to content

Commit

Permalink
Merge pull request #142 from aaron-williamson/improve-file-sync
Browse files Browse the repository at this point in the history
Improve File Sync, Load and Add, and Clean Up
  • Loading branch information
cadon authored Jan 14, 2017
2 parents 002ea76 + 873ab43 commit b4505ca
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
27 changes: 26 additions & 1 deletion ARKBreedingStats/Creature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace ARKBreedingStats
{
[Serializable()]
public class Creature
public class Creature : IEquatable<Creature>
{
public string species;
public string name;
Expand Down Expand Up @@ -71,6 +71,31 @@ public Creature(string species, string name, string owner, Sex sex, int[] levels
calculateLevelFound();
}

public bool Equals(Creature other)
{
if (other.guid == guid)
return true;
else
return false;
}

public override bool Equals(object obj)
{
if (obj == null)
return false;

Creature creatureObj = obj as Creature;
if (creatureObj == null)
return false;
else
return Equals(creatureObj);
}

public override int GetHashCode()
{
return guid.GetHashCode();
}

public void calculateLevelFound()
{
levelFound = 0;
Expand Down
9 changes: 9 additions & 0 deletions ARKBreedingStats/CreatureCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,14 @@ namespace ARKBreedingStats
public List<Player> players = new List<Player>();
[XmlArray]
public List<Tribe> tribes = new List<Tribe>();

public void mergeCreatureList(List<Creature> creaturesToMerge)
{
foreach (Creature creature in creaturesToMerge)
{
if (!creatures.Contains(creature))
creatures.Add(creature);
}
}
}
}
6 changes: 3 additions & 3 deletions ARKBreedingStats/FileSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ private void onChanged(object source, FileSystemEventArgs e)
break;
}
}
catch (FileNotFoundException ex)
catch (FileNotFoundException)
{ }
catch (IOException ex)
catch (IOException)
{ }
catch (UnauthorizedAccessException ex)
catch (UnauthorizedAccessException)
{ }
Thread.Sleep(500);
}
Expand Down
4 changes: 2 additions & 2 deletions ARKBreedingStats/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public void collectionChanged()
}
else
{
loadCollectionFile(currentFileName);
loadCollectionFile(currentFileName, true);
}
}

Expand Down Expand Up @@ -1089,7 +1089,7 @@ private void loadCollectionFile(string fileName, bool keepCurrentCreatures = fal
assignCollectionClasses();

if (keepCurrentCreatures)
creatureCollection.creatures.AddRange(oldCreatures);
creatureCollection.mergeCreatureList(oldCreatures);
else
{
currentFileName = fileName;
Expand Down

0 comments on commit b4505ca

Please sign in to comment.