Skip to content

Commit a26ded7

Browse files
Initial commit
0 parents  commit a26ded7

File tree

9 files changed

+289
-0
lines changed

9 files changed

+289
-0
lines changed

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Build files
2+
Hider/bin/*
3+
Hider/obj/*
4+
5+
# User-options files
6+
*.user
7+
8+
# Extra build files
9+
*.exe
10+
*.obj
11+
*.pdb
12+
*.nupkg
13+
14+
# IDE files
15+
.vs/*

FileHider.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.32112.339
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hider", "Hider\Hider.csproj", "{633103B0-A2A8-4754-9168-73C6EB7B4C50}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{633103B0-A2A8-4754-9168-73C6EB7B4C50}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{633103B0-A2A8-4754-9168-73C6EB7B4C50}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{633103B0-A2A8-4754-9168-73C6EB7B4C50}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{633103B0-A2A8-4754-9168-73C6EB7B4C50}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {E12FA776-B0B9-4623-8581-2B23808AC79A}
24+
EndGlobalSection
25+
EndGlobal

Hider/App.xaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Application x:Class="Hider.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:Hider"
5+
StartupUri="MainWindow.xaml">
6+
<Application.Resources>
7+
8+
</Application.Resources>
9+
</Application>

Hider/App.xaml.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System.Windows;
2+
3+
namespace Hider
4+
{
5+
/// <summary>
6+
/// Main logic for the App
7+
/// </summary>
8+
public partial class App : Application
9+
{
10+
}
11+
}

Hider/AssemblyInfo.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Windows;
2+
3+
[assembly: ThemeInfo(
4+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
5+
//(used if a resource is not found in the page,
6+
// or application resource dictionaries)
7+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
8+
//(used if a resource is not found in the page,
9+
// app, or any theme specific resource dictionaries)
10+
)]

Hider/Hider.csproj

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>WinExe</OutputType>
5+
<TargetFramework>net6.0-windows</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
<UseWPF>true</UseWPF>
8+
<UseWindowsForms>True</UseWindowsForms>
9+
</PropertyGroup>
10+
11+
</Project>

Hider/MainWindow.xaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<Window x:Class="Hider.MainWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:Hider"
7+
mc:Ignorable="d"
8+
Title="File Hider" Height="200" Width="600"
9+
ResizeMode="NoResize"
10+
>
11+
12+
<Grid Margin="10, 10, 10, 10">
13+
14+
15+
<!-- Row definition for the window -->
16+
<Grid.RowDefinitions>
17+
<RowDefinition Height="30"></RowDefinition>
18+
<RowDefinition Height="30"></RowDefinition>
19+
<RowDefinition Height="10"></RowDefinition>
20+
<RowDefinition Height="30"></RowDefinition>
21+
<RowDefinition Height="40"></RowDefinition>
22+
</Grid.RowDefinitions>
23+
24+
<!-- Input File -->
25+
<Grid Grid.Row="0">
26+
<Grid.ColumnDefinitions>
27+
<ColumnDefinition Width="120"></ColumnDefinition>
28+
<ColumnDefinition></ColumnDefinition>
29+
<ColumnDefinition Width="30"></ColumnDefinition>
30+
</Grid.ColumnDefinitions>
31+
32+
<Label Grid.Column="0">Input file: </Label>
33+
<TextBox MaxLines="1" Grid.Column="1" Margin="2" x:Name="inputFileBox"></TextBox>
34+
<Button Grid.Column="2" Click="OnBrowseInputFile" Margin="2">...</Button>
35+
</Grid>
36+
37+
<!-- Input directory -->
38+
<Grid Grid.Row="1">
39+
<Grid.ColumnDefinitions>
40+
<ColumnDefinition Width="120"></ColumnDefinition>
41+
<ColumnDefinition></ColumnDefinition>
42+
<ColumnDefinition Width="30"></ColumnDefinition>
43+
</Grid.ColumnDefinitions>
44+
45+
<Label Grid.Column="0">Input directory: </Label>
46+
<TextBox MaxLines="1" Grid.Column="1" Margin="2" x:Name="inputDirBox"></TextBox>
47+
<Button Grid.Column="2" Click="OnBrowseInputDir" Margin="2">...</Button>
48+
</Grid>
49+
50+
<Separator Grid.Row="2"></Separator>
51+
52+
<!-- Output File -->
53+
<Grid Grid.Row="3">
54+
<Grid.ColumnDefinitions>
55+
<ColumnDefinition Width="120"></ColumnDefinition>
56+
<ColumnDefinition></ColumnDefinition>
57+
<ColumnDefinition Width="30"></ColumnDefinition>
58+
</Grid.ColumnDefinitions>
59+
60+
<Label Grid.Column="0">Output file: </Label>
61+
<TextBox MaxLines="1" Grid.Column="1" Margin="2" x:Name="outputFileBox"></TextBox>
62+
<Button Grid.Column="2" Click="OnBrowseOutputFile" Margin="2">...</Button>
63+
</Grid>
64+
65+
<!-- Buttons -->
66+
<Grid Grid.Row="4">
67+
<Grid.ColumnDefinitions>
68+
<ColumnDefinition></ColumnDefinition>
69+
<ColumnDefinition></ColumnDefinition>
70+
</Grid.ColumnDefinitions>
71+
72+
<Button Grid.Column="0" Margin="5" x:Name="hideButton" Click="OnHideFiles">Hide File!</Button>
73+
<Button Grid.Column="1" Margin="5" x:Name="quitButton" Click="OnQuitApp">Quit</Button>
74+
</Grid>
75+
</Grid>
76+
</Window>

Hider/MainWindow.xaml.cs

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
using System;
2+
using System.IO;
3+
using System.IO.Compression;
4+
using System.Windows;
5+
6+
namespace Hider
7+
{
8+
/// <summary>
9+
/// Main logic for MainWindow
10+
/// </summary>
11+
public partial class MainWindow : Window
12+
{
13+
string inputFileExt;
14+
15+
public MainWindow()
16+
{
17+
inputFileExt = "";
18+
}
19+
20+
private void OnQuitApp(object sender, RoutedEventArgs e)
21+
{
22+
Application.Current.Shutdown();
23+
}
24+
25+
private void OnHideFiles(object sender, RoutedEventArgs e)
26+
{
27+
// Get the path values from the input boxes.
28+
String inputFilePath = inputFileBox.Text.Trim();
29+
String inputDirPath = inputDirBox.Text.Trim();
30+
String outputFilePath = outputFileBox.Text.Trim();
31+
32+
// Remove the temporary file if it exists.
33+
if (File.Exists("./temp.zip"))
34+
{
35+
File.Delete("./temp.zip");
36+
}
37+
38+
byte[] inputFileBuffer;
39+
if (File.Exists(inputFilePath))
40+
{
41+
inputFileBuffer = File.ReadAllBytes(inputFilePath);
42+
}
43+
else
44+
{
45+
ShowError("Cannot open input file to read!");
46+
return;
47+
}
48+
49+
FileStream outputFile;
50+
if(File.Exists(outputFilePath))
51+
{
52+
ShowError("Please select a different output file!");
53+
return;
54+
}
55+
else
56+
{
57+
outputFile = File.Create(outputFilePath);
58+
}
59+
60+
if (!Directory.Exists(inputDirPath))
61+
{
62+
ShowError("The given input directory does not exist!");
63+
return;
64+
}
65+
66+
ZipFile.CreateFromDirectory(inputDirPath, "./temp.zip");
67+
byte[] zipBuffer = File.ReadAllBytes("./temp.zip");
68+
byte[] buffer = new byte[zipBuffer.Length+inputFileBuffer.Length];
69+
inputFileBuffer.CopyTo(buffer, 0);
70+
zipBuffer.CopyTo(buffer, inputFileBuffer.Length);
71+
outputFile.Write(buffer);
72+
outputFile.Close();
73+
File.Delete("./temp.zip");
74+
75+
ShowInformation("The file has been saved successfully! Open the output file using an archive manager(WinRAR, 7-Zip, WinZIP etc.) to view the hidden files!");
76+
}
77+
78+
private void ShowError(string errMsg)
79+
{
80+
MessageBox.Show(errMsg, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
81+
}
82+
83+
private void ShowInformation(string msg)
84+
{
85+
MessageBox.Show(msg, "Information", MessageBoxButton.OK, MessageBoxImage.Information);
86+
}
87+
88+
private void OnBrowseInputFile(object sender, RoutedEventArgs e)
89+
{
90+
System.Windows.Forms.OpenFileDialog dialog = new();
91+
dialog.Title = "Please select an input file";
92+
dialog.Filter = "Supported Files(*.jpg, *.mp3, *.mp4)|*.jpg;*.mp3;*.mp4";
93+
dialog.ShowDialog();
94+
inputFileBox.Text = dialog.FileName;
95+
inputFileExt = Path.GetExtension(inputFileBox.Text); // Get the extension of the input file.
96+
}
97+
98+
private void OnBrowseInputDir(object sender, RoutedEventArgs e)
99+
{
100+
System.Windows.Forms.FolderBrowserDialog dialog = new();
101+
dialog.ShowNewFolderButton = false;
102+
dialog.ShowDialog();
103+
inputDirBox.Text = dialog.SelectedPath;
104+
}
105+
106+
private void OnBrowseOutputFile(object sender, RoutedEventArgs e)
107+
{
108+
System.Windows.Forms.SaveFileDialog dialog = new();
109+
dialog.Title = "Please select an output file";
110+
dialog.Filter = $"Input file type (*{inputFileExt})|*{inputFileExt}"; // Remove the . from the input file extension and set is as filter.
111+
dialog.ShowDialog();
112+
outputFileBox.Text = dialog.FileName;
113+
}
114+
}
115+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
https://go.microsoft.com/fwlink/?LinkID=208121.
4+
-->
5+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
6+
<PropertyGroup>
7+
<Configuration>Release</Configuration>
8+
<Platform>Any CPU</Platform>
9+
<PublishDir>bin\Release\net6.0-windows\publish\win-x64\</PublishDir>
10+
<PublishProtocol>FileSystem</PublishProtocol>
11+
<TargetFramework>net6.0-windows</TargetFramework>
12+
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
13+
<SelfContained>true</SelfContained>
14+
<PublishSingleFile>False</PublishSingleFile>
15+
<PublishReadyToRun>True</PublishReadyToRun>
16+
</PropertyGroup>
17+
</Project>

0 commit comments

Comments
 (0)