Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// Licensed under the MIT License.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Controls.Primitives;
using System.Diagnostics;
Expand Down Expand Up @@ -48,6 +49,7 @@
using Xamarin.PropertyEditing.Windows;

using XIR = Xamarin.Interactive.Remote;
using System.Linq;

namespace Xamarin.Interactive.Client.Windows
{
Expand Down Expand Up @@ -134,34 +136,41 @@ bool Save (SaveOperation operation)

CommonFileDialogComboBox formatComboBox = null;

if (saveOperation.SupportedOptions.HasFlag (WorkbookSaveOptions.Archive)) {
formatComboBox = new CommonFileDialogComboBox ();
var formatComboBoxLookup = new Dictionary<int, WorkbookSaveOptions> ();
var formatComboBoxReverseLookup = new Dictionary<WorkbookSaveOptions, int> ();

formatComboBox = new CommonFileDialogComboBox ();
if (saveOperation.SupportsSingleFileOption) {
formatComboBoxLookup [formatComboBox.Items.Count] = WorkbookSaveOptions.SingleWorkbookFile;
formatComboBoxReverseLookup [WorkbookSaveOptions.SingleWorkbookFile] = formatComboBox.Items.Count;
formatComboBox.Items.Add (new CommonFileDialogComboBoxItem (
Catalog.GetString ("Workbook File")));
}

if (saveOperation.SupportsMultiFileOptions) {
formatComboBoxLookup [formatComboBox.Items.Count] = WorkbookSaveOptions.PackageDirectory;
formatComboBoxReverseLookup [WorkbookSaveOptions.PackageDirectory] = formatComboBox.Items.Count;
formatComboBox.Items.Add (new CommonFileDialogComboBoxItem (
Catalog.GetString ("Package Directory")));
formatComboBoxLookup [formatComboBox.Items.Count] = WorkbookSaveOptions.Archive;
formatComboBoxReverseLookup [WorkbookSaveOptions.Archive] = formatComboBox.Items.Count;
formatComboBox.Items.Add (new CommonFileDialogComboBoxItem (
Catalog.GetString ("Archive")));
formatComboBox.SelectedIndex = saveOperation.Options.HasFlag (
WorkbookSaveOptions.Archive) ? 1 : 0;

var formatGroup = new CommonFileDialogGroupBox ("Workbook Format:");
formatGroup.Items.Add (formatComboBox);
saveDialog.Controls.Add (formatGroup);
}

formatComboBox.SelectedIndex = formatComboBoxReverseLookup [saveOperation.SaveOption];

var formatGroup = new CommonFileDialogGroupBox ("Workbook Format:");
formatGroup.Items.Add (formatComboBox);
saveDialog.Controls.Add (formatGroup);

if (saveDialog.ShowDialog (this) != CommonFileDialogResult.Ok)
return false;

if (formatComboBox != null)
switch (formatComboBox.SelectedIndex) {
case 0:
saveOperation.Options &= ~WorkbookSaveOptions.Archive;
break;
case 1:
saveOperation.Options |= WorkbookSaveOptions.Archive;
break;
default:
throw new IndexOutOfRangeException ();
}
// TODO - we could put up some kind of warning for InvolesMultipleFiles
// but saving as single workbook?

saveOperation.SaveOption = formatComboBoxLookup [formatComboBox.SelectedIndex];

savePath = saveDialog.FileName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@
<PackageReference Include="MouseKeyboardActivityMonitor">
<Version>4.0.5150.10665</Version>
</PackageReference>
<PackageReference Include="WindowsAPICodePack-Core">
<Version>1.1.2</Version>
</PackageReference>
<PackageReference Include="WindowsAPICodePack-Shell">
<Version>1.1.1</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Page Include="App.xaml">
Expand Down Expand Up @@ -264,14 +270,6 @@
<Project>{0fd4b1dd-45a8-4f02-beb0-5881cd512573}</Project>
<Name>CommonMark.Base</Name>
</ProjectReference>
<ProjectReference Include="..\..\External\WindowsAPICodePack\Core\Core.csproj">
<Project>{2e1fb0df-f9bb-4909-9f32-2d9d022a8e57}</Project>
<Name>Core</Name>
</ProjectReference>
<ProjectReference Include="..\..\External\WindowsAPICodePack\Shell\Shell.csproj">
<Project>{aa0c00cb-8699-4f37-bfae-40ca87acc06d}</Project>
<Name>Shell</Name>
</ProjectReference>
<ProjectReference Include="..\..\External\Xamarin.PropertyEditing\Xamarin.PropertyEditing.Windows\Xamarin.PropertyEditing.Windows.csproj">
<Project>{60af04be-1b6b-411b-bcba-c95eafbd7ac0}</Project>
<Name>Xamarin.PropertyEditing.Windows</Name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ namespace Xamarin.Interactive.Workbook.LoadAndSave
{
interface IWorkbookSaveOperation
{
WorkbookSaveOptions SupportedOptions { get; }
WorkbookSaveOptions Options { get; set; }
bool SupportsMultiFileOptions { get; }
bool SupportsSingleFileOption { get; }
bool InvolesMultipleFiles { get; }
WorkbookSaveOptions SaveOption { get; set; }
FilePath Destination { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@

namespace Xamarin.Interactive.Workbook.LoadAndSave
{
[Flags]
enum WorkbookSaveOptions
{
None = 0,
Archive = 1 << 0,
Sign = 1 << 1
SingleWorkbookFile = 0,
Archive = 1,
PackageDirectory = 2
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public async Task Open (
if (quarantineInfoHandler == null)
throw new ArgumentNullException (nameof (quarantineInfoHandler));

SaveOptions = WorkbookSaveOptions.None;
SaveOptions = WorkbookSaveOptions.SingleWorkbookFile;
LogicalPath = openPath;

QuarantineInfo quarantineInfo = null;
Expand Down Expand Up @@ -300,7 +300,7 @@ void Open (FilePath openPath, bool isDirectory, params AgentType [] platformTarg
if (isDirectory) {
indexPage.Path = indexPageFileName;
readPath = openPath.Combine (indexPage.Path);
openedFromDirectory = true;
SaveOptions = WorkbookSaveOptions.PackageDirectory;
} else {
// If we are opening a file within a .workbook directory somewhere,
// actually open that directory. This is to mostly address issues
Expand All @@ -323,6 +323,7 @@ void Open (FilePath openPath, bool isDirectory, params AgentType [] platformTarg

indexPage.Path = openPath.Name;
readPath = openPath;
SaveOptions = WorkbookSaveOptions.SingleWorkbookFile;
}

using (var stream = new FileStream (
Expand Down Expand Up @@ -361,7 +362,7 @@ void OpenZip (FileStream stream, AgentType [] platformTargets)

Open (extractPath, true, platformTargets);

SaveOptions |= WorkbookSaveOptions.Archive;
SaveOptions = WorkbookSaveOptions.Archive;
}

FilePath GetTempZipArchivePath ()
Expand All @@ -377,16 +378,28 @@ sealed class SaveOperation : IWorkbookSaveOperation
public WorkbookPage OnlyPage;
public bool OnlyPageHasDependencies;

public WorkbookSaveOptions SupportedOptions {
public bool InvolesMultipleFiles {
get {
if (OnlyPage == null || OnlyPageHasDependencies)
return WorkbookSaveOptions.Archive;
return (OnlyPage == null || OnlyPageHasDependencies);
}
}

public bool SupportsMultiFileOptions {
get {
// actually it seems, we always can have multifile options...
return true;
}
}

return WorkbookSaveOptions.None;
public bool SupportsSingleFileOption {
get {
// actually it seems, we always can have singlefile options...
// - or do I misunderstand what "OnlyPage == null" means...
return true;
}
}

public WorkbookSaveOptions Options { get; set; }
public WorkbookSaveOptions SaveOption { get; set; }
public FilePath Destination { get; set; }
}

Expand All @@ -400,7 +413,7 @@ public IWorkbookSaveOperation CreateSaveOperation ()
AllDependencies = dependencies,
OnlyPage = onlyPage.Key,
OnlyPageHasDependencies = onlyPage.Key != null && onlyPage.Value.Count > 0,
Options = SaveOptions
SaveOption = SaveOptions
};
}

Expand All @@ -411,19 +424,13 @@ public void Save (IWorkbookSaveOperation operation)
throw new ArgumentNullException (nameof (operation));

LogicalPath = operation.Destination;
SaveOptions = WorkbookSaveOptions.None;
SaveOptions = operation.SaveOption;

if (IndexPage != null && IndexPage.IsUntitled)
if (IndexPage != null)
IndexPage.Title = LogicalPath.NameWithoutExtension;

if (saveOperation.OnlyPage != null &&
!saveOperation.OnlyPageHasDependencies &&
!openedFromDirectory) {
// The workbook package has only a single page with no relative
// dependencies. If the original path was a workbook directory,
// keep that format. If we originally opened from a workbook
// directory and our target save path is not a directory, keep
// that format. Otherwise, save the page as a single file.
if (saveOperation.SaveOption == WorkbookSaveOptions.SingleWorkbookFile) {
// This is a simple save... so we ignore dependencies
var writePath = logicalPath.DirectoryExists
? logicalPath.Combine (saveOperation.OnlyPage.Path)
: logicalPath;
Expand Down Expand Up @@ -471,12 +478,12 @@ public void Save (IWorkbookSaveOperation operation)
}
}

if (saveOperation.Options.HasFlag (WorkbookSaveOptions.Archive))
if (saveOperation.SaveOption == WorkbookSaveOptions.Archive)
ArchiveDirectory (logicalPath);

// For overwrite saves of archives, WorkingPath should continue
// to point to the extracted directory in temp
if (!saveOperation.Options.HasFlag (WorkbookSaveOptions.Archive) ||
if ((saveOperation.SaveOption != WorkbookSaveOptions.Archive) ||
WorkingPath == null ||
!WorkingPath.Exists)
WorkingPath = logicalPath;
Expand All @@ -499,8 +506,6 @@ void CopyDirectoryContents (FilePath sourceDirectory, FilePath destDirectory)

void ArchiveDirectory (FilePath directory)
{
SaveOptions |= WorkbookSaveOptions.Archive;

var archivePath = GetTempZipArchivePath ();

using (var stream = new FileStream (
Expand Down
17 changes: 9 additions & 8 deletions Package/Windows/AgentAppFiles.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -300,17 +300,18 @@
<Component Id="WpfAgentApp.System.Xml.XPath.XDocument.dll" Guid="54907165-7367-4BFB-AF25-88BBFE04AE0E">
<File Id="WpfAgentApp.System.Xml.XPath.XDocument.dll" Source="$(var.WpfAgentAppDirectory)\System.Xml.XPath.XDocument.dll" />
</Component>
<Component Id="WpfAgentApp.Microsoft.WindowsAPICodePack.dll" Guid="DC2BA773-3248-4AF3-ACE8-F9EB248A1A09">
<File Id="WpfAgentApp.Microsoft.WindowsAPICodePack.dll" Source="$(var.WpfAgentAppDirectory)\Microsoft.WindowsAPICodePack.dll" />
</Component>
</ComponentGroup>

<?ifdef AndroidSupport ?>
<?define AndroidAgentAppDirectory="..\..\_build\$(var.Configuration)\WorkbookApps\Android" ?>
<ComponentGroup Id="AndroidAgentAppComponents" Directory="AndroidAgentAppInstallFolder">
<Component Id="AndroidAgentApp.apk" Guid="6CD2D3A9-40D7-4583-BDD1-5B4711431381">
<File Id="AndroidAgentApp.apk" Source="$(var.AndroidAgentAppDirectory)\com.xamarin.workbook_app_android-Signed.apk" />
</Component>
</ComponentGroup>
<?define AndroidAgentAppDirectory="..\..\_build\$(var.Configuration)\WorkbookApps\Android" ?>
<ComponentGroup Id="AndroidAgentAppComponents" Directory="AndroidAgentAppInstallFolder">
<Component Id="AndroidAgentApp.apk" Guid="6CD2D3A9-40D7-4583-BDD1-5B4711431381">
<File Id="AndroidAgentApp.apk" Source="$(var.AndroidAgentAppDirectory)\com.xamarin.workbook_app_android-Signed.apk" />
</Component>
</ComponentGroup>
<?endif?>

<ComponentGroup Id="WorkbookManifestComponents" Directory="AgentAppInstallFolder">
<Component Id="workbookapps.json" Guid="47A8314B-0E4A-48BD-AA24-84A18AE06291">
<File Id="workbookapps.json" Source="..\..\_build\$(var.Configuration)\WorkbookApps\workbookapps.json" />
Expand Down
6 changes: 6 additions & 0 deletions Package/Windows/DotNetCoreAgentAppFiles-win-x86.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,12 @@
<Component Id="DNCAgentAppwinx86.System.Memory.dll" Guid="FDA9A09B-F94B-4509-BAB8-919511A724DF">
<File Id="DNCAgentAppwinx86.System.Memory.dll" Source="$(var.DotNetCoreAssembliesDir)\System.Memory.dll" />
</Component>
<Component Id="DNCAgentAppwinx86.mscordaccore_x86_x86_4.6.26515.07.dll" Guid="A79CC6CE-1A0A-4FCC-9EE9-B40A26274239">
<File Id="DNCAgentAppwinx86.mscordaccore_x86_x86_4.6.26515.07.dll" Source="$(var.DotNetCoreAssembliesDir)\mscordaccore_x86_x86_4.6.26515.07.dll" />
</Component>
<Component Id="DNCAgentAppwinx86.sos_x86_x86_4.6.26515.07.dll" Guid="B4810B78-BFF9-41CD-98FD-38674A4BB261">
<File Id="DNCAgentAppwinx86.sos_x86_x86_4.6.26515.07.dll" Source="$(var.DotNetCoreAssembliesDir)\sos_x86_x86_4.6.26515.07.dll" />
</Component>
</ComponentGroup>
</Fragment>
</Wix>
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@
<PackageReference Include="System.ValueTuple">
<Version>4.4.0</Version>
</PackageReference>
<PackageReference Include="WindowsAPICodePack-Core">
<Version>1.1.2</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
Expand Down Expand Up @@ -121,4 +124,4 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="Build.targets" />
</Project>
</Project>