コード例 #1
0
        public override Rect GetBarBounds(BarEntry e)
#endif
        {
            IBarDataSet set = data.GetDataSetForEntry(e);

            if (set == null)
            {
#if __ANDROID__ && !SKIASHARP
                outputRect.Set(float.MinValue, float.MinValue, float.MinValue, float.MinValue);
                return;
#else
                return(Rect.Empty);
#endif
            }

            float y = e.Y;
            float x = e.X;

            float barWidth = data.BarWidth;

            float top    = x - barWidth / 2f;
            float bottom = x + barWidth / 2f;
            float left   = y >= 0 ? y : 0;
            float right  = y <= 0 ? y : 0;

#if __ANDROID__ && !SKIASHARP
            outputRect.Set(left, top, right, bottom);
            GetTransformer(set.AxisDependency).RectValueToPixel(outputRect);
#else
            var outputRect = new Rect(left, top, right, bottom);
            return(GetTransformer(set.AxisDependency).RectValueToPixel(outputRect));
#endif
        }
コード例 #2
0
        /// <summary>
        /// Collect all icons
        /// </summary>
        private static void CollectIcons(ApkFile apk, List <BarEntry> entries, Dictionary <string, string> apkPath2barPath)
        {
#if DEBUG
            Debugger.Launch();
#endif

            var iconNames = apk.Manifest.Activities.Select(x => x.Icon).Where(x => !string.IsNullOrEmpty(x)).ToList();
            var appIcon   = apk.Manifest.ApplicationIcon;
            if (!string.IsNullOrEmpty(appIcon))
            {
                iconNames.Add(appIcon);
            }

            foreach (var name in iconNames)
            {
                if (apkPath2barPath.ContainsKey(name))
                {
                    continue;
                }
                int nameAsInt;
                if (!int.TryParse(name, out nameAsInt))
                {
                    continue;
                }
                var resId    = apk.Resources.GetResourceIdentifier(nameAsInt);
                var iconData = IconBuilder.GetIcon(resId, apk);
                if (iconData != null)
                {
                    var barPath = "android/res/drawable/" + resId + ".png";
                    var entry   = new BarEntry(barPath, new MemoryStream(iconData));
                    entries.Add(entry);
                    apkPath2barPath[name] = barPath;
                }
            }
        }
コード例 #3
0
        public EntryDetailsDialog(BarEntry e, string BarPath)
        {
            entry = e;

            InitializeComponent();
            GetCustomValues(BarPath);
            DataContext = this;
        }
コード例 #4
0
        private List <BarDataSet> getDataSet()
        {
            List <BarDataSet> dataSets = null;

            List <BarEntry> valueSet1 = new List <BarEntry>();
            BarEntry        v1e1      = new BarEntry(110.000f, 0); // Jan

            valueSet1.Add(v1e1);
            BarEntry v1e2 = new BarEntry(40.000f, 1); // Feb

            valueSet1.Add(v1e2);
            BarEntry v1e3 = new BarEntry(60.000f, 2); // Mar

            valueSet1.Add(v1e3);
            BarEntry v1e4 = new BarEntry(30.000f, 3); // Apr

            valueSet1.Add(v1e4);
            BarEntry v1e5 = new BarEntry(90.000f, 4); // May

            valueSet1.Add(v1e5);
            BarEntry v1e6 = new BarEntry(100.000f, 5); // Jun

            valueSet1.Add(v1e6);

            List <BarEntry> valueSet2 = new List <BarEntry>();
            BarEntry        v2e1      = new BarEntry(150.000f, 0); // Jan

            valueSet2.Add(v2e1);
            BarEntry v2e2 = new BarEntry(90.000f, 1); // Feb

            valueSet2.Add(v2e2);
            BarEntry v2e3 = new BarEntry(120.000f, 2); // Mar

            valueSet2.Add(v2e3);
            BarEntry v2e4 = new BarEntry(60.000f, 3); // Apr

            valueSet2.Add(v2e4);
            BarEntry v2e5 = new BarEntry(20.000f, 4); // May

            valueSet2.Add(v2e5);
            BarEntry v2e6 = new BarEntry(80.000f, 5); // Jun

            valueSet2.Add(v2e6);

            BarDataSet barDataSet1 = new BarDataSet(valueSet1, "1");

            barDataSet1.Color = (Color.Rgb(0, 155, 0));
            BarDataSet barDataSet2 = new BarDataSet(valueSet2, "2");

            //barDataSet2.SetColor(ColorTemplate.ColorfulColors);

            dataSets = new List <BarDataSet>();
            dataSets.Add(barDataSet1);
            dataSets.Add(barDataSet2);
            return(dataSets);
        }
