public void setVariantsGridDataSource(Track track) { if (track == null) { _decodeForm.VariantsGrid.DataSource = null; _decodeForm.VariantsGrid.Columns[(int)VariantGridColumn.Rate].HeaderCell.SortGlyphDirection = System.Windows.Forms.SortOrder.None; return; } //keep user sort Serializable.SortOrder sortOrder = Serializable.SortOrder.Descending; if (_decodeForm.VariantsGrid.Columns[(int)VariantGridColumn.Rate].HeaderCell.SortGlyphDirection == System.Windows.Forms.SortOrder.Ascending) { sortOrder = Serializable.SortOrder.Ascending; } if (sortOrder != track.CurrentSort()) { track.Sort(sortOrder); } _decodeForm.VariantsGrid.DataSource = track; if (sortOrder == Serializable.SortOrder.Descending) { _decodeForm.VariantsGrid.Columns[(int)VariantGridColumn.Rate].HeaderCell.SortGlyphDirection = System.Windows.Forms.SortOrder.Descending; } else { _decodeForm.VariantsGrid.Columns[(int)VariantGridColumn.Rate].HeaderCell.SortGlyphDirection = System.Windows.Forms.SortOrder.Ascending; } //select de preferred variant. selectCellInGrid(_decodeForm.VariantsGrid, track.GetPreferredVariantIndex(), 0); _decodeForm.UpdateTxtBox(); }
private void init(byte[] variantBytes, int startPosition, int len) { sortOrder = Serializable.SortOrder.None; preferredVariantIndex = -1; preferredUserVariantIndex = -1; trackBytes = null; variants.Clear(); if (len > 0) { //copy track bytes adding a 0 add the beginning and another at the end trackBytes = new byte[len + 2]; Array.Copy(variantBytes, startPosition, trackBytes, 1, len); // calculate for two directions variants.Add(new Variant(trackBytes, bpc, add) { track = trackId, direction = 0 }); variants.Add(new Variant(BitSolution.Reverse(trackBytes), bpc, add) { track = trackId, direction = 1 }); variants.Sort(new VariantComparer(SortOrder.Descending)); preferredUserVariantIndex = 0; } }
public void Sort(Serializable.SortOrder sortOrder) { if (this.sortOrder != sortOrder) { if (variants != null) { Variant preferredVariant = GetPreferredVariant(); variants.Sort(new VariantComparer(sortOrder)); //update preferred variant if (preferredUserVariantIndex >= 0) { preferredUserVariantIndex = variants.IndexOf(preferredVariant); } else { preferredVariantIndex = variants.IndexOf(preferredVariant); } this.sortOrder = sortOrder; } } }
public void deserialiseMetaData(byte[] buf, ref int index) { byte bpc; byte add; int startIndex = index; int preferredVariantIndex; int preferredUserVariantIndex; Serializable.SortOrder sortOrder; if (index + buf.Length < serialiseMetaDataSize()) { throw new Exception("buffer to small"); } /* read the settings */ bpc = (byte)buf[index++]; add = buf[index++]; // preferredDirection = (int)buf[index++]; preferredVariantIndex = (int)buf[index++]; preferredUserVariantIndex = (int)buf[index++]; sortOrder = (Serializable.SortOrder)buf[index++]; /* correct the int to byte conversion issue */ if ((preferredVariantIndex) == 0xff) { preferredVariantIndex = -1; } if ((preferredUserVariantIndex) == 0xff) { preferredUserVariantIndex = -1; } // if ((preferredDirection) == 0xff) preferredDirection = -1; /* apply settings */ this.preferredVariantIndex = preferredVariantIndex; this.preferredUserVariantIndex = preferredUserVariantIndex; /* change bpc if required */ if (this.bpc != bpc || this.add != add) { ChangeGroupSettings(bpc, add); } Sort(sortOrder); /* we have to apply this again according to Francis */ this.preferredVariantIndex = preferredVariantIndex; this.preferredUserVariantIndex = preferredUserVariantIndex; #if DEBUG if (index - startIndex != serialiseMetaDataSize()) { throw new Exception("serialiseSize is buggy (returning the wrong buffer size)"); } #endif }
/** * protected constructor that must be only used to build serialized cards */ protected Track(int trackId, b serializedB) { this.trackId = trackId; bpc = serializedB._bpc; add = serializedB._add; preferredVariantIndex = serializedB._pVI; preferredUserVariantIndex = serializedB._pUVI; trackBytes = serializedB._tB; sortOrder = Serializable.SortOrder.None; variants = null; if (serializedB._aV.Count > 0) { // variants = new Variant[serializedB._aV.Length]; variants.Clear(); for (int i = 0; i < variants.Count; i++) { if (trackBytes != null) { int direction = 1; if (i < (variants.Count / 2)) { direction = 0; } variants[i] = new Variant(trackBytes, bpc, add) { direction = direction, track = trackId }; } else { variants[i] = null; } } if (serializedB._sO != Serializable.SortOrder.None) { Sort(serializedB._sO); //this must be done after sorting again!! preferredVariantIndex = serializedB._pVI; preferredUserVariantIndex = serializedB._pUVI; } //set user strings when sort order is correct for (int i = 0; i < variants.Count; i++) { if ((serializedB._aV[i] != null) && (serializedB._aV[i]._uS != null)) { SetTrack(new StringWithParity(serializedB._aV[i]._uS)); break;//there was only one user string. } } } }
public void ChangeGroupSettings(byte bpc, byte add) { this.bpc = bpc; this.add = add; Serializable.SortOrder sortOrder = this.sortOrder; //remove 0 at the beginning and at the end. init(trackBytes, 1, trackBytes.Length - 2); if (sortOrder != Serializable.SortOrder.None) { Sort(sortOrder); } }