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