コード例 #5
0
        /// <summary>
        /// This method creates the Highlight object that also indicates which value of a stacked BarEntry has been
        /// selected.
        /// </summary>
        /// <param name="high">the Highlight to work with looking for stacked values</param>
        /// <param name="dataSet"></param>
        /// <param name="xVal"></param>
        /// <param name="yVal"></param>
        /// <returns></returns>
        public Highlight GetStackedHighlight(Highlight high, IDataSet <BarEntry> dataSet, float xVal, float yVal)
        {
            BarEntry entry = dataSet.EntryForXValue(xVal, yVal);

            if (entry == null)
            {
                return(null);
            }

            // not stacked
            if (entry.YVals == null)
            {
                return(high);
            }
            else
            {
                var ranges = entry.Ranges;

                if (ranges.Count > 0)
                {
                    int stackIndex = GetClosestStackIndex(ranges, yVal);

                    var pixels = Chart.GetTransformer(dataSet.AxisDependency).PointValueToPixel(high.X, ranges[stackIndex].To);

                    Highlight stackedHigh = new Highlight(
                        entry.X,
                        entry.Y,
                        (float)pixels.X,
                        (float)pixels.Y,
                        high.DataSetIndex,
                        stackIndex,
                        high.Axis
                        );

                    return(stackedHigh);
                }
            }

            return(null);
        }
コード例 #6
0
 public override void GetBarBounds(BarEntry e, Rect outputRect)
コード例 #7
0
        void PrepareBuffer(IBarDataSet dataSet, int index)
        {
            if (Chart is IBarDataProvider dataProvider && (Chart.BarData is BarData barData))
            {
                var barWidthHalf         = barData.BarWidth / 2f;
                var bufferIndex          = 0;
                var containsStacks       = dataSet.IsStacked;
                var isInverted           = dataProvider.IsInverted(axis: dataSet.AxisDependency);
                var phaseY               = Animator.PhaseY;
                var size                 = (float)Math.Ceiling(dataSet.EntryCount * Animator.PhaseX);
                IDataSet <BarEntry> data = dataSet;
                for (int i = 0; i < size; i++)
                {
                    BarEntry e = data[i];
                    if (e == null)
                    {
                        continue;
                    }

                    var x     = e.X;
                    var left  = x - barWidthHalf;
                    var right = x + barWidthHalf;

                    var y    = e.Y;
                    var vals = e.YVals;
                    if (containsStacks && vals != null)
                    {
                        var posY = 0.0f;
                        var negY = -e.NegativeSum;

                        // fill the stack
                        foreach (var value in vals)
                        {
                            float yStart;
                            if (value == 0.0 && (posY == 0.0 || negY == 0.0))
                            {
                                // Take care of the situation of a 0.0 value, which overlaps a non-zero bar
                                y      = value;
                                yStart = y;
                            }
                            else if (value >= 0.0f)
                            {
                                y      = posY;
                                yStart = posY + value;
                                posY   = yStart;
                            }
                            else
                            {
                                y      = negY;
                                yStart = negY + Math.Abs(value);
                                negY  += Math.Abs(value);
                            }

                            var top = isInverted
                                ? (y <= yStart ? y : yStart)
                                : (y >= yStart ? y : yStart);
                            var bottom = isInverted
                                ? (y >= yStart ? y : yStart)
                                : (y <= yStart ? y : yStart);

                            // multiply the height of the rect with the phase
                            top    *= phaseY;
                            bottom *= phaseY;

                            BarBuffer[index][bufferIndex++] = new SKPoint(left, top);
                            BarBuffer[index][bufferIndex++] = new SKPoint(right, bottom);
                        }
                    }
                    else
                    {
                        float bottom, top;

                        if (isInverted)
                        {
                            bottom = y >= 0 ? y : 0;
                            top    = y <= 0 ? y : 0;
                        }
                        else
                        {
                            top    = y >= 0 ? y : 0;
                            bottom = y <= 0 ? y : 0;
                        }

                        // multiply the height of the rect with the phase
                        if (top > 0)
                        {
                            top *= phaseY;
                        }
                        else
                        {
                            bottom *= phaseY;
                        }
                        BarBuffer[index][bufferIndex++] = new SKPoint(left, top);
                        BarBuffer[index][bufferIndex++] = new SKPoint(right, bottom);
                    }
                }
            }
        }
