2020-06-24 00:21:18 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright 2020 faddenSoft
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using System.Windows;
|
2020-06-26 23:58:42 +00:00
|
|
|
|
using System.Windows.Controls;
|
2020-06-24 00:21:18 +00:00
|
|
|
|
using System.Windows.Input;
|
|
|
|
|
|
2020-06-26 23:58:42 +00:00
|
|
|
|
using Asm65;
|
|
|
|
|
|
2020-06-24 00:21:18 +00:00
|
|
|
|
namespace SourceGen.Tools.Omf.WpfGui {
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Apple IIgs OMF file viewer.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class OmfViewer : Window, INotifyPropertyChanged {
|
2020-06-26 23:58:42 +00:00
|
|
|
|
private OmfFile mOmfFile;
|
|
|
|
|
private Formatter mFormatter;
|
2020-06-24 00:21:18 +00:00
|
|
|
|
|
|
|
|
|
//private Brush mDefaultLabelColor = SystemColors.WindowTextBrush;
|
|
|
|
|
|
|
|
|
|
// INotifyPropertyChanged implementation
|
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
|
private void OnPropertyChanged([CallerMemberName] string propertyName = "") {
|
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class SegmentListItem {
|
2020-06-26 23:58:42 +00:00
|
|
|
|
public OmfSegment OmfSeg { get; private set; }
|
2020-06-24 00:21:18 +00:00
|
|
|
|
|
2020-06-26 00:30:44 +00:00
|
|
|
|
public int SegNum {
|
2020-06-26 23:58:42 +00:00
|
|
|
|
get { return OmfSeg.SegNum; }
|
|
|
|
|
}
|
|
|
|
|
public string Version {
|
|
|
|
|
get { return OmfSegment.VersionToString(OmfSeg.Version); }
|
2020-06-26 00:30:44 +00:00
|
|
|
|
}
|
|
|
|
|
public string Kind {
|
2020-06-26 23:58:42 +00:00
|
|
|
|
get { return OmfSegment.KindToString(OmfSeg.Kind); }
|
2020-06-26 00:30:44 +00:00
|
|
|
|
}
|
|
|
|
|
public string LoadName {
|
2020-06-26 23:58:42 +00:00
|
|
|
|
get { return OmfSeg.LoadName; }
|
2020-06-26 00:30:44 +00:00
|
|
|
|
}
|
|
|
|
|
public string SegName {
|
2020-06-26 23:58:42 +00:00
|
|
|
|
get { return OmfSeg.SegName; }
|
2020-06-26 00:30:44 +00:00
|
|
|
|
}
|
2020-06-26 23:58:42 +00:00
|
|
|
|
public int Length {
|
|
|
|
|
get { return OmfSeg.Length; }
|
2020-06-26 00:30:44 +00:00
|
|
|
|
}
|
|
|
|
|
public int FileLength {
|
2020-06-29 03:50:41 +00:00
|
|
|
|
get { return OmfSeg.RawFileLength; }
|
2020-06-26 00:30:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public SegmentListItem(OmfSegment omfSeg) {
|
2020-06-26 23:58:42 +00:00
|
|
|
|
OmfSeg = omfSeg;
|
|
|
|
|
}
|
|
|
|
|
public override string ToString() {
|
|
|
|
|
return "[SegmentListItem " + OmfSeg + "]";
|
2020-06-24 00:21:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<SegmentListItem> SegmentListItems { get; private set; } = new List<SegmentListItem>();
|
|
|
|
|
|
2020-06-26 23:58:42 +00:00
|
|
|
|
private string mPathName;
|
|
|
|
|
public string PathName {
|
|
|
|
|
get { return mPathName; }
|
|
|
|
|
set { mPathName = value; OnPropertyChanged(); }
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-28 18:56:51 +00:00
|
|
|
|
private string mFileSummaryStr;
|
|
|
|
|
public string FileSummaryStr {
|
|
|
|
|
get { return mFileSummaryStr; }
|
|
|
|
|
set { mFileSummaryStr = value; OnPropertyChanged(); }
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 23:58:42 +00:00
|
|
|
|
private string mMessageStrings;
|
|
|
|
|
public string MessageStrings {
|
|
|
|
|
get { return mMessageStrings; }
|
|
|
|
|
set { mMessageStrings = value; OnPropertyChanged(); }
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-24 00:21:18 +00:00
|
|
|
|
|
2020-06-26 23:58:42 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Constructor.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="owner">Parent window.</param>
|
|
|
|
|
/// <param name="pathName">Path to file on disk. Only used for display.</param>
|
|
|
|
|
/// <param name="data">File contents.</param>
|
2020-06-29 03:50:41 +00:00
|
|
|
|
/// <param name="formatter">Text formatter.</param>
|
2020-06-26 23:58:42 +00:00
|
|
|
|
public OmfViewer(Window owner, string pathName, byte[] data, Formatter formatter) {
|
2020-06-24 00:21:18 +00:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
Owner = owner;
|
|
|
|
|
DataContext = this;
|
|
|
|
|
|
2020-06-26 23:58:42 +00:00
|
|
|
|
PathName = pathName;
|
|
|
|
|
mFormatter = formatter;
|
2020-06-24 00:21:18 +00:00
|
|
|
|
|
2020-06-26 23:58:42 +00:00
|
|
|
|
mOmfFile = new OmfFile(data);
|
2020-06-28 01:06:26 +00:00
|
|
|
|
mOmfFile.Analyze(mFormatter);
|
2020-06-26 00:30:44 +00:00
|
|
|
|
|
2020-06-28 18:56:51 +00:00
|
|
|
|
string summary;
|
|
|
|
|
if (mOmfFile.OmfFileKind == OmfFile.FileKind.Foreign) {
|
|
|
|
|
summary = (string)FindResource("str_OmfFileNot");
|
|
|
|
|
} else {
|
|
|
|
|
string fileStr;
|
|
|
|
|
switch (mOmfFile.OmfFileKind) {
|
|
|
|
|
case OmfFile.FileKind.Indeterminate:
|
|
|
|
|
fileStr = (string)FindResource("str_OmfFileIndeterminateStr");
|
|
|
|
|
break;
|
|
|
|
|
case OmfFile.FileKind.Load:
|
|
|
|
|
fileStr = (string)FindResource("str_OmfFileLoadStr");
|
|
|
|
|
break;
|
|
|
|
|
case OmfFile.FileKind.Object:
|
|
|
|
|
fileStr = (string)FindResource("str_OmfFileObjectStr");
|
|
|
|
|
break;
|
|
|
|
|
case OmfFile.FileKind.Library:
|
|
|
|
|
fileStr = (string)FindResource("str_OmfFileLibraryStr");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
fileStr = (string)FindResource("str_OmfFileUnknownStr");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string fmt;
|
|
|
|
|
if (mOmfFile.SegmentList.Count == 1) {
|
|
|
|
|
fmt = (string)FindResource("str_OmfFileSummaryFmt");
|
|
|
|
|
} else {
|
|
|
|
|
fmt = (string)FindResource("str_OmfFileSummaryPlFmt");
|
|
|
|
|
}
|
|
|
|
|
summary = string.Format(fmt, fileStr, mOmfFile.SegmentList.Count);
|
|
|
|
|
}
|
|
|
|
|
FileSummaryStr = summary;
|
|
|
|
|
|
2020-06-26 23:58:42 +00:00
|
|
|
|
foreach (OmfSegment omfSeg in mOmfFile.SegmentList) {
|
2020-06-26 00:30:44 +00:00
|
|
|
|
SegmentListItems.Add(new SegmentListItem(omfSeg));
|
|
|
|
|
}
|
2020-06-26 23:58:42 +00:00
|
|
|
|
MessageStrings = string.Join("\r\n", mOmfFile.MessageList.ToArray());
|
2020-06-24 00:21:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SegmentList_MouseDoubleClick(object sender, MouseButtonEventArgs e) {
|
2020-06-26 23:58:42 +00:00
|
|
|
|
SegmentListItem item = (SegmentListItem)((DataGrid)sender).SelectedItem;
|
|
|
|
|
OmfSegmentViewer dlg = new OmfSegmentViewer(this, mOmfFile, item.OmfSeg, mFormatter);
|
|
|
|
|
dlg.ShowDialog();
|
2020-06-24 00:21:18 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|