Skip to content

Commit f3b7f51

Browse files
committed
Upload project files
1 parent da30b2c commit f3b7f51

17 files changed

Lines changed: 1097 additions & 0 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/obj
2+
/bin

App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
</configuration>

App.xaml

Lines changed: 327 additions & 0 deletions
Large diffs are not rendered by default.

App.xaml.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace Trinity_Configs_Migrator
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
}
17+
}

MainWindow.xaml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<Window x:Class="Trinity_Configs_Migrator.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:Trinity_Configs_Migrator"
7+
mc:Ignorable="d"
8+
Title="Trinity Configs Migrator" Height="380" Width="650" Foreground="White"
9+
WindowStartupLocation="CenterScreen"
10+
ResizeMode="CanMinimize"
11+
WindowStyle="None"
12+
AllowsTransparency="True"
13+
Background="Transparent"
14+
RenderOptions.BitmapScalingMode="HighQuality"
15+
Loaded="Window_Loaded">
16+
<WindowChrome.WindowChrome>
17+
<WindowChrome CaptionHeight="28" ResizeBorderThickness="0" CornerRadius="30"/>
18+
</WindowChrome.WindowChrome>
19+
<Border CornerRadius="5" Background="#FF1D1D1D">
20+
<Grid>
21+
<!--Title Bar begin-->
22+
<Border VerticalAlignment="Top" Height="25" Background="#FF282828" CornerRadius="5,5,0,0">
23+
<Grid>
24+
<TextBlock Text="Trinity Configs Migrator" VerticalAlignment="Center" Margin="10,0,0,0" Foreground="#FFD7D7D7"/>
25+
<StackPanel WindowChrome.IsHitTestVisibleInChrome="True" VerticalAlignment="Center" HorizontalAlignment="Right" Orientation="Horizontal">
26+
<Button x:Name="titleBarBtnMinimize" Content="" HorizontalAlignment="Left" VerticalAlignment="Top" BorderBrush="{x:Null}" Background="#00000000" Foreground="#FF8D8D8D" FontFamily="Arial" FontSize="13" Width="38" Padding="-4,0,0,0" Height="26" Click="titleBarBtnMinimize_Click" Style="{DynamicResource ControlBoxButtonMinimize}"/>
27+
<Button x:Name="titleBarBtnExit" Content="X" HorizontalAlignment="Left" VerticalAlignment="Top" Foreground="#FF8D8D8D" BorderBrush="{x:Null}" Background="#00000000" FontFamily="Arial" FontSize="14" Width="36" Padding="0" Height="26" Click="titleBarBtnExit_Click" Style="{DynamicResource ControlBoxButtonClose}"/>
28+
</StackPanel>
29+
</Grid>
30+
</Border>
31+
<TabControl x:Name="TCMNav" Margin="0,28,0,0" Background="{x:Null}" BorderBrush="{x:Null}">
32+
<TabItem Style="{DynamicResource TabItemStyle1}" x:Name="tcm_tab_home" Header="Home" Visibility="Visible" Background="{x:Null}" BorderBrush="{x:Null}" Cursor="Hand">
33+
<Grid>
34+
<StackPanel Orientation="Vertical" Margin="0,15,0,0">
35+
<TextBlock Text="Configs Migration" HorizontalAlignment="Center" Foreground="#FF8FF291" FontSize="16" FontWeight="Bold" FontFamily="Bahnschrift Light"/>
36+
<Image Source="/res/file_migration_icon.png" Width="100" HorizontalAlignment="Center" Margin="0,15,0,0" />
37+
<StackPanel HorizontalAlignment="Center" Orientation="Horizontal" Margin="0,15,0,0">
38+
<Button x:Name="BtnOldPath" Content="Select old config" Padding="5,5,5,5" Style="{DynamicResource ThanksButton}" Foreground="#FFC9C9C9" Background="#FF282828" Cursor="Hand" BorderBrush="#FF3C3C3C" Click="BtnOldPath_Click"/>
39+
<TextBlock Text="and" Margin="10,0,10,0" Foreground="White" VerticalAlignment="Center"/>
40+
<Button x:Name="BrtnNewPath" Content="Select new config" Padding="5,5,5,5" Style="{DynamicResource ThanksButton}" Background="#FF282828" Foreground="#FF67C6A7" Cursor="Hand" BorderBrush="#FF3C3C3C" Click="BrtnNewPath_Click"/>
41+
</StackPanel>
42+
<Border HorizontalAlignment="Center" Margin="0,15,0,0" BorderBrush="#FF3A3A3A" BorderThickness="1,1,1,1" CornerRadius="3,3,3,3" Width="500">
43+
<StackPanel Orientation="Horizontal">
44+
<TextBlock Text="Old Config Path:" Padding="5,5,5,5" Foreground="#FF666666"/>
45+
<TextBlock x:Name="info_old_path" Text="..." Padding="5,5,5,5" Foreground="#FF666666" TextTrimming="CharacterEllipsis" Width="390"/>
46+
</StackPanel>
47+
</Border>
48+
<Border HorizontalAlignment="Center" Margin="0,5,0,0" BorderBrush="#FF3A3A3A" BorderThickness="1,1,1,1" CornerRadius="3,3,3,3" Width="500">
49+
<StackPanel Orientation="Horizontal">
50+
<TextBlock Text="New Config Path:" Padding="5,5,5,5" Foreground="#FF666666"/>
51+
<TextBlock x:Name="info_new_path" Text="..." Padding="5,5,5,5" Foreground="#FF666666" TextTrimming="CharacterEllipsis" Width="390"/>
52+
</StackPanel>
53+
</Border>
54+
<Button x:Name="BtnMigrate" Content="MIGRATE" Cursor="Hand" Margin="0,20,0,0" Width="120" Padding="5,5,5,5" Background="#FF87BB88" FontWeight="Bold" FontFamily="Corbel" FontSize="14" Foreground="#FF262626" Style="{DynamicResource MigrateButton}" Click="BtnMigrate_Click"/>
55+
<TextBlock x:Name="migration_info" HorizontalAlignment="Center" Margin="0,15,0,0" Width="500" TextTrimming="CharacterEllipsis" TextAlignment="Center" Height="20" Foreground="#FFB6B756"/>
56+
</StackPanel>
57+
</Grid>
58+
</TabItem>
59+
<TabItem x:Name="tcm_tab_about" Header="About" Visibility="Visible" Margin="0,-2,-2,0" Style="{DynamicResource TabItemStyle1}" Cursor="Hand">
60+
<StackPanel Orientation="Vertical" Margin="0,25,0,0">
61+
<TextBlock Text="Trinity Configs Migrator" Foreground="#FFD15E5E" FontWeight="Bold" HorizontalAlignment="Center"/>
62+
<Grid HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,15,0,0">
63+
<TextBlock xml:space="preserve" TextAlignment="Center" Foreground="#FFAB4B4B">Migrates old config file settings to the newly selected config file.
64+
For example select your old server worldserver.conf file and your new server worldserver.conf file then migrate.
65+
This will transfer all settings values to the new server config file.
66+
</TextBlock>
67+
</Grid>
68+
<TextBlock Text="Developed by CyberMist" HorizontalAlignment="Center" Foreground="#FFD1985E" FontWeight="Bold"/>
69+
<Image Source="/res/cyb_logo.png" Width="80" Margin="0,10,0,0"/>
70+
<Button Width="100" Margin="0,10,0,0" Cursor="Hand" Background="#FF292929" HorizontalContentAlignment="Center" BorderBrush="#FF3C3C3C" Style="{DynamicResource ThanksButton}">
71+
<Button.Content>
72+
<StackPanel Orientation="Horizontal">
73+
<Image Source="/res/pp.png" Width="30" Margin="-15,0,0,0" VerticalAlignment="Center" />
74+
<TextBlock Text="Say thanks" Foreground="#FF0CBACF" VerticalAlignment="Center"/>
75+
</StackPanel>
76+
</Button.Content>
77+
</Button>
78+
</StackPanel>
79+
</TabItem>
80+
</TabControl>
81+
<!--Title Bar end-->
82+
83+
</Grid>
84+
</Border>
85+
</Window>