コード例 #8
0
        public override void DrawValues(SKCanvas c)
        {
            // if values are drawn
            if (IsDrawingValuesAllowed(Chart))
            {
                BarData data     = Chart.BarData;
                var     dataSets = data.DataSets;

                float valueOffsetPlus   = 4.5f.DpToPixel();
                var   drawValueAboveBar = Chart.IsDrawValueAboveBar;

                for (int i = 0; i < data.DataSetCount; i++)
                {
                    IBarDataSet barDataSet = dataSets[i];

                    if (!ShouldDrawValues(barDataSet))
                    {
                        continue;
                    }

                    IDataSet <BarEntry> dataSet = barDataSet;
                    // apply the text-styling defined by the DataSet
                    ApplyValueTextStyle(barDataSet);

                    var isInverted = Chart.IsInverted(barDataSet.AxisDependency);

                    // calculate the correct offset depending on the draw position of
                    // the value
                    float valueTextHeight = ValuePaint.MeasureHeight("8");
                    float posOffset       = (drawValueAboveBar ? -valueOffsetPlus : valueTextHeight + valueOffsetPlus);
                    float negOffset       = (drawValueAboveBar ? valueTextHeight + valueOffsetPlus : -valueOffsetPlus);

                    if (isInverted)
                    {
                        posOffset = -posOffset - valueTextHeight;
                        negOffset = -negOffset - valueTextHeight;
                    }

                    // get the buffer
                    var buffer = BarBuffer[i];

                    float phaseY = Animator.PhaseY;

                    var iconsOffset = barDataSet.IconsOffset;
                    iconsOffset.X = iconsOffset.X.DpToPixel();
                    iconsOffset.Y = iconsOffset.Y.DpToPixel();

                    // if only single values are drawn (sum)
                    if (!barDataSet.IsStacked)
                    {
                        for (int j = 0; j < buffer.Length * Animator.PhaseX; j += 2)
                        {
                            float x = (buffer[j].X + buffer[j + 1].X) / 2f;

                            if (!ViewPortHandler.IsInBoundsRight(x))
                            {
                                break;
                            }

                            if (!ViewPortHandler.IsInBoundsY(buffer[j].Y) ||
                                !ViewPortHandler.IsInBoundsLeft(x))
                            {
                                continue;
                            }

                            BarEntry entry = dataSet[j / 2];
                            float    val   = entry.Y;

                            if (barDataSet.IsDrawValuesEnabled)
                            {
                                DrawValue(c, barDataSet.ValueFormatter, val, entry, i, x,
                                          val >= 0 ?
                                          (buffer[j].Y + posOffset) :
                                          (buffer[j + 1].Y + negOffset),
                                          barDataSet.ValueTextColorAt(j / 2));
                            }

                            if (entry.Icon != null && barDataSet.IsDrawIconsEnabled)
                            {
                                float px = x;
                                float py = val >= 0 ?
                                           (buffer[j].Y + posOffset) :
                                           (buffer[j + 1].Y + negOffset);

                                px += iconsOffset.X;
                                py += iconsOffset.Y;

                                entry.Icon.Draw(
                                    c,
                                    (int)px,
                                    (int)py);
                            }
                        }

                        // if we have stacks
                    }
                    else
                    {
                        Transformer trans = Chart.GetTransformer(barDataSet.AxisDependency);

                        int bufferIndex = 0;
                        int index       = 0;
                        while (index < barDataSet.EntryCount * Animator.PhaseX)
                        {
                            BarEntry entry = dataSet[index];

                            var   vals = entry.YVals;
                            float x    = (buffer[bufferIndex].X + buffer[bufferIndex + 1].X) / 2f;

                            var color = barDataSet.ValueTextColorAt(index);

                            // we still draw stacked bars, but there is one
                            // non-stacked
                            // in between
                            if (vals == null)
                            {
                                if (!ViewPortHandler.IsInBoundsRight(x))
                                {
                                    break;
                                }

                                if (!ViewPortHandler.IsInBoundsY(buffer[bufferIndex].Y) ||
                                    !ViewPortHandler.IsInBoundsLeft(x))
                                {
                                    continue;
                                }

                                if (barDataSet.IsDrawValuesEnabled)
                                {
                                    DrawValue(c, barDataSet.ValueFormatter, entry.Y, entry, i, x,
                                              buffer[bufferIndex].Y +
                                              (entry.Y >= 0 ? posOffset : negOffset),
                                              color);
                                }

                                if (entry.Icon != null && barDataSet.IsDrawIconsEnabled)
                                {
                                    float px = x;
                                    float py = buffer[bufferIndex].Y +
                                               (entry.Y >= 0 ? posOffset : negOffset);

                                    px += iconsOffset.X;
                                    py += iconsOffset.Y;

                                    entry.Icon.Draw(
                                        c,
                                        (int)px,
                                        (int)py);
                                }

                                // draw stack values
                            }
                            else
                            {
                                SKPoint[] transformed = new SKPoint[vals.Count];

                                float posY = 0f;
                                float negY = -entry.NegativeSum;

                                for (int idx = 0; idx < transformed.Length; idx++)
                                {
                                    float value = vals[idx];
                                    float y;

                                    if (value == 0.0f && (posY == 0.0f || negY == 0.0f))
                                    {
                                        // Take care of the situation of a 0.0 value, which overlaps a non-zero bar
                                        y = value;
                                    }
                                    else if (value >= 0.0f)
                                    {
                                        posY += value;
                                        y     = posY;
                                    }
                                    else
                                    {
                                        y     = negY;
                                        negY -= value;
                                    }

                                    transformed[idx].Y = y * phaseY;
                                }

                                transformed = trans.PointValuesToPixel(transformed);

                                for (int k = 0; k < transformed.Length; k++)
                                {
                                    float val       = vals[k / 2];
                                    var   drawBelow =
                                        (val == 0.0f && negY == 0.0f && posY > 0.0f) ||
                                        val < 0.0f;
                                    float y = transformed[k].Y
                                              + (drawBelow ? negOffset : posOffset);

                                    if (!ViewPortHandler.IsInBoundsRight(x))
                                    {
                                        break;
                                    }

                                    if (!ViewPortHandler.IsInBoundsY(y) ||
                                        !ViewPortHandler.IsInBoundsLeft(x))
                                    {
                                        continue;
                                    }

                                    if (barDataSet.IsDrawValuesEnabled)
                                    {
                                        DrawValue(c,
                                                  barDataSet.ValueFormatter,
                                                  vals[k / 2],
                                                  entry,
                                                  i,
                                                  x,
                                                  y,
                                                  color);
                                    }

                                    if (entry.Icon != null && barDataSet.IsDrawIconsEnabled)
                                    {
                                        entry.Icon.Draw(c,
                                                        (int)(x + iconsOffset.X),
                                                        (int)(y + iconsOffset.Y));
                                    }
                                }
                            }

                            bufferIndex = vals == null ? bufferIndex + 2 : bufferIndex + 2 * vals.Count;
                            index++;
                        }
                    }
                }
            }
        }
