Advertisement
Jayss8

Osu! Song Receiver

Jul 8th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1. using System;
  2. using System.Diagnostics;
  3. using System.IO;
  4.  
  5. /// <summary>
  6. /// <para>A simple program that detects the user's song, and edits a .txt file with the song name.</para>
  7. /// </summary>
  8.  
  9. namespace osuBrandon
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             Console.Title = "Osu! Stream Song Reciever";
  16.  
  17.             string sDirectory = @"D:\Games\OSU";
  18.             string sPath = @"D:\Games\OSU\actualsong.txt";
  19.  
  20.             string sOld_Song = String.Empty;
  21.             string sNew_Song = String.Empty;
  22.  
  23.             // Create Directory if it doesn't exist...
  24.             if (!Directory.Exists(sDirectory))
  25.             {
  26.                 Directory.CreateDirectory(sDirectory);
  27.             }
  28.  
  29.             // Loop to check song change...
  30.             while (true)
  31.             {
  32.                 Process[] p = Process.GetProcessesByName("osu!");
  33.                 try
  34.                 {
  35.                     sNew_Song = p[0].MainWindowTitle.Substring(8, (p[0].MainWindowTitle.Length - 8));
  36.                 }
  37.                 catch (Exception e)
  38.                 {
  39.                     // Selecting song...
  40.                     continue;
  41.                 }
  42.  
  43.                 if ((sOld_Song != sNew_Song) || (sOld_Song == String.Empty) && (sNew_Song == String.Empty))
  44.                 {
  45.                     Console.WriteLine(sNew_Song);
  46.  
  47.                     // Write song name into the text file...
  48.                     using (TextWriter tw = File.CreateText(sPath))
  49.                     {
  50.                         tw.WriteLine(sNew_Song);
  51.                         tw.Close();
  52.                     }
  53.                 }
  54.                 sOld_Song = sNew_Song;
  55.  
  56.                 // 500 ms break
  57.                 System.Threading.Thread.Sleep(500);
  58.             }
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement