-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
209 lines (177 loc) · 7.09 KB
/
MainWindow.xaml.cs
File metadata and controls
209 lines (177 loc) · 7.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Windows;
using System.Windows.Controls; // ContextMenu ve ListBox için gerekli
using Microsoft.Win32;
namespace JSONFileExplorer
{
public partial class MainWindow : Window
{
private HashSet<string> databaseIds = new HashSet<string>();
private string currentFilePath = "";
public MainWindow()
{
InitializeComponent();
}
// --- 1. DOSYA YÜKLEME ---
private void BtnLoad_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
// Hem JSON hem TXT hem de uzantısız dosyaları görebilmek için filtre:
openFileDialog.Filter = "Tüm Dosyalar (*.*)|*.*|JSON Dosyaları (*.json)|*.json|Metin Dosyaları (*.txt)|*.txt";
if (openFileDialog.ShowDialog() == true)
{
currentFilePath = openFileDialog.FileName;
LoadData(currentFilePath);
}
}
private void LoadData(string path)
{
try
{
string content = File.ReadAllText(path);
databaseIds.Clear();
try
{
// JSON formatı denemesi
var tempDict = JsonSerializer.Deserialize<Dictionary<string, bool>>(content);
if (tempDict != null)
{
foreach (var key in tempDict.Keys)
{
databaseIds.Add(key);
}
}
}
catch
{
// Düz yazı formatı denemesi
string[] lines = content.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var line in lines)
{
string cleanId = line.Trim().Replace("\"", "").Replace(",", "");
if (!string.IsNullOrWhiteSpace(cleanId))
{
databaseIds.Add(cleanId);
}
}
}
UpdateUI();
lblStatus.Text = $"✅ Yüklendi: {databaseIds.Count} adet kayıt.";
}
catch (Exception ex)
{
MessageBox.Show("Hata: " + ex.Message);
}
}
// --- 2. ARAYÜZ GÜNCELLEME ---
private void UpdateUI()
{
lstCurrentIds.ItemsSource = null;
// Tüm listeyi göster (Take(100) kaldırdık)
lstCurrentIds.ItemsSource = databaseIds.ToList();
((System.Windows.Controls.GroupBox)lstCurrentIds.Parent).Header = $"Mevcut İçerik (Toplam: {databaseIds.Count})";
}
// --- 3. İŞLE VE KAYDET ---
private void BtnProcess_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(currentFilePath))
{
MessageBox.Show("Lütfen önce bir dosya yükleyin!");
return;
}
string rawInput = txtBulkInput.Text;
string[] newLines = rawInput.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
int addedCount = 0;
int duplicateCount = 0;
foreach (var line in newLines)
{
string idToCheck = line.Trim().Replace("\"", "").Replace(",", "");
if (string.IsNullOrWhiteSpace(idToCheck)) continue;
if (databaseIds.Contains(idToCheck))
{
duplicateCount++;
}
else
{
databaseIds.Add(idToCheck);
addedCount++;
}
}
SaveDatabase();
txtBulkInput.Clear();
UpdateUI();
MessageBox.Show($"EKLENEN: {addedCount}\nZATEN VARDI: {duplicateCount}\nTOPLAM: {databaseIds.Count}", "İşlem Tamam");
lblStatus.Text = "Kayıt başarılı.";
}
private void SaveDatabase()
{
// Dosyanın uzantısını kontrol et (.json mu?)
string extension = Path.GetExtension(currentFilePath).ToLower();
// DURUM 1: Eğer dosya bir JSON ise, eski formatı koru (Roblox Table Formatı)
if (extension == ".json")
{
var exportDict = new Dictionary<string, bool>();
foreach (var id in databaseIds)
{
exportDict[id] = true;
}
var options = new JsonSerializerOptions { WriteIndented = true };
string jsonOutput = JsonSerializer.Serialize(exportDict, options);
File.WriteAllText(currentFilePath, jsonOutput);
}
// DURUM 2: JSON değilse (txt veya uzantısız BLScriptsData gibi), DÜZ METİN kaydet
else
{
// HashSet içindeki tüm ID'leri alt alta yaz
File.WriteAllLines(currentFilePath, databaseIds);
}
}
// --- YENİ EKLENEN ÖZELLİKLER (SİLME & KOPYALAMA) ---
// Ortak Silme Fonksiyonu
private void RemoveSelectedItems()
{
if (lstCurrentIds.SelectedItems.Count == 0) return;
// Seçilenleri listeye al
var itemsToRemove = lstCurrentIds.SelectedItems.Cast<string>().ToList();
int deletedCount = 0;
foreach (var id in itemsToRemove)
{
if (databaseIds.Contains(id))
{
databaseIds.Remove(id);
deletedCount++;
}
}
UpdateUI();
lblStatus.Text = $"🗑️ {deletedCount} adet kayıt silindi.";
// Değişikliği anında kaydetmek istersen burayı aç:
// SaveDatabase();
}
// Klavye Tuşuna Basınca (Delete Tuşu)
private void LstCurrentIds_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key == System.Windows.Input.Key.Delete)
{
RemoveSelectedItems();
}
}
// Sağ Tık Menüsü: Sil
private void BtnDelete_Click(object sender, RoutedEventArgs e)
{
RemoveSelectedItems();
}
// Sağ Tık Menüsü: Kopyala
private void BtnCopy_Click(object sender, RoutedEventArgs e)
{
if (lstCurrentIds.SelectedItems.Count == 0) return;
var selectedList = lstCurrentIds.SelectedItems.Cast<string>();
string clipboardText = string.Join(Environment.NewLine, selectedList);
Clipboard.SetText(clipboardText);
lblStatus.Text = "📋 Seçilenler kopyalandı.";
}
}
}