コード例 #9
0
        protected virtual void DrawDataSet(SKCanvas c, IBarDataSet barDataSet, int index)
        {
            Transformer trans = Chart.GetTransformer(barDataSet.AxisDependency);

            BarBorderPaint.Color       = barDataSet.BarBorderColor;
            BarBorderPaint.StrokeWidth = barDataSet.BarBorderWidth.DpToPixel();

            var drawBorder = barDataSet.BarBorderWidth > 0.0f;

            float phaseX = Animator.PhaseX;

            // draw the bar shadow before the values
            if (Chart.IsDrawBarShadow)
            {
                ShadowPaint.Color = barDataSet.BarShadowColor;
                IDataSet <BarEntry> dataSet = barDataSet;
                BarData             barData = Chart.BarData;

                float barWidth     = barData.BarWidth;
                float barWidthHalf = barWidth / 2.0f;
                float x;

                for (int i = 0, count = Math.Min((int)Math.Ceiling(barDataSet.EntryCount * phaseX), barDataSet.EntryCount);
                     i < count;
                     i++)
                {
                    BarEntry e = dataSet[i];

                    x = e.X;
                    BarShadowRectBuffer.Left  = x - barWidthHalf;
                    BarShadowRectBuffer.Right = x + barWidthHalf;

                    BarShadowRectBuffer = trans.RectValueToPixel(BarShadowRectBuffer);

                    if (!ViewPortHandler.IsInBoundsLeft(BarShadowRectBuffer.Right))
                    {
                        continue;
                    }

                    if (!ViewPortHandler.IsInBoundsRight(BarShadowRectBuffer.Left))
                    {
                        break;
                    }

                    BarShadowRectBuffer.Top    = ViewPortHandler.ContentTop;
                    BarShadowRectBuffer.Bottom = ViewPortHandler.ContentBottom;

                    c.DrawRect(BarShadowRectBuffer, ShadowPaint);
                }
            }

            PrepareBuffer(dataSet: barDataSet, index: index);
            SKPoint[] pts;
            BarBuffer[index] = pts = trans.PointValuesToPixel(BarBuffer[index]);
            // initialize the buffer
            bool isCustomFill  = barDataSet.Fills != null && barDataSet.Fills.Count != 0;
            bool isSingleColor = barDataSet.Colors.Count == 1;
            bool isInverted    = Chart.IsInverted(barDataSet.AxisDependency);

            if (isSingleColor)
            {
                RenderPaint.Color = barDataSet.Color;
            }

            for (int j = 0, pos = 0; j < pts.Length; j += 2, pos++)
            {
                if (!ViewPortHandler.IsInBoundsLeft(pts[j + 1].X))
                {
                    continue;
                }

                if (!ViewPortHandler.IsInBoundsRight(pts[j].X))
                {
                    break;
                }

                if (!isSingleColor)
                {
                    // Set the color for the currently drawn value. If the index
                    // is out of bounds, reuse colors.
                    RenderPaint.Color = barDataSet.ColorAt(pos);
                }

                if (isCustomFill)
                {
                    barDataSet.GetFill(pos)
                    .Draw(
                        c, RenderPaint,
                        pts[j].X,
                        pts[j].Y,
                        pts[j + 1].X,
                        pts[j + 1].Y,
                        isInverted ? FillDirection.Down : FillDirection.Up);
                }
                else
                {
                    DrawRect(c, pts[j].X, pts[j].Y, pts[j + 1].X,
                             pts[j + 1].Y, RenderPaint);
                }

                if (drawBorder)
                {
                    DrawRect(c, pts[j].X, pts[j].Y, pts[j + 1].X,
                             pts[j + 1].Y, BarBorderPaint);
                }
            }
        }
