Skip to content

Commit

Permalink
Merge pull request #16 from basharast/main
Browse files Browse the repository at this point in the history
IUTool mode and more improvements
  • Loading branch information
fadilfadz01 authored Oct 26, 2024
2 parents e91e871 + 3c19e8d commit 4c94b37
Show file tree
Hide file tree
Showing 14 changed files with 726 additions and 99 deletions.
34 changes: 33 additions & 1 deletion Universal Updater/CabExtractor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
using System;
/**************************************************************************
*
* Project Name: Universal Updater
* Description: Console based unofficial updater for Windows Phone.
*
* Author: Fadil Fadz
* Created Date: 2021
*
* Contributors: Bashar Astifan
*
* Copyright © 2021 - 2024 Fadil Fadz
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
**************************************************************************/

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down
36 changes: 33 additions & 3 deletions Universal Updater/CheckForUpdates.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
using System;
using System.Collections.Generic;
using System.Text;
/**************************************************************************
*
* Project Name: Universal Updater
* Description: Console based unofficial updater for Windows Phone.
*
* Author: Fadil Fadz
* Created Date: 2021
*
* Contributors: Bashar Astifan
*
* Copyright © 2021 - 2024 Fadil Fadz
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
**************************************************************************/

using System;

namespace Universal_Updater
{
Expand Down
51 changes: 44 additions & 7 deletions Universal Updater/DownloadPackages.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
using System;
/**************************************************************************
*
* Project Name: Universal Updater
* Description: Console based unofficial updater for Windows Phone.
*
* Author: Fadil Fadz
* Created Date: 2021
*
* Contributors: Bashar Astifan
*
* Copyright © 2021 - 2024 Fadil Fadz
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
**************************************************************************/

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Text.RegularExpressions;
Expand All @@ -16,7 +47,7 @@ namespace Universal_Updater
class DownloadPackages
{
static Tuple<DateTime, long, long> DownloadingProgress = new Tuple<DateTime, long, long>(DateTime.MinValue, 0, 0);
public static string[] installedPackages = new string[] { "Dummy" };
public static string[] installedPackages = new string[] { };
static List<string> filteredPackages = new List<string>();
static bool isFeatureInstalled = false;
static bool filterCBSPackagesOnly = false;
Expand Down Expand Up @@ -132,10 +163,11 @@ public static async Task<bool> OfflineUpdate(string[] folderFiles)
filterCBSPackagesOnly = folderHasCBS;
}



ConsoleKeyInfo packagesFilterAction = default(ConsoleKeyInfo);
if (!Program.updateRules.ForceFilterMode && !Program.updateRules.ForcePushAllMode)
// For FFU only we skip checking installedPackages length,
// because we mount FFU later which is intentionally made after all questions
var showFilterOptions = (installedPackages.Length > 0 || Program.pushToFFU);
if (!Program.updateRules.ForceFilterMode && !Program.updateRules.ForcePushAllMode && showFilterOptions)
{
// Allow user to push all package if he want
Program.WriteLine("\nFilter packages options: ", ConsoleColor.Blue);
Expand Down Expand Up @@ -202,8 +234,13 @@ public static async Task<bool> OfflineUpdate(string[] folderFiles)
Program.Write("\nPUSH MODE: ", ConsoleColor.Gray);
Program.WriteLine((PushPackages.useOldTools ? "FFU (SPKG)" : "FFU (CBS)"), (PushPackages.useOldTools ? ConsoleColor.DarkYellow : ConsoleColor.Blue));
}
else if (Program.iutoolMode)
{
Program.Write("\nPUSH MODE: ", ConsoleColor.Gray);
Program.WriteLine("IUTOOL", ConsoleColor.DarkGray);
}

if (Program.updateRules.ForceFilterMode || packagesFilterAction.KeyChar == '1')
if ((Program.updateRules.ForceFilterMode || packagesFilterAction.KeyChar == '1') && installedPackages.Length > 0)
{
Program.WriteLine($"\nFiltering packages (type: {previewType}), please wait...", ConsoleColor.DarkGray);
Program.appendLog("\n[INSTALLED PACKAGES]\n");
Expand Down
204 changes: 204 additions & 0 deletions Universal Updater/FolderPicker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
/**************************************************************************
*
* Project Name: Universal Updater
* Description: Console based unofficial updater for Windows Phone.
*
* Author: Fadil Fadz
* Created Date: 2021
*
* Contributors: Bashar Astifan
*
* Copyright © 2021 - 2024 Fadil Fadz
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
**************************************************************************/

using System;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Universal_Updater
{
public static class GeneralPicker
{
public static Task<string> ShowSaveFileDialogAsync(string fileExt)
{
var capsPreview = fileExt.ToUpper();
MessageBox.Show(
$"Please the ({capsPreview}) save location.",
$"Save {capsPreview}",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
var taskCompletionSource = new TaskCompletionSource<string>();

// start STA thread for showing the SaveFileDialog
Thread staThread = new Thread(() =>
{
using (var saveFileDialog = new SaveFileDialog())
{
saveFileDialog.Title = $"Save {capsPreview} File";
saveFileDialog.Filter = $"{capsPreview} Files (*.{fileExt})|*.{fileExt}";
saveFileDialog.DefaultExt = $"{fileExt}";
saveFileDialog.AddExtension = true;

if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
taskCompletionSource.SetResult(saveFileDialog.FileName);
}
else
{
taskCompletionSource.SetResult(null);
}
}
});

staThread.SetApartmentState(ApartmentState.STA);
staThread.Start();

return taskCompletionSource.Task;
}

public static Task<string> ShowOpenFileDialogAsync(string fileExt)
{
var capsPreview = fileExt.ToUpper();
MessageBox.Show(
$"Please select the ({capsPreview}) file.",
$"Open {capsPreview}",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
var taskCompletionSource = new TaskCompletionSource<string>();

// Start STA thread for showing the OpenFileDialog
Thread staThread = new Thread(() =>
{
using (var openFileDialog = new OpenFileDialog())
{
openFileDialog.Title = $"Open {capsPreview} File";
openFileDialog.Filter = $"{capsPreview} Files (*.{fileExt})|*.{fileExt}";
openFileDialog.DefaultExt = $"{fileExt}";
openFileDialog.AddExtension = true;

if (openFileDialog.ShowDialog() == DialogResult.OK)
{
taskCompletionSource.SetResult(openFileDialog.FileName);
}
else
{
taskCompletionSource.SetResult(null);
}
}
});

staThread.SetApartmentState(ApartmentState.STA);
staThread.Start();

return taskCompletionSource.Task;
}

public static async Task<string> ShowSelectFolderDialogAsync()
{
MessageBox.Show(
$"Please select update packages folder.",
$"Select Folder",
MessageBoxButtons.OK,
MessageBoxIcon.Information);

string result = await Task.Run(() =>
{
var dialog = (IFileOpenDialog)new FileOpenDialog();
dialog.SetOptions(FOS.FOS_PICKFOLDERS | FOS.FOS_FORCEFILESYSTEM);
if (dialog.Show(IntPtr.Zero) == 0)
{
dialog.GetResult(out IShellItem item);
item.GetDisplayName(SIGDN.SIGDN_FILESYSPATH, out IntPtr ptr);
string path = Marshal.PtrToStringAuto(ptr);
return path;
}
return null;
});

return result;
}

[ComImport]
[Guid("DC1C5A9C-E88A-4DDE-A5A1-60F82A20AEF7")]
[ClassInterface(ClassInterfaceType.None)]
private class FileOpenDialog { }

[ComImport]
[Guid("42f85136-db7e-439c-85f1-e4075d135fc8")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
private interface IFileOpenDialog
{
[PreserveSig] int Show([In] IntPtr parent);
void SetFileTypes(); // Not fully defined
void SetFileTypeIndex(int iFileType);
void GetFileTypeIndex(out int piFileType);
void Advise(); // Not fully defined
void Unadvise();
void SetOptions([In] FOS fos);
void GetOptions(out FOS pfos);
void SetDefaultFolder(IShellItem psi);
void SetFolder(IShellItem psi);
void GetFolder(out IShellItem ppsi);
void GetCurrentSelection(out IShellItem ppsi);
void SetFileName([In, MarshalAs(UnmanagedType.LPWStr)] string pszName);
void GetFileName([MarshalAs(UnmanagedType.LPWStr)] out string pszName);
void SetTitle([In, MarshalAs(UnmanagedType.LPWStr)] string pszTitle);
void SetOkButtonLabel([In, MarshalAs(UnmanagedType.LPWStr)] string pszText);
void SetFileNameLabel([In, MarshalAs(UnmanagedType.LPWStr)] string pszLabel);
void GetResult(out IShellItem ppsi);
void AddPlace(IShellItem psi, int alignment);
void SetDefaultExtension([In, MarshalAs(UnmanagedType.LPWStr)] string pszDefaultExtension);
void Close(int hr);
void SetClientGuid(); // Not fully defined
void ClearClientData();
void SetFilter([MarshalAs(UnmanagedType.IUnknown)] object filter);
void GetResults(); // Not fully defined
void GetSelectedItems(); // Not fully defined
}

[ComImport]
[Guid("43826d1e-e718-42ee-bc55-a1e261c37bfe")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
private interface IShellItem
{
void BindToHandler(); // Not fully defined
void GetParent(); // Not fully defined
void GetDisplayName(SIGDN sigdnName, out IntPtr ppszName);
void GetAttributes(); // Not fully defined
void Compare(); // Not fully defined
}

private enum SIGDN : uint
{
SIGDN_FILESYSPATH = 0x80058000,
}

[Flags]
private enum FOS
{
FOS_FORCEFILESYSTEM = 0x40,
FOS_PICKFOLDERS = 0x20,
}
}
}
Loading

0 comments on commit 4c94b37

Please sign in to comment.