MainWindow.xaml.cs

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
using Microsoft.Win32;
2+
using System;
3+
using System.IO;
4+
using System.Threading.Tasks;
5+
using System.Windows;
6+
using System.Windows.Media;
7+
8+
namespace Trinity_Configs_Migrator
9+
{
10+
/// <summary>
11+
/// Interaction logic for MainWindow.xaml
12+
/// </summary>
13+
public partial class MainWindow : Window
14+
{
15+
public MainWindow()
16+
{
17+
InitializeComponent();
18+
}
19+
20+
private void Window_Loaded(object sender, RoutedEventArgs e)
21+
{
22+
//TCMNav.SelectedItem = tcm_tab_about;
23+
}
24+
25+
private void titleBarBtnMinimize_Click(object sender, RoutedEventArgs e)
26+
{
27+
WindowState = WindowState.Minimized;
28+
}
29+
30+
private void titleBarBtnExit_Click(object sender, RoutedEventArgs e)
31+
{
32+
Close();
33+
}
34+
35+
private void BtnOldPath_Click(object sender, RoutedEventArgs e)
36+
{
37+
// Configure open file dialog box
38+
var dialog = new OpenFileDialog();
39+
dialog.FileName = "Authserver or Worldserver Config"; // Default file name
40+
dialog.DefaultExt = ".conf"; // Default file extension
41+
dialog.Filter = "Text documents (.conf)|*.conf"; // Filter files by extension
42+
43+
// Show open file dialog box
44+
bool? result = dialog.ShowDialog();
45+
46+
// Process open file dialog box results
47+
if (result == true)
48+
{
49+
// Open document
50+
string filename = dialog.FileName;
51+
info_old_path.Text = filename;
52+
}
53+
}
54+
55+
private void BrtnNewPath_Click(object sender, RoutedEventArgs e)
56+
{
57+
// Configure open file dialog box
58+
var dialog = new OpenFileDialog();
59+
dialog.FileName = "Authserver or Worldserver Config"; // Default file name
60+
dialog.DefaultExt = ".conf"; // Default file extension
61+
dialog.Filter = "Text documents (.conf)|*.conf"; // Filter files by extension
62+
63+
// Show open file dialog box
64+
bool? result = dialog.ShowDialog();
65+
66+
// Process open file dialog box results
67+
if (result == true)
68+
{
69+
// Open document
70+
string filename = dialog.FileName;
71+
info_new_path.Text = filename;
72+
}
73+
}
74+
75+
private void BtnMigrate_Click(object sender, RoutedEventArgs e)
76+
{
77+
migration_info.Text = "Working on migration documents..";
78+
79+
Task.Delay(1000);
80+
81+
// get whole text from old file
82+
string old_config_content = string.Empty;
83+
try
84+
{
85+
// Open the text file using a stream reader.
86+
using (var sr = new StreamReader(info_old_path.Text))
87+
{
88+
// Read the stream as a string, and write the string to the console.
89+
old_config_content = sr.ReadToEnd();
90+
}
91+
}
92+
catch (Exception ex)
93+
{
94+
MessageBox.Show(ex.Message);
95+
}
96+
97+
//get whole text from new file
98+
string new_config_content = string.Empty;
99+
try
100+
{
101+
// Open the text file using a stream reader.
102+
using (var sr = new StreamReader(info_new_path.Text))
103+
{
104+
// Read the stream as a string, and write the string to the console.
105+
new_config_content = sr.ReadToEnd();
106+
}
107+
}
108+
catch (Exception ex)
109+
{
110+
MessageBox.Show(ex.Message);
111+
}
112+
113+
int counter = 0;
114+
115+
// get old config file reference
116+
string old_config_ref = string.Empty;
117+
foreach (string line in old_config_content.Split('\n'))
118+
{
119+
if (line.StartsWith("["))
120+
{
121+
old_config_ref = line;
122+
}
123+
}
124+
125+
// get new config file reference
126+
string new_config_ref = string.Empty;
127+
foreach (string line in new_config_content.Split('\n'))
128+
{
129+
if (line.StartsWith("["))
130+
{
131+
new_config_ref = line;
132+
}
133+
}
134+
135+
if (old_config_ref != new_config_ref)
136+
{
137+
migration_info.Foreground = new SolidColorBrush(Colors.DarkRed);
138+
migration_info.Text = "You are trying to migrate settings from 2 different config references, for example transfering authserver settings to worldserver.conf";
139+
}
140+
else
141+
{
142+
// Read the file and display it line by line.
143+
foreach (string oldline in old_config_content.Split('\n'))
144+
{
145+
// if line doesn't start with "#", or not null or not empty then definetely found a variable
146+
if (!oldline.StartsWith("[") && !oldline.StartsWith("#") && !string.IsNullOrEmpty(oldline) && !string.IsNullOrWhiteSpace(oldline))
147+
{
148+
// get varialbe name
149+
string s_old_var_name = string.Empty;
150+
int charLocation = oldline.IndexOf("=", StringComparison.Ordinal);
151+
if (charLocation > 0)
152+
{
153+
s_old_var_name = oldline.Substring(0, charLocation);
154+
}
155+
156+
string s_old_var_value = oldline.Substring(oldline.LastIndexOf('=') + 1);
157+
158+
// check if variable exists in the new config file
159+
if (!new_config_content.Contains(s_old_var_name))
160+
continue;
161+
162+
int lineNumber = 0;
163+
foreach (string lineN in new_config_content.Split('\n'))
164+
{
165+
lineNumber++;
166+
if (lineN.Contains(s_old_var_name) && !lineN.StartsWith("#") && lineN != oldline)
167+
{
168+
LineChanger(oldline.Replace("\n", "").Replace("\r", ""), info_new_path.Text, lineNumber);
169+
//MessageBox.Show($"transfering value for {s_old_var_name} to new config at line number [{lineNumber}]");
170+
171+
counter++;
172+
break;
173+
}
174+
}
175+
}
176+
}
177+
178+
if (counter > 0)
179+
{
180+
migration_info.Foreground = new SolidColorBrush(Colors.DarkGreen);
181+
migration_info.Text = $"{counter} settings transfered.";
182+
}
183+
else
184+
{
185+
migration_info.Foreground = new SolidColorBrush(Colors.DarkOrange);
186+
migration_info.Text = $"{counter} settings transfered, nothing different.";
187+
}
188+
}
189+
}
190+
191+
static void LineChanger(string newText, string fileName, int line_to_edit)
192+
{
193+
int currentLineNumber = 0;
194+
string[] lines = File.ReadAllLines(fileName);
195+
foreach (string line in lines)
196+
{
197+
if (currentLineNumber == line_to_edit)
198+
{
199+
lines[currentLineNumber -1] = newText;
200+
break;
201+
}
202+
currentLineNumber++;
203+
}
204+
205+
File.WriteAllLines(fileName, lines);
206+
}
207+
}
208+
}