コード例 #10
0
ファイル: ChartUtils.cs プロジェクト: danejur/AniDroid
 public override string GetBarLabel(BarEntry barEntry)
 {
     return(barEntry.GetY().ToString("#"));
 }
コード例 #11
0
ファイル: ChartUtils.cs プロジェクト: danejur/AniDroid
 public override string GetBarLabel(BarEntry barEntry)
 {
     return(barEntry.GetY().KiloFormat());
 }
コード例 #12
0
        private async void BarView1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count == 0 || Bar1 == null || Bar2 == null || barComparer == null)
            {
                return;
            }


            //   e.Handled = true;
            try
            {
                ImageViewer1.Visibility = Visibility.Collapsed;
                ImageViewer2.Visibility = Visibility.Collapsed;
                XMLViewer1.Visibility   = Visibility.Collapsed;
                XMLViewer1.Text         = "";

                XMLViewer2.Visibility = Visibility.Collapsed;
                XMLViewer2.Text       = "";

                BarComparerEntry entry = (BarComparerView.SelectedItem as BarComparerEntry);
                if (entry == null)
                {
                    return;
                }

                BarEntry entryOld = entry.entryOld;
                BarEntry entryNew = entry.entryNew;

                await Bar1.readFile(entryOld);

                await Bar2.readFile(entryNew);


                if (Bar1.Preview != null && Bar2.Preview != null)
                {
                    try
                    {
                        IEnumerable <string> Old = new List <string>();
                        IEnumerable <string> New = new List <string>();
                        await Task.Run(() =>
                        {
                            var diff = SideBySideDiffBuilder.Diff(Bar1.Preview.Text, Bar2.Preview.Text);


                            Old = diff.OldText.Lines.Select(x =>
                            {
                                if (x.Type == ChangeType.Inserted || x.SubPieces.Any(x => x.Type == ChangeType.Inserted))
                                {
                                    return("!+ " + x.Text);
                                }
                                if (x.Type == ChangeType.Deleted || x.SubPieces.Any(x => x.Type == ChangeType.Deleted))
                                {
                                    return("!- " + x.Text);
                                }
                                return("   " + x.Text);
                            }
                                                            );

                            New = diff.NewText.Lines.Select(x =>
                            {
                                if (x.Type == ChangeType.Inserted || x.SubPieces.Any(x => x.Type == ChangeType.Inserted))
                                {
                                    return("!+ " + x.Text);
                                }
                                if (x.Type == ChangeType.Deleted || x.SubPieces.Any(x => x.Type == ChangeType.Deleted))
                                {
                                    return("!- " + x.Text);
                                }
                                return("   " + x.Text);
                            });
                        });

                        XMLViewer1.Text = string.Join("\n", Old);
                        XMLViewer2.Text = string.Join("\n", New);
                    }
                    catch { }
                }

                if (entryNew == null)
                {
                    if (Bar1.Preview != null)
                    {
                        XMLViewer1.Text = Bar1.Preview.Text;
                    }
                }


                if (entryOld == null)
                {
                    if (Bar2.Preview != null)
                    {
                        XMLViewer2.Text = Bar2.Preview.Text;
                    }
                }
                if (entryOld != null)
                {
                    if (entryOld.Extension == ".DDT")
                    {
                        ImagePreview1.Source    = Bar1.PreviewDdt.Bitmap;
                        XMLViewer1.Visibility   = Visibility.Collapsed;
                        ImageViewer1.Visibility = Visibility.Visible;
                    }
                    else
                    if (entryOld.Extension == ".BMP" || entryOld.Extension == ".PNG" || entryOld.Extension == ".CUR" || entryOld.Extension == ".JPG")
                    {
                        ImagePreview1.Source    = Bar1.PreviewImage;
                        XMLViewer1.Visibility   = Visibility.Collapsed;
                        ImageViewer1.Visibility = Visibility.Visible;
                    }
                    else
                    if (entryOld.Extension == ".XMB" || entryOld.Extension == ".XML" || entryOld.Extension == ".SHP" || entryOld.Extension == ".LGT" || entryOld.Extension == ".XS" || entryOld.Extension == ".TXT" || entryOld.Extension == ".CFG" || entryOld.Extension == ".XAML" || entryNew.Extension == ".PY")
                    {
                        ImageViewer1.Visibility = Visibility.Collapsed;
                        XMLViewer1.Visibility   = Visibility.Visible;
                    }
                    else
                    {
                        ImageViewer1.Visibility = Visibility.Collapsed;
                        XMLViewer1.Visibility   = Visibility.Collapsed;
                    }
                }

                if (entryNew != null)
                {
                    if (entryNew.Extension == ".DDT")
                    {
                        ImagePreview2.Source    = Bar2.PreviewDdt.Bitmap;
                        XMLViewer2.Visibility   = Visibility.Collapsed;
                        ImageViewer2.Visibility = Visibility.Visible;
                    }
                    else
                    if (entryNew.Extension == ".BMP" || entryNew.Extension == ".PNG" || entryNew.Extension == ".CUR" || entryNew.Extension == ".JPG")
                    {
                        ImagePreview2.Source    = Bar2.PreviewImage;
                        XMLViewer2.Visibility   = Visibility.Collapsed;
                        ImageViewer2.Visibility = Visibility.Visible;
                    }
                    else
                    if (entryNew.Extension == ".XMB" || entryNew.Extension == ".XML" || entryNew.Extension == ".SHP" || entryNew.Extension == ".LGT" || entryNew.Extension == ".XS" || entryNew.Extension == ".TXT" || entryNew.Extension == ".CFG" || entryNew.Extension == ".XAML" || entryNew.Extension == ".PY")
                    {
                        ImageViewer2.Visibility = Visibility.Collapsed;
                        XMLViewer2.Visibility   = Visibility.Visible;
                    }
                    else
                    {
                        ImageViewer2.Visibility = Visibility.Collapsed;
                        XMLViewer2.Visibility   = Visibility.Collapsed;
                    }
                }
            }
            catch (Exception ex)
            {
                // MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
コード例 #13
0
        /// <summary>
        /// The passed outputRect will be assigned the values of the bounding box of the specified Entry in the specified DataSet.
        /// The rect will be assigned Float.MIN_VALUE in all locations if the Entry could not be found in the charts data.
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
#if __ANDROID__ && !SKIASHARP
        public virtual void GetBarBounds(BarEntry e, Rect outputRect)
コード例 #14
0
        public async Task readFile(BarEntry file)
        {
            // Firstly, is the file parameter null?

            PreviewDdt   = null;
            Preview      = null;
            PreviewImage = null;
            if (file == null)
            {
                return;
            }

            if (file.Extension == ".WAV" /* || file.Extension == ".MP3"*/)
            {
                using FileStream input = File.OpenRead(barFilePath);
                // Locate the file within the BAR file.
                input.Seek(file.Offset, SeekOrigin.Begin);
                var data = new byte[file.FileSize2];
                await input.ReadAsync(data, 0, data.Length);

                //File.WriteAllBytes(file.fileNameWithoutPath, data);
                audio = new MemoryStream(data);
                if (file.isCompressed)
                {
                    //   AudioFileReader audioFileReader = new AudioFileReader();
                    //  DirectSoundOut directSoundOut = new DirectSoundOut();

                    // audioFileReader.
                    audio = new MemoryStream(data);
                }
                else
                {
                    audio = new MemoryStream(data);
                }

                return;
            }
            if (file.Extension == ".DDT")
            {
                using FileStream input = File.OpenRead(barFilePath);
                // Locate the file within the BAR file.
                input.Seek(file.Offset, SeekOrigin.Begin);
                var data = new byte[file.FileSize2];
                await input.ReadAsync(data, 0, data.Length);


                if (Alz4Utils.IsAlz4File(data))
                {
                    data = await Alz4Utils.ExtractAlz4BytesAsync(data);
                }
                else
                {
                    if (L33TZipUtils.IsL33TZipFile(data))
                    {
                        data = await L33TZipUtils.ExtractL33TZippedBytesAsync(data);
                    }
                }

                PreviewDdt = new DdtFile(data, true);
                return;
            }
            if (file.Extension == ".BMP" || file.Extension == ".PNG" || file.Extension == ".CUR" || file.Extension == ".JPG")
            {
                using FileStream input = File.OpenRead(barFilePath);
                // Locate the file within the BAR file.
                input.Seek(file.Offset, SeekOrigin.Begin);
                var data = new byte[file.FileSize2];
                await input.ReadAsync(data, 0, data.Length);

                if (Alz4Utils.IsAlz4File(data))
                {
                    data = await Alz4Utils.ExtractAlz4BytesAsync(data);
                }
                else
                {
                    if (L33TZipUtils.IsL33TZipFile(data))
                    {
                        data = await L33TZipUtils.ExtractL33TZippedBytesAsync(data);
                    }
                }
                var bitmap = new BitmapImage();
                using (var stream = new MemoryStream(data))
                {
                    bitmap.BeginInit();
                    bitmap.StreamSource = stream;
                    bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                    bitmap.EndInit();
                    bitmap.Freeze();
                }

                PreviewImage = bitmap;
                return;
            }

            if (file.Extension == ".XMB")
            {
                using FileStream input = File.OpenRead(barFilePath);
                // Locate the file within the BAR file.
                input.Seek(file.Offset, SeekOrigin.Begin);
                var data = new byte[file.FileSize2];
                await input.ReadAsync(data, 0, data.Length);

                if (Alz4Utils.IsAlz4File(data))
                {
                    data = await Alz4Utils.ExtractAlz4BytesAsync(data);
                }
                else
                {
                    if (L33TZipUtils.IsL33TZipFile(data))
                    {
                        data = await L33TZipUtils.ExtractL33TZippedBytesAsync(data);
                    }
                }

                //File.WriteAllBytes(file.fileNameWithoutPath, data);

                Preview = new Document();
                Preview.SyntaxHighlighting = "XML";
                Preview.Text = await XMBFile.XmbToXmlAsync(data);

                NotifyPropertyChanged("Preview");
                return;
            }
            if (file.Extension == ".XAML" || file.Extension == ".XML" || file.Extension == ".SHP" || file.Extension == ".LGT" || file.Extension == ".XS" || file.Extension == ".TXT" || file.Extension == ".CFG" || file.Extension == ".PY")
            {
                using FileStream input = File.OpenRead(barFilePath);
                // Locate the file within the BAR file.
                input.Seek(file.Offset, SeekOrigin.Begin);
                var data = new byte[file.FileSize2];
                await input.ReadAsync(data, 0, data.Length);

                if (Alz4Utils.IsAlz4File(data))
                {
                    data = await Alz4Utils.ExtractAlz4BytesAsync(data);
                }
                else
                {
                    if (L33TZipUtils.IsL33TZipFile(data))
                    {
                        data = await L33TZipUtils.ExtractL33TZippedBytesAsync(data);
                    }
                }
                Preview      = new Document();
                Preview.Text = System.Text.Encoding.UTF8.GetString(data);
                if (file.Extension == ".XS")
                {
                    Preview.SyntaxHighlighting = "C++";
                }
                else
                {
                    Preview.SyntaxHighlighting = "XML";
                }
                NotifyPropertyChanged("Preview");
                return;
            }

            return;
        }
コード例 #15
0
        public async Task readFile(BarEntry file)
        {
            // Firstly, is the file parameter null?

            PreviewDdt   = null;
            Preview      = null;
            PreviewImage = null;
            if (file == null)
            {
                return;
            }

            if (file.Extension == ".WAV" || file.Extension == ".MP3")
            {
                using FileStream input = File.OpenRead(barFilePath);
                // Locate the file within the BAR file.
                input.Seek(file.Offset, SeekOrigin.Begin);
                var data = new byte[file.FileSize2];
                await input.ReadAsync(data, 0, data.Length);

                if (file.isCompressed == 2)
                {
                    audio = new MemoryStream(await soundUtils.DecryptSound(data));
                }
                else
                {
                    audio = new MemoryStream(data);
                }
                return;
            }
            if (file.Extension == ".DDT")
            {
                using FileStream input = File.OpenRead(barFilePath);
                // Locate the file within the BAR file.
                input.Seek(file.Offset, SeekOrigin.Begin);
                var data = new byte[file.FileSize2];
                await input.ReadAsync(data, 0, data.Length);


                if (Alz4Utils.IsAlz4File(data))
                {
                    data = await Alz4Utils.ExtractAlz4BytesAsync(data);
                }
                else
                {
                    if (L33TZipUtils.IsL33TZipFile(data))
                    {
                        data = await L33TZipUtils.ExtractL33TZippedBytesAsync(data);
                    }
                }



                PreviewDdt = new DdtFile(data, true);
                return;
            }
            if (file.Extension == ".BMP" || file.Extension == ".TGA" || file.Extension == ".PNG" || file.Extension == ".CUR" || file.Extension == ".JPG")
            {
                using FileStream input = File.OpenRead(barFilePath);
                // Locate the file within the BAR file.
                input.Seek(file.Offset, SeekOrigin.Begin);
                var data = new byte[file.FileSize2];
                await input.ReadAsync(data, 0, data.Length);

                if (Alz4Utils.IsAlz4File(data))
                {
                    data = await Alz4Utils.ExtractAlz4BytesAsync(data);
                }
                else
                {
                    if (L33TZipUtils.IsL33TZipFile(data))
                    {
                        data = await L33TZipUtils.ExtractL33TZippedBytesAsync(data);
                    }
                }
                var bitmap = new BitmapImage();

                using (var stream = new MemoryStream(data))
                {
                    if (file.Extension == ".TGA")
                    {
                        IImage image = await Task.Run(() => Pfim.Pfim.FromStream(stream));

                        var pinnedArray = GCHandle.Alloc(image.Data, GCHandleType.Pinned);
                        var addr        = pinnedArray.AddrOfPinnedObject();
                        var bsource     = BitmapSource.Create(image.Width, image.Height, 96.0, 96.0,
                                                              PixelFormat(image), null, addr, image.DataLen, image.Stride);
                        PngBitmapEncoder encoder      = new PngBitmapEncoder();
                        MemoryStream     memoryStream = new MemoryStream();

                        encoder.Frames.Add(BitmapFrame.Create(bsource));
                        encoder.Save(memoryStream);
                        memoryStream.Position = 0;
                        bitmap.BeginInit();
                        bitmap.StreamSource = memoryStream;
                        bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                        bitmap.EndInit();
                        bitmap.Freeze();
                        memoryStream.Close();
                    }

                    /*else if (file.Extension == ".PNG")
                     * {
                     *  System.Drawing.Image image = System.Drawing.Image.FromStream(stream);
                     *  using var memory = new MemoryStream();
                     *  image.Save(memory, System.Drawing.Imaging.ImageFormat.Bmp);
                     *  memory.Seek(0, SeekOrigin.Begin);
                     *  bitmap.BeginInit();
                     *  bitmap.CacheOption = BitmapCacheOption.OnLoad;
                     *  bitmap.StreamSource = memory;
                     *  bitmap.EndInit();
                     * }*/
                    else
                    {
                        bitmap.BeginInit();
                        bitmap.StreamSource = stream;
                        bitmap.CacheOption  = BitmapCacheOption.OnLoad;
                        bitmap.EndInit();
                        bitmap.Freeze();
                    }
                }


                PreviewImage = bitmap;
                return;
            }

            if (file.Extension == ".XMB")
            {
                using FileStream input = File.OpenRead(barFilePath);
                // Locate the file within the BAR file.
                input.Seek(file.Offset, SeekOrigin.Begin);
                var data = new byte[file.FileSize2];
                await input.ReadAsync(data, 0, data.Length);

                if (Alz4Utils.IsAlz4File(data))
                {
                    data = await Alz4Utils.ExtractAlz4BytesAsync(data);
                }
                else
                {
                    if (L33TZipUtils.IsL33TZipFile(data))
                    {
                        data = await L33TZipUtils.ExtractL33TZippedBytesAsync(data);
                    }
                }

                //File.WriteAllBytes(file.fileNameWithoutPath, data);

                Preview = new Document();
                Preview.SyntaxHighlighting = "XML";
                Preview.Text = await XMBFile.XmbToXmlAsync(data);

                NotifyPropertyChanged("Preview");
                return;
            }
            if (file.Extension == ".XAML" || file.Extension == ".XML" || file.Extension == ".SHP" || file.Extension == ".LGT" || file.Extension == ".XS" || file.Extension == ".TXT" || file.Extension == ".CFG" || file.Extension == ".PY" || file.Extension == ".TACTICS")
            {
                using FileStream input = File.OpenRead(barFilePath);
                // Locate the file within the BAR file.
                input.Seek(file.Offset, SeekOrigin.Begin);
                var data = new byte[file.FileSize2];
                await input.ReadAsync(data, 0, data.Length);

                if (Alz4Utils.IsAlz4File(data))
                {
                    data = await Alz4Utils.ExtractAlz4BytesAsync(data);
                }
                else
                {
                    if (L33TZipUtils.IsL33TZipFile(data))
                    {
                        data = await L33TZipUtils.ExtractL33TZippedBytesAsync(data);
                    }
                }
                Preview      = new Document();
                Preview.Text = System.Text.Encoding.UTF8.GetString(data);
                if (file.Extension == ".XS")
                {
                    Preview.SyntaxHighlighting = "C++";
                }
                else
                {
                    Preview.SyntaxHighlighting = "XML";
                }
                NotifyPropertyChanged("Preview");
                return;
            }

            return;
        }
コード例 #16
0
ファイル: BarBuilder.cs プロジェクト: Xtremrules/dot42
        /// <summary>
        /// Collect all icons
        /// </summary>
        private static void CollectIcons(ApkFile apk, List<BarEntry> entries, Dictionary<string, string> apkPath2barPath)
        {
#if DEBUG
            Debugger.Launch();
#endif

            var iconNames = apk.Manifest.Activities.Select(x => x.Icon).Where(x => !string.IsNullOrEmpty(x)).ToList();
            var appIcon = apk.Manifest.ApplicationIcon;
            if (!string.IsNullOrEmpty(appIcon))
                iconNames.Add(appIcon);

            foreach (var name in iconNames)
            {
                if (apkPath2barPath.ContainsKey(name))
                    continue;
                int nameAsInt;
                if (!int.TryParse(name, out nameAsInt))
                    continue;
                var resId = apk.Resources.GetResourceIdentifier(nameAsInt);
                var iconData = IconBuilder.GetIcon(resId, apk);
                if (iconData != null)
                {
                    var barPath = "android/res/drawable/" + resId + ".png";
                    var entry = new BarEntry(barPath, new MemoryStream(iconData));
                    entries.Add(entry);
                    apkPath2barPath[name] = barPath;
                }
            }
        }