Properties/AssemblyInfo.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System.Reflection;
2+
using System.Resources;
3+
using System.Runtime.CompilerServices;
4+
using System.Runtime.InteropServices;
5+
using System.Windows;
6+
7+
// General Information about an assembly is controlled through the following
8+
// set of attributes. Change these attribute values to modify the information
9+
// associated with an assembly.
10+
[assembly: AssemblyTitle("Trinity Configs Migrator")]
11+
[assembly: AssemblyDescription("Developed by CyberMist")]
12+
[assembly: AssemblyConfiguration("")]
13+
[assembly: AssemblyCompany("CyberMist2.inc")]
14+
[assembly: AssemblyProduct("Trinity Configs Migrator")]
15+
[assembly: AssemblyCopyright("Copyright © CyberMist 2022")]
16+
[assembly: AssemblyTrademark("")]
17+
[assembly: AssemblyCulture("")]
18+
19+
// Setting ComVisible to false makes the types in this assembly not visible
20+
// to COM components. If you need to access a type in this assembly from
21+
// COM, set the ComVisible attribute to true on that type.
22+
[assembly: ComVisible(false)]
23+
24+
//In order to begin building localizable applications, set
25+
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
26+
//inside a <PropertyGroup>. For example, if you are using US english
27+
//in your source files, set the <UICulture> to en-US. Then uncomment
28+
//the NeutralResourceLanguage attribute below. Update the "en-US" in
29+
//the line below to match the UICulture setting in the project file.
30+
31+
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32+
33+
34+
[assembly: ThemeInfo(
35+
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36+
//(used if a resource is not found in the page,
37+
// or application resource dictionaries)
38+
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39+
//(used if a resource is not found in the page,
40+
// app, or any theme specific resource dictionaries)
41+
)]
42+
43+
44+
// Version information for an assembly consists of the following four values:
45+
//
46+
// Major Version
47+
// Minor Version
48+
// Build Number
49+
// Revision
50+
//
51+
// You can specify all the values or you can default the Build and Revision Numbers
52+
// by using the '*' as shown below:
53+
// [assembly: AssemblyVersion("1.0.*")]
54+
[assembly: AssemblyVersion("1.0.0.0")]
55+
[assembly: AssemblyFileVersion("1.0.0.0")]

0 commit comments

Comments
